-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetTeammemberIssue.py
150 lines (127 loc) · 4.2 KB
/
GetTeammemberIssue.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
import requests
import json
import pymysql
import time
from datetime import datetime
import sys
import os
import base64
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import Utility.DBConfig as DB
import Utility.RepoConfig as Repo
def main():
"""
Main function to collect the issues associated with the team members
"""
selectKey = "SELECT DISTINCT(issue_key) FROM sprint_teammember_issue_new WHERE issue_key NOT IN (SELECT issue_key FROM collected_key)"
cursor.execute(selectKey)
result = cursor.fetchall()
for row in result:
currentKey = row['issue_key']
check = 0
try:
print("\n")
# collect the detail of the issue
collectDetail(currentKey, db.folder)
time.sleep(0.001)
# collect the comments of the issue
collectComment(currentKey, db.folder)
time.sleep(0.001)
# collect the change log of the issue
collectChangeLog(currentKey, db.folder)
time.sleep(0.001)
check = 1
except Exception as e:
print("ERROR: {}".format(e))
check = 0
time.sleep(1)
finally:
if check == 1:
storeDB(currentKey)
print("\n")
def storeDB(currentKey):
"""
Store the issue key into the database
"""
insertKey = "INSERT INTO collected_key(`issue_key`, `collectedTime`) VALUES(%s, %s)"
inputPara = (
currentKey,
datetime.now()
)
cursor.execute(insertKey, inputPara)
connection.commit()
print("Inserted {} successfully".format(currentKey))
def createRequest(url):
"""
Send a request to the given URL
<url>: The URL to send the request to
"""
# <api_token>: your api token for the repository
apiToken = "<api_token>"
headers = {
"Accept": "application/json",
"Bearer": apiToken,
}
try:
response = requests.request(
"GET",
url,
headers=headers
)
except requests.exceptions.RequestException as e:
print("ERROR: {}".format(e))
# sys.exit(1)
json_data = json.loads(response.text)
return json_data
def collectDetail(issueKey, folder):
"""
Collect the detail of the issue
"""
url = "https://{}/rest/api/2/issue/{}".format(repo.domain, issueKey)
json_data = createRequest(url)
writeFile(json_data, "detail", issueKey, folder, repo.name)
def collectComment(issueKey, folder):
"""
Collect the comments of the issue
"""
url = "https://{}/rest/api/2/issue/{}/comment".format(repo.domain, issueKey)
json_data = createRequest(url)
writeFile(json_data, "comment", issueKey, folder, repo.name)
def collectChangeLog(issueKey, folder):
"""
Collect the change logs of the issue
"""
url = "https://{}/rest/api/2/issue/{}?expand=changelog".format(repo.domain, issueKey)
json_data = createRequest(url)
writeFile(json_data, "changeLog", issueKey, folder, repo.name)
def writeFile(data, type, issueKey, folder, repo):
if type == "detail":
path = "<file_path>".format(folder, repo, issueKey)
elif type == "comment":
path = "<file_path>".format(folder, repo, issueKey)
elif type == "changeLog":
path = "<file_path>".format(folder, repo, issueKey)
try:
with open(path, 'w') as json_file:
json.dump(data, json_file, indent=4)
print("Write '{}' success!!".format(json_file.name))
except:
print("Write error!!")
sys.exit(1)
if __name__ == '__main__':
repo = Repo.createRepo()
db = DB.createDB(repo)
connection = pymysql.connect(
host=db.host,
port=db.port,
user=db.user,
passwd=db.pwd,
database=db.repo.name,
cursorclass=pymysql.cursors.DictCursor
)
cursor = connection.cursor()
main()
cursor.close()
connection.close()
print("DB Connection is closed")
print("----------------- COMPLETED -----------------")