-
Notifications
You must be signed in to change notification settings - Fork 0
/
zenhubutils.py
65 lines (53 loc) · 1.4 KB
/
zenhubutils.py
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
import migrationauth
import requests
base_url = 'https://api.zenhub.com/public/graphql'
headers = {
'Authorization': f'Bearer {migrationauth.ZENHUB_TOKEN}',
'Content-Type': 'application/json',
}
workspace_id = '604fab62d4b98d00150a2854'
def get_issue_data(gh_repo_id, gh_issue_number):
"""Get ZenHub Pipeline and Releases for a GitHub issue"""
query = """query {
issueByInfo(
repositoryGhId: """+gh_repo_id+""",
issueNumber: """+gh_issue_number+"""
) {
releases {
nodes {
title
}
}
pipelineIssue(workspaceId: \""""+workspace_id+"""\") {
pipeline {
name
}
}
estimate {
value
}
}
}"""
response = requests.post(
base_url,
headers=headers,
json={'query': query}
)
if not response.ok:
print(
f'* An unexpected response was returned from ZenHub: {response} {response.reason}')
exit(1)
response_json = response.json()
issue_info = response_json['data']['issueByInfo']
estimate = None
if issue_info['estimate']:
estimate = issue_info['estimate']['value']
pipeline = issue_info['pipelineIssue']['pipeline']['name']
releases = []
for release in issue_info['releases']['nodes']:
releases.append(release['title'])
return {
'estimate': estimate,
'pipeline': pipeline,
'releases': releases
}