-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
users.go
78 lines (67 loc) · 1.37 KB
/
users.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"github.com/shurcooL/githubv4"
)
var viewerQuery struct {
Viewer struct {
Login githubv4.String
}
}
var recentFollowersQuery struct {
User struct {
Login githubv4.String
Followers struct {
TotalCount githubv4.Int
Edges []struct {
Cursor githubv4.String
Node qlUser
}
} `graphql:"followers(first: $count)"`
} `graphql:"user(login:$username)"`
}
func getUsername() (string, error) {
err := gitHubClient.Query(context.Background(), &viewerQuery, nil)
if err != nil {
return "", err
}
return string(viewerQuery.Viewer.Login), nil
}
func recentFollowers(count int) []User {
// fmt.Printf("Finding recent followers...\n")
var users []User
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
}
err := gitHubClient.Query(context.Background(), &recentFollowersQuery, variables)
if err != nil {
panic(err)
}
// fmt.Printf("%+v\n", query)
for _, v := range recentFollowersQuery.User.Followers.Edges {
users = append(users, userFromQL(v.Node))
}
// fmt.Printf("Found %d recent followers!\n", len(users))
return users
}
/*
{
user(login: "muesli") {
login
followers(first: 10) {
totalCount
edges {
cursor
node {
id
avatarUrl
login
name
url
}
}
}
}
}
*/