-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.go
60 lines (51 loc) · 1.32 KB
/
github.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
package main
import (
"context"
"github.com/shurcooL/githubv4"
)
func ListOpenPullRequests(ctx context.Context, client *githubv4.Client, owner, name string) ([]*PullRequest, error) {
var q struct {
Repository struct {
PullRequests struct {
Nodes []struct {
Number githubv4.Int
Title string
CreatedAt githubv4.DateTime
UpdatedAt githubv4.DateTime
Labels struct {
Nodes []struct {
Name string
}
} `graphql:"labels(first: 10)"`
Files struct {
Nodes []struct {
Path string
}
} `graphql:"files(first: 100)"`
}
} `graphql:"pullRequests(first: 100, states: OPEN)"`
} `graphql:"repository(owner: $owner, name: $name)"`
}
variables := map[string]interface{}{
"owner": githubv4.String("storj"),
"name": githubv4.String("storj"),
}
err := client.Query(ctx, &q, variables)
var prs []*PullRequest
for _, node := range q.Repository.PullRequests.Nodes {
pr := &PullRequest{
Number: int32(node.Number),
Title: node.Title,
CreatedAt: node.CreatedAt.Time,
UpdatedAt: node.UpdatedAt.Time,
}
for _, label := range node.Labels.Nodes {
pr.Labels = append(pr.Labels, label.Name)
}
for _, file := range node.Files.Nodes {
pr.Files = append(pr.Files, file.Path)
}
prs = append(prs, pr)
}
return prs, err
}