-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweeklyreport.py
204 lines (173 loc) · 7.61 KB
/
weeklyreport.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"""
Welcome to the Weekly Report for Jira in GRIT
by dp24
Pulls
Weekly data split by project
- Tickets new
- Tickets modified
- Tickets Finished
All within a specified week.
REQUIRES:
- jira
Usage:
- For most recent week report
python3 weeklyreport.py -n
- For one week in the past
python3 weeklyreport.py -1w
- Two weeks would be
python3 weeklyreport.py -2w
- Output to TSV with:
python3 weeklyreport.py -1w > {TITLE}.tsv
"""
import sys
from jira import JIRA
import os
from dotenv import load_dotenv
import datetime
import maya
def dotloader():
load_dotenv()
jira_user = os.getenv('JIRA_USER')
jira_pass = os.getenv('JIRA_PASS')
return jira_user, jira_pass
def authorise(user, password):
jira = "https://grit-jira.sanger.ac.uk"
auth_jira = JIRA(jira, basic_auth=(user, password))
return auth_jira
def tickets_new(auth_jira, week_no, proj, queue):
"""
Tickets that were created this week
:param queue:
:param auth_jira:
:param week_no:
:param proj:
:return:
"""
if week_no == '-n':
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'created > startOfWeek() AND '
f'created < endOfWeek()',
maxResults=10000)
else:
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'created > startOfWeek({week_no}) AND '
f'created < endOfWeek({week_no})',
maxResults=10000)
print(f" ---- New Tickets ({queue}: {proj})---- ")
if len(projects) >= 1:
for i in projects:
issue = auth_jira.issue(f'{i}')
obj = maya.parse(issue.fields.created).datetime()
ymd_date = obj.date().strftime('%Y-%m-%d')
print(f"{issue.fields.customfield_10201}\t"
f"{issue.fields.issuetype.name}\t"
f"{issue.fields.resolution}\t"
f"{ymd_date}\t"
f"{issue.fields.status}")
else:
print("None")
def tickets_inprogress(auth_jira, week_no, proj, queue):
"""
Tickets that have been updated in the past week
:param queue:
:param auth_jira:
:param week_no:
:param proj:
:return:
"""
# NEED TO ADD ABOUT IN SUBMISSION TOO
if week_no == '-n':
if queue == '"Rapid Curation"':
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'resolution = "Unresolved" AND '
f'status != "Submitted" AND '
f'updated > startOfWeek() AND '
f'updated < endOfWeek()',
maxResults=10000)
else:
# This doesn't use datetime stuff at all on purpose,
# if it did it would remove tickets that are not updated at least once per week.
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'resolution = "In progress" AND '
f'status != "Submitted" AND '
f'updated > startOfWeek() AND '
f'updated < endOfWeek()',
maxResults=10000)
else:
if queue == '"Rapid Curation"':
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'resolution = "Unresolved" AND '
f'status != "Submitted" AND '
f'updated > startOfWeek({week_no}) AND '
f'updated < endOfWeek({week_no})',
maxResults=10000)
else:
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'resolution = "In progress" AND '
f'status != "Submitted" AND '
f'updated > startOfWeek({week_no}) AND '
f'updated < endOfWeek({week_no})',
maxResults=10000)
print(f" ---- Inprogress Tickets ({queue}: {proj}) ---- ")
if len(projects) >= 1:
for i in projects:
issue = auth_jira.issue(f'{i}')
obj = maya.parse(issue.fields.updated).datetime()
ymd_date = obj.date().strftime('%Y-%m-%d')
print(f"{issue.fields.customfield_10201}\t"
f"{issue.fields.issuetype.name}\t"
f"{issue.fields.resolution}\t"
f"{ymd_date}\t"
f"{issue.fields.status}")
else:
print("None")
def tickets_submitted(auth_jira, week_no, proj, queue):
if week_no == '-n':
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'status = Submitted AND status = "In Submission" AND '
f'updated > startOfWeek() AND '
f'updated < endOfWeek()')
else:
projects = auth_jira.search_issues(f'project={queue} AND '
f'type {proj} AND '
f'status = Submitted AND status = "In Submission" AND '
f'updated > startOfWeek({week_no}) AND '
f'updated < endOfWeek({week_no})')
print(f" ---- Submitted Tickets ({queue}: {proj})---- ")
if len(projects) >= 1:
for i in projects:
issue = auth_jira.issue(f'{i}')
obj = maya.parse(issue.fields.updated).datetime()
ymd_date = obj.date().strftime('%Y-%m-%d')
print(f"{issue.fields.customfield_10201}\t"
f"{issue.fields.issuetype.name}\t"
f"{issue.fields.resolution}\t"
f"{ymd_date}\t"
f"{issue.fields.status}")
else:
print("None")
pass
def main():
# ASG will need to be added once in use. - 3, '!= "ASG" AND != "Darwin"'
queue_list = ['"Rapid Curation"', '"Assembly curation"']
project_list = ['= "Darwin"', '= "VGP"', '= "VGP+"', '= "ASG"', '= "ERGA"', '= "Faculty"', '= "Other"']
username, password = dotloader()
week_no = sys.argv[1]
auth_jira = authorise(username, password)
print(f'============== START for {datetime.date.today()} ============')
for i in queue_list:
for proj in project_list:
tickets_new(auth_jira, week_no, proj, i)
tickets_inprogress(auth_jira, week_no, proj, i)
tickets_submitted(auth_jira, week_no, proj, i)
print('================ QUEUE BREAK ================')
print(f'============== END for {datetime.date.today()} =============')
if __name__ == "__main__":
main()