forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries_user.go
45 lines (41 loc) · 1 KB
/
queries_user.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
package api
type Organization struct {
Login string
}
func CurrentLoginName(client *Client, hostname string) (string, error) {
var query struct {
Viewer struct {
Login string
}
}
err := client.Query(hostname, "UserCurrent", &query, nil)
return query.Viewer.Login, err
}
func CurrentLoginNameAndOrgs(client *Client, hostname string) (string, []string, error) {
var query struct {
Viewer struct {
Login string
Organizations struct {
Nodes []Organization
} `graphql:"organizations(first: 100)"`
}
}
err := client.Query(hostname, "UserCurrent", &query, nil)
if err != nil {
return "", nil, err
}
orgNames := []string{}
for _, org := range query.Viewer.Organizations.Nodes {
orgNames = append(orgNames, org.Login)
}
return query.Viewer.Login, orgNames, err
}
func CurrentUserID(client *Client, hostname string) (string, error) {
var query struct {
Viewer struct {
ID string
}
}
err := client.Query(hostname, "UserCurrent", &query, nil)
return query.Viewer.ID, err
}