...
1
2 package teamster
3
4 import (
5 "context"
6 "fmt"
7 "os"
8
9 "github.com/google/go-github/v47/github"
10
11 "edge-infra.dev/pkg/f8n/devinfra/github/ghfs"
12 "edge-infra.dev/pkg/lib/cli/rags"
13 "edge-infra.dev/pkg/lib/cli/sink"
14 "edge-infra.dev/pkg/tools/team"
15 )
16
17
18
19 func New(name string) *sink.Command {
20 cmd := &sink.Command{
21 Use: fmt.Sprintf("%s [command] [flags]", name),
22 Short: "Work with team configuration files.",
23 Commands: []*sink.Command{
24 NewCmdSync(),
25 NewCmdResolve(),
26 NewCmdValidate(),
27 },
28 }
29
30 return cmd
31 }
32
33 func commonFlags(org, repo, ref *string) []*rags.Rag {
34 return []*rags.Rag{
35 {
36 Name: "org",
37 Value: &rags.String{Var: org},
38 Usage: "A GitHub organization name.",
39 },
40 {
41 Name: "repo",
42 Value: &rags.String{Var: repo},
43 Usage: "A GitHub repo to read team files from instead of the local file " +
44 "system. Requires --ref to be provided",
45 },
46 {
47 Name: "ref",
48 Value: &rags.String{Var: ref},
49 Usage: "Reference to use when reading team files from remote repository " +
50 "provided via --repo.",
51 },
52 }
53 }
54
55 func getTeam(
56 ctx context.Context,
57 file, org, repo, ref string,
58 gh *github.Client,
59 ) (*team.Team, error) {
60
61 if repo != "" || ref != "" {
62 if gh == nil {
63 return nil, fmt.Errorf("unexpected error: no GitHub client provided for " +
64 "remote team file fetching")
65 }
66 if org == "" || repo == "" || ref == "" {
67 return nil, fmt.Errorf("--repo, --org, and --ref are required for remote " +
68 "team file fetching")
69 }
70 fs, err := ghfs.New(ctx, gh, org, repo, ref)
71 if err != nil {
72 return nil, err
73 }
74 return team.Load(fs, file)
75 }
76
77 return team.Load(os.DirFS("."), file)
78 }
79
View as plain text