-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
sponsors.go
93 lines (84 loc) · 2.03 KB
/
sponsors.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"context"
"github.com/shurcooL/githubv4"
)
var sponsorsQuery struct {
User struct {
Login githubv4.String
SponsorshipsAsMaintainer struct {
TotalCount githubv4.Int
Edges []struct {
Cursor githubv4.String
Node struct {
CreatedAt githubv4.DateTime
SponsorEntity struct {
Typename githubv4.String `graphql:"__typename"`
User qlUser `graphql:"... on User"`
Organization qlUser `graphql:"... on Organization"`
}
}
}
} `graphql:"sponsorshipsAsMaintainer(first: $count, orderBy: {field: CREATED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}
func sponsors(count int) []Sponsor {
// fmt.Printf("Finding sponsors...\n")
var sponsors []Sponsor
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
}
err := gitHubClient.Query(context.Background(), &sponsorsQuery, variables)
if err != nil {
panic(err)
}
// fmt.Printf("%+v\n", query)
for _, v := range sponsorsQuery.User.SponsorshipsAsMaintainer.Edges {
switch v.Node.SponsorEntity.Typename {
case "User":
sponsors = append(sponsors, Sponsor{
User: userFromQL(v.Node.SponsorEntity.User),
CreatedAt: v.Node.CreatedAt.Time,
})
case "Organization":
sponsors = append(sponsors, Sponsor{
User: userFromQL(v.Node.SponsorEntity.Organization),
CreatedAt: v.Node.CreatedAt.Time,
})
}
}
// fmt.Printf("Found %d sponsors!\n", len(users))
return sponsors
}
/*
{
user(login: "muesli") {
login
sponsorshipsAsMaintainer(first: 100) {
totalCount
edges {
cursor
node {
createdAt
sponsorEntity {
__typename
... on User {
login
name
avatarUrl
url
}
... on Organization {
login
name
avatarUrl
url
}
}
}
}
}
}
}
*/