-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphql.go
109 lines (101 loc) · 2.41 KB
/
graphql.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"encoding/json"
"fmt"
)
// No changes here, please.
var graphQLquery = `query ($limit: Int!) {
viewer {
repository(name: "%s") {
name
pullRequests(first: $limit, states: OPEN) {
totalCount
edges {
node {
number
title
url
labels(first: $limit) {
totalCount
edges {
node {
name
}
}
}
reviews(first: $limit, states: [APPROVED, CHANGES_REQUESTED]) {
totalCount
edges {
node {
author {
login
}
state
}
}
}
}
}
}
}
}
}`
// 100 should be enough forever, come on.
var graphQLvariables = `{
"limit": 100
}`
// GraphQLRequestBody represents a valid GraphQL request body.
type GraphQLRequestBody struct {
Query string `json:"query"`
Variables string `json:"variables"`
}
// GraphQLResponseBody represents the expected GraphQL response body.
type GraphQLResponseBody struct {
Data struct {
Viewer struct {
Repository struct {
Name string `json:"name"`
PullRequests struct {
TotalCount int `json:"totalCount"`
Edges []struct {
Node struct {
Number int `json:"number"`
Title string `json:"title"`
URL string `json:"url"`
Labels struct {
TotalCount int `json:"totalCount"`
Edges []struct {
Node struct {
Name string `json:"name"`
} `json:"node"`
} `json:"edges"`
} `json:"labels"`
Reviews struct {
TotalCount int `json:"totalCount"`
Edges []struct {
Node struct {
Author struct {
Login string `json:"login"`
} `json:"author"`
State string `json:"state"`
} `json:"node"`
} `json:"edges"`
} `json:"reviews"`
} `json:"node"`
} `json:"edges"`
} `json:"pullRequests"`
} `json:"repository"`
} `json:"viewer"`
} `json:"data"`
}
func buildGraphQLRequestBody(repository string) string {
r := GraphQLRequestBody{
Query: fmt.Sprintf(graphQLquery, repository),
Variables: graphQLvariables,
}
body, err := json.Marshal(r)
if err != nil {
panic(err)
}
return string(body)
}