Merge key fetcher #6
|
@ -27,7 +27,7 @@ func main() {
|
||||||
keysDir := parser.String("d", "directory", &argparse.Options{Required: false, Help: "Path where to store the key files", Default: "./"})
|
keysDir := parser.String("d", "directory", &argparse.Options{Required: false, Help: "Path where to store the key files", Default: "./"})
|
||||||
quiet := parser.Flag("q", "quiet", &argparse.Options{Required: false, Help: "Skip output to stdout", Default: false})
|
quiet := parser.Flag("q", "quiet", &argparse.Options{Required: false, Help: "Skip output to stdout", Default: false})
|
||||||
ghOrganization := parser.String("o", "org", &argparse.Options{Required: false, Help: "Github Organization name", Default: "OpenFest"})
|
ghOrganization := parser.String("o", "org", &argparse.Options{Required: false, Help: "Github Organization name", Default: "OpenFest"})
|
||||||
ghTeam := parser.String("t", "team", &argparse.Options{Required: false, Help: "Github Team name", Default: "NOC"})
|
ghTeam := parser.String("t", "team", &argparse.Options{Required: false, Help: "Github Team name, 'all' for all members of the organization", Default: "NOC"})
|
||||||
|
|
||||||
// Parse input
|
// Parse input
|
||||||
err := parser.Parse(os.Args)
|
err := parser.Parse(os.Args)
|
||||||
|
@ -107,64 +107,94 @@ func main() {
|
||||||
func fetchUsers(client *github.Client, org *string, team *string) (teamMembers []*string) {
|
func fetchUsers(client *github.Client, org *string, team *string) (teamMembers []*string) {
|
||||||
var targetTeam *github.Team
|
var targetTeam *github.Team
|
||||||
|
|
||||||
for nextPage := 0; ; {
|
if team == nil || *team == "all" {
|
||||||
// list all teams for the specified org
|
for nextPage := 0; ; {
|
||||||
opt := &github.ListOptions{nextPage, 50}
|
// list all members for the given organization's team
|
||||||
teams, rsp, err := client.Teams.ListTeams(context.Background(), *org, opt)
|
opt := &github.ListMembersOptions{
|
||||||
|
PublicOnly: false,
|
||||||
|
ListOptions: github.ListOptions{nextPage, 50},
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
users, rsp, err := client.Organizations.ListMembers(context.Background(), *org, opt)
|
||||||
fmt.Println("client.ListTeams error: ", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rsp == nil {
|
if err != nil {
|
||||||
fmt.Println("client.ListTeams returned empty response: ", err)
|
fmt.Println("client.Organizations.ListMembers ", err)
|
||||||
}
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
for _, ghTeam := range teams {
|
if rsp == nil {
|
||||||
if *ghTeam.Name == *team {
|
fmt.Println("client.Organizations.ListMembers: ", err)
|
||||||
targetTeam = ghTeam
|
}
|
||||||
|
|
||||||
|
for _, user := range users {
|
||||||
|
teamMembers = append(teamMembers, user.Login)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rsp.NextPage == 0 || nextPage == rsp.NextPage {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
nextPage = rsp.NextPage
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for nextPage := 0; ; {
|
||||||
|
// list all teams for the specified org
|
||||||
|
opt := &github.ListOptions{nextPage, 50}
|
||||||
|
teams, rsp, err := client.Teams.ListTeams(context.Background(), *org, opt)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("client.ListTeams error: ", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rsp == nil {
|
||||||
|
fmt.Println("client.ListTeams returned empty response: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ghTeam := range teams {
|
||||||
|
if *ghTeam.Name == *team {
|
||||||
|
targetTeam = ghTeam
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rsp.NextPage == 0 || nextPage == rsp.NextPage {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
nextPage = rsp.NextPage
|
||||||
}
|
}
|
||||||
|
|
||||||
if rsp.NextPage == 0 || nextPage == rsp.NextPage {
|
if targetTeam == nil {
|
||||||
break
|
fmt.Println(*team , " team not found in ", *org)
|
||||||
}
|
os.Exit(2)
|
||||||
nextPage = rsp.NextPage
|
|
||||||
}
|
|
||||||
|
|
||||||
if targetTeam == nil {
|
|
||||||
fmt.Println(*team , " team not found in ", *org)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
for nextPage := 0; ; {
|
|
||||||
// list all members for the given organization's team
|
|
||||||
opt := &github.TeamListTeamMembersOptions{
|
|
||||||
Role: "all",
|
|
||||||
ListOptions: github.ListOptions{nextPage, 50},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
users, rsp, err := client.Teams.ListTeamMembers(context.Background(), *targetTeam.ID, opt)
|
for nextPage := 0; ; {
|
||||||
|
// list all members for the given organization's team
|
||||||
|
opt := &github.TeamListTeamMembersOptions{
|
||||||
|
Role: "all",
|
||||||
|
ListOptions: github.ListOptions{nextPage, 50},
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
users, rsp, err := client.Teams.ListTeamMembers(context.Background(), *targetTeam.ID, opt)
|
||||||
fmt.Println("client.Teams.ListTeamMembers ", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rsp == nil {
|
if err != nil {
|
||||||
fmt.Println("client.Teams.ListTeamMembers: ", err)
|
fmt.Println("client.Teams.ListTeamMembers ", err)
|
||||||
}
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
for _, user := range users {
|
if rsp == nil {
|
||||||
teamMembers = append(teamMembers, user.Login)
|
fmt.Println("client.Teams.ListTeamMembers: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rsp.NextPage == 0 || nextPage == rsp.NextPage {
|
for _, user := range users {
|
||||||
break
|
teamMembers = append(teamMembers, user.Login)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rsp.NextPage == 0 || nextPage == rsp.NextPage {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
nextPage = rsp.NextPage
|
||||||
}
|
}
|
||||||
nextPage = rsp.NextPage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return teamMembers
|
return teamMembers
|
||||||
|
|
Loading…
Reference in New Issue