forked from muesli/markscribe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stars.go
75 lines (67 loc) · 1.37 KB
/
stars.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
package main
import (
"context"
"github.com/shurcooL/githubv4"
)
var recentStarsQuery struct {
User struct {
Login githubv4.String
Stars struct {
TotalCount githubv4.Int
Edges []struct {
Cursor githubv4.String
StarredAt githubv4.DateTime
Node qlRepository
}
} `graphql:"starredRepositories(first: $count, after:$after, orderBy: {field: STARRED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}
func recentStars(count int) []Star {
var starredRepos []Star
var after *githubv4.String
outer:
for {
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
"after": after,
}
err := gitHubClient.Query(context.Background(), &recentStarsQuery, variables)
if err != nil {
panic(err)
}
for _, v := range recentStarsQuery.User.Stars.Edges {
if v.Node.IsPrivate {
continue
}
starredRepos = append(starredRepos, Star{
StarredAt: v.StarredAt.Time,
Repo: repoFromQL(v.Node),
})
if len(starredRepos) >= count {
break outer
}
after = githubv4.NewString(v.Cursor)
}
}
return starredRepos
}
/*
{
viewer {
login
starredRepositories(first: 3, orderBy: {field: STARRED_AT, direction: DESC}) {
totalCount
edges {
cursor
starredAt
node {
nameWithOwner
url
description
}
}
}
}
}
*/