-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorg.go
46 lines (39 loc) · 941 Bytes
/
org.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
package main
import (
"log"
"strings"
"github.com/cli/go-gh/v2/pkg/api"
)
type LoginQuery struct {
Viewer struct {
Login string
}
}
func OrgRole(org string, team string, login string, host string) string {
opts := api.ClientOptions{
Host: host,
}
restClient, err := api.NewRESTClient(opts)
if err != nil {
log.Fatal(err)
}
// build query
query := []string{"orgs", org}
if team != "" {
query = append(query, "teams", team)
}
query = append(query, "memberships", login)
path := strings.Join(query, "/")
var resp map[string]interface{}
err = restClient.Get(path, &resp)
if err != nil {
// We can't seem to parse the error response to check the status code
// so we'll just check the error message instead.
// https://github.com/cli/go-gh/issues/118
if strings.Contains(err.Error(), "Not Found") {
noRoleErr(login, NestedEntityName(org, team))
}
log.Fatal(err)
}
return resp["role"].(string)
}