Skip to content

Commit aff63d4

Browse files
committed
adding makefile
1 parent 1266c3e commit aff63d4

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
SRC=main.go
3+
BIN=github-team-ssh-keys
4+
5+
all:
6+
GO111MODULE=on go build -o $(BIN) $(SRC)
7+
8+
run:
9+
GO111MODULE=on go run ${SRC} --github-org epitech --github-team sysadmin
10+
11+
clean:
12+
rm -f $(BIN)

main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ func githubBootContext() (*github.Client, context.Context) {
4343
return github.NewClient(tc), ctx
4444
}
4545

46-
func warningMsg(msg string) {
46+
func warningMsg(err error, msg string) {
47+
if err != nil {
48+
fmt.Fprintln(os.Stderr, err.Error())
49+
}
50+
4751
if werror != nil && *werror {
4852
log.Fatal(msg)
4953
} else {
50-
fmt.Fprintf(os.Stderr, msg)
54+
fmt.Fprintln(os.Stderr, msg)
5155
}
5256
}
5357

@@ -61,7 +65,7 @@ func getGithubOrgMembers() []string {
6165
for {
6266
users, resp, err := githubClient.Organizations.ListMembers(githubClientCtx, *githubOrg, opt)
6367
if err != nil {
64-
warningMsg(fmt.Sprintf("[warning] Github Organisation %s not found", githubOrg))
68+
warningMsg(err, fmt.Sprintf("[warning] Github Organisation \"%s\" not found", *githubOrg))
6569
break
6670
}
6771

@@ -82,7 +86,7 @@ func getGithubTeamMembers(teamName string) []string {
8286
// get team id from slug
8387
team, _, err := githubClient.Teams.GetTeamBySlug(githubClientCtx, *githubOrg, teamName)
8488
if err != nil {
85-
warningMsg(fmt.Sprintf("[warning] Github Organisation %s not found.\n", githubOrg))
89+
warningMsg(err, fmt.Sprintf("[warning] Github Organisation \"%s\" not found.\n", *githubOrg))
8690
return []string{}
8791
}
8892

@@ -95,7 +99,7 @@ func getGithubTeamMembers(teamName string) []string {
9599
for {
96100
users, resp, err := githubClient.Teams.ListTeamMembers(githubClientCtx, team.GetID(), opt)
97101
if err != nil {
98-
warningMsg(fmt.Sprintf("[warning] Github teams %s not found.\n", teamName))
102+
warningMsg(err, fmt.Sprintf("[warning] Github teams \"%s\" not found.\n", teamName))
99103
break
100104
}
101105

@@ -114,7 +118,7 @@ func getGithubTeamMembers(teamName string) []string {
114118
func getUserSSHKeys(username string) []string {
115119
resp, err := http.Get("https://github.com/" + username + ".keys")
116120
if err != nil {
117-
warningMsg(fmt.Sprintf("[warning] Github Organisation %s not found.\n", githubOrg))
121+
warningMsg(err, fmt.Sprintf("[warning] Failed to fetch public ssh key of user \"%s\"", username))
118122
return []string{}
119123
}
120124

@@ -150,7 +154,7 @@ func checkFlags() {
150154

151155
// warnings
152156
if len(*githubOrg) > 0 && len(*githubToken) == 0 {
153-
fmt.Fprintf(os.Stderr, "[warning] You provided --github-org without --github-token: organization private members won't be fetched.\n")
157+
fmt.Fprintln(os.Stderr, "[warning] You provided --github-org without --github-token: organization private members won't be fetched.")
154158
}
155159
}
156160

0 commit comments

Comments
 (0)