-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathteam.go
80 lines (67 loc) · 1.51 KB
/
team.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"sort"
"github.com/google/go-github/v33/github"
)
func getTeams(org string, format string) {
ctx := context.Background()
client := createGithubClient(ctx)
opt := &github.ListOptions{PerPage: 100}
var objsAll []*github.Team
for {
objs, resp, err := client.Teams.ListTeams(ctx, org, opt)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
objsAll = append(objsAll, objs...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
sort.Slice(objsAll, func(i, j int) bool {
return *objsAll[i].Name < *objsAll[j].Name
})
if format == "normal" {
for _, repo := range objsAll {
fmt.Println(*repo.Name)
}
} else if format == "json" {
bytes, _ := json.Marshal(objsAll)
fmt.Println(string(bytes))
}
}
func getTeam(org string, team *string, format string) {
ctx := context.Background()
client := createGithubClient(ctx)
obj, _, err := client.Teams.GetTeamBySlug(ctx, org, *team)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if format == "normal" {
fmt.Println(*obj.Name)
} else if format == "json" {
bytes, _ := json.Marshal(obj)
fmt.Println(string(bytes))
}
}
func addTeamToRepo(org string,
repo, team, permission string) {
ctx := context.Background()
client := createGithubClient(ctx)
perm := &github.TeamAddTeamRepoOptions{
Permission: permission,
}
resp, err := client.Teams.AddTeamRepoBySlug(ctx, org, team, org, repo, perm)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(resp.Status)
}