-
Notifications
You must be signed in to change notification settings - Fork 33
/
helpers.go
63 lines (53 loc) · 1.25 KB
/
helpers.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
package main
import (
"context"
"log"
"github.com/google/go-github/v34/github"
"github.com/ktrysmt/go-bitbucket"
gitlab "github.com/xanzy/go-gitlab"
)
func getUsername(client interface{}, service string) string {
if client == nil {
log.Fatalf("Couldn't acquire a client to talk to %s", service)
}
if service == "github" {
ctx := context.Background()
user, _, err := client.(*github.Client).Users.Get(ctx, "")
if err != nil {
log.Fatal("Error retrieving username", err.Error())
}
return *user.Login
}
if service == "gitlab" {
user, _, err := client.(*gitlab.Client).Users.CurrentUser()
if err != nil {
log.Fatal("Error retrieving username", err.Error())
}
return user.Username
}
if service == "bitbucket" {
user, err := client.(*bitbucket.Client).User.Profile()
if err != nil {
log.Fatal("Error retrieving username", err.Error())
}
return user.Username
}
return ""
}
func validGitlabProjectMembership(membership string) bool {
validMemberships := []string{"all", "owner", "member", "starred"}
for _, m := range validMemberships {
if membership == m {
return true
}
}
return false
}
func contains(list []string, x string) bool {
for _, item := range list {
if item == x {
return true
}
}
return false
}