-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpulls.py
More file actions
81 lines (75 loc) · 1.58 KB
/
pulls.py
File metadata and controls
81 lines (75 loc) · 1.58 KB
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
#!/usr/bin/env python3
from gql import gql, Client, AIOHTTPTransport
from os import environ
from sys import argv
transport = AIOHTTPTransport(
url="https://api.github.com/graphql",
headers={"Authorization": "bearer " + environ["GITHUB_TOKEN"]},
)
client = Client(transport=transport, fetch_schema_from_transport=True)
def make_request(after=None):
if after is None:
query = gql(
"""
query {
user(login: \""""
+ argv[1]
+ """\") {
pullRequests(first: 100) {
edges {
node {
url
}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
totalCount
}
}
}
"""
)
else:
query = gql(
"""
query {
user(login: \""""
+ argv[1]
+ """\") {
pullRequests(first: 100, after: \""""
+ after
+ """\") {
edges {
node {
url
}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
totalCount
}
}
}
"""
)
result = client.execute(query)
for i in result["user"]["pullRequests"]["edges"]:
print(i["node"]["url"])
if result["user"]["pullRequests"]["pageInfo"]["hasNextPage"]:
return result["user"]["pullRequests"]["pageInfo"]["endCursor"]
else:
print("totalCount: " + str(result["user"]["pullRequests"]["totalCount"]))
return None
after = None
while True:
after = make_request(after=after)
if after is None:
break