-
Notifications
You must be signed in to change notification settings - Fork 4
/
member.go
72 lines (62 loc) · 1.33 KB
/
member.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
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"sort"
"github.com/google/go-github/v33/github"
)
func getMembers(org string, format string) {
ctx := context.Background()
client := createGithubClient(ctx)
opt := &github.ListMembersOptions{ListOptions: github.ListOptions{PerPage: 100}}
var objsAll []*github.User
for {
objs, resp, err := client.Organizations.ListMembers(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].Login < *objsAll[j].Login
})
if format == "normal" {
for _, repo := range objsAll {
fmt.Println(*repo.Login)
}
} else if format == "json" {
bytes, _ := json.Marshal(objsAll)
fmt.Println(string(bytes))
}
}
func getPrimaryEmail() string {
ctx := context.Background()
client := createGithubClient(ctx)
opt := &github.ListOptions{PerPage: 100}
var objsAll []*github.UserEmail
for {
objs, resp, err := client.Users.ListEmails(ctx, opt)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
objsAll = append(objsAll, objs...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
for _, e := range objsAll {
if *e.Primary && *e.Verified {
return *e.Email
}
}
return ""
}