forked from muesli/markscribe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gists.go
62 lines (54 loc) · 1.06 KB
/
gists.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
package main
import (
"context"
"github.com/shurcooL/githubv4"
)
var gistsQuery struct {
User struct {
Login githubv4.String
Gists struct {
TotalCount githubv4.Int
Edges []struct {
Cursor githubv4.String
Node qlGist
}
} `graphql:"gists(first: $count, orderBy: {field: CREATED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}
func gists(count int) []Gist {
// fmt.Printf("Finding gists...\n")
var gists []Gist
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
}
err := gitHubClient.Query(context.Background(), &gistsQuery, variables)
if err != nil {
panic(err)
}
// fmt.Printf("%+v\n", query)
for _, v := range gistsQuery.User.Gists.Edges {
gists = append(gists, gistFromQL(v.Node))
}
// fmt.Printf("Found %d gists!\n", len(gists))
return gists
}
/*
{
user(login: "muesli") {
login
gists(first: 100) {
totalCount
edges {
cursor
node {
name
description
url
createdAt
}
}
}
}
}
*/