-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReopenStatus.py
More file actions
116 lines (96 loc) · 3.67 KB
/
Copy pathReopenStatus.py
File metadata and controls
116 lines (96 loc) · 3.67 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
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
import sys
import os
import requests
import json
import base64
import pymysql
import time
from collections import Counter
import operator
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import Utility.JSONUtility as Utility
import Utility.RepoConfig as Repo
def collectReopenIss():
"""
Collect the number of reopen issue in the sprint
"""
print("Try to create new column [no_reopen] ...")
# Add no_reopen column
try:
addColumn = "ALTER TABLE sprint_issue_feature_insight ADD `reopen_status` TINYINT NOT NULL AFTER `no_comment`"
cursor.execute(addColumn)
connection.commit()
print("Add no_reopen column successfully")
except:
print("This repo already has no_reopen column")
print("Collect No Reopen Issue in Issue level")
select = "SELECT board_id, sprint_id, issue_key FROM sprint_issue_feature_insight"
cursor.execute(select)
result = cursor.fetchall()
for row in result:
countReOp = 0
currentBoardID = str(row['board_id'])
currentSprintID = str(row['sprint_id'])
currentIssueKey = str(row['issue_key'])
selectissue = "SELECT state FROM sprint_issue WHERE board_id = %s AND sprint_id = %s AND issue_key = %s AND exist_in_website = 1"
inputPara = (
currentBoardID,
currentSprintID,
currentIssueKey
)
cursor.execute(selectissue, inputPara)
res = cursor.fetchone()
if res['state'] == 'Completed':
selectComple = "SELECT complete_date FROM sprint_feature WHERE board_id = %s AND sprint_id = %s"
inputPara = (
currentBoardID,
currentSprintID
)
cursor.execute(selectComple, inputPara)
resultComple = cursor.fetchone()
currentcompleteDate = resultComple['complete_date']
selectChangelog = "SELECT CreatedDate FROM issue_changelog WHERE issue_key = %s"
inputPara = (
currentIssueKey
)
cursor.execute(selectChangelog, inputPara)
resultCl = cursor.fetchall()
for changelog in resultCl:
CreatedDate = changelog['CreatedDate']
# Modified 8//6/2019 - update criteria
try:
calTime = (currentcompleteDate-CreatedDate).days
except:
continue
if calTime <= 0 :
countReOp += 1
break
updateNoReopen = "UPDATE sprint_issue_feature_insight SET reopen_status = %s WHERE board_id = %s AND sprint_id = %s AND issue_key = %s"
inputPara = (
countReOp,
currentBoardID,
currentSprintID,
currentIssueKey
)
cursor.execute(updateNoReopen, inputPara)
connection.commit()
# print("Issue {} has {} no of being reopened".format(currentIssueKey, countReOp))
print("\r\n---------------------- UPDATE NO_REOPEN COMPLETED for {}----------------------\r\n".format(repo.upper()))
if __name__ == '__main__':
try:
repo = sys.argv[1]
except:
print("No argument")
sys.exit()
connection = pymysql.connect(
host="localhost",
user="root",
passwd="whateverpasswordiwant",
database=repo,
cursorclass=pymysql.cursors.DictCursor
)
cursor = connection.cursor()
collectReopenIss()
cursor.close()
connection.close()
print("DB Connection is closed")