-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira_service.py
71 lines (54 loc) · 1.68 KB
/
jira_service.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
66
67
68
69
70
71
from math import ceil
import requests
from conf import Conf
class JiraService:
def __init__(self, *args, **kwargs):
self.conf = Conf.get_conf()
self.headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': f"Basic {self.conf['api-token']}",
}
def _run_jql(self, host, jql):
params = {
"jql": jql
}
issues = []
res = requests.get(
f"{host}/rest/api/2/search",
params={
"jql": jql,
"maxResults": 50,
"startAt": 0,
},
headers=self.headers
)
res.raise_for_status()
res_json = res.json()
issues += res_json['issues']
page_count = ceil(res_json['total'] / 50)
for page in range(1, page_count):
params = {
"jql": jql,
"maxResults": 50,
"startAt": page * 50
}
res = requests.get(
f"{host}/rest/api/2/search",
params=params,
headers=self.headers
)
res.raise_for_status()
res_json = res.json()
issues += res_json['issues']
return issues
def get_issues(self, start_date=None, end_date=None):
jql = self.conf['issue-jql']
if start_date:
jql = jql + f" AND resolved >= {start_date}"
if end_date:
jql = jql + f" AND resolved <= {end_date}"
return self._run_jql(self.conf['host'], jql)
if __name__ == '__main__':
service = JiraService()
print(service.get_issues())