11import csv
22import pytz
33
4- from github import Github , Repository , GithubException
5-
64from github import Github , Repository , GithubException , PullRequest
75
86EMPTY_FIELD = 'Empty field'
97
108
119def login (token ):
1210 client = Github (login_or_token = token )
11+
1312 try :
1413 client .get_user ().login
1514 except GithubException as err :
@@ -73,7 +72,6 @@ def log_repository_commits(repository: Repository, csv_name, start, finish):
7372 continue
7473 if commit .commit is not None :
7574 info = {'repository name' : repository .full_name ,
76- 'commit id' : commit .commit .sha ,
7775 'author name' : commit .commit .author .name ,
7876 'author login' : EMPTY_FIELD ,
7977 'author email' : EMPTY_FIELD ,
@@ -94,7 +92,8 @@ def log_issue_to_csv(info, csv_name):
9492 fieldnames = ['repository name' , 'number' , 'title' , 'state' , 'task' , 'created at' , 'creator name' , 'creator login' ,
9593 'creator email' , 'closer name' , 'closer login' , 'closer email' , 'closed at' , 'comment body' ,
9694 'comment created at' , 'comment author name' , 'comment author login' , 'comment author email' ,
97- 'assignee story' , ]
95+ 'assignee story' , 'connected pull requests' ]
96+
9897 with open (csv_name , 'a' , newline = '' ) as file :
9998 writer = csv .DictWriter (file , fieldnames = fieldnames )
10099 writer .writerow (info )
@@ -126,7 +125,11 @@ def log_repository_issues(repository: Repository, csv_name, start, finish):
126125 'comment author login' : EMPTY_FIELD ,
127126 'comment author email' : EMPTY_FIELD ,
128127 'assignee story' : EMPTY_FIELD ,
128+ 'connected pull requests' : EMPTY_FIELD
129129 }
130+ if issue .number is not None :
131+ info_tmp ['connected pull requests' ] = get_connected_pulls (issue .number , repository .owner , repository .name ,
132+ token )
130133
131134 info_tmp ['assignee story' ] = get_assignee_story (issue )
132135
@@ -159,7 +162,7 @@ def log_pr_to_csv(info, csv_name):
159162 'creator login' , 'creator email' ,
160163 'changed files' , 'comment body' , 'comment created at' , 'comment author name' , 'comment author login' ,
161164 'comment author email' , 'merger name' , 'merger login' , 'merger email' , 'source branch' ,
162- 'target branch' , 'assignee story' , ]
165+ 'target branch' , 'assignee story' , 'related issues' ]
163166 with open (csv_name , 'a' , newline = '' ) as file :
164167 writer = csv .DictWriter (file , fieldnames = fieldnames )
165168 writer .writerow (info )
@@ -197,7 +200,10 @@ def log_repositories_pr(repository: Repository, csv_name, start, finish):
197200 'source branch' : pull .head .ref ,
198201 'target branch' : pull .base .ref ,
199202 'assignee story' : EMPTY_FIELD ,
203+ 'related issues' : EMPTY_FIELD
200204 }
205+ if pull .issue_url is not None :
206+ info_tmp ['related issues' ] = get_related_issues (pull .number , repository .owner , repository .name , token )
201207
202208 if pull .merged_by is not None :
203209 info_tmp ['merger name' ] = pull .merged_by .name
@@ -247,7 +253,9 @@ def log_pull_requests(client: Github, repositories, csv_name, start, finish):
247253 'merger email' ,
248254 'source branch' ,
249255 'target branch' ,
256+ 'related issues'
250257 'assignee story' ,
258+ 'related issues'
251259 )
252260 )
253261
@@ -278,7 +286,9 @@ def log_issues(client: Github, repositories, csv_name, start, finish):
278286 'comment author name' ,
279287 'comment author login' ,
280288 'comment author email' ,
289+ 'connected pull requests'
281290 'assignee story' ,
291+ 'connected pull requests'
282292 )
283293 )
284294
@@ -292,12 +302,12 @@ def log_commits(client: Github, repositories, csv_name, start, finish):
292302 writer .writerow (
293303 (
294304 'repository name' ,
295- 'commit id' ,
296305 'author name' ,
297306 'author login' ,
298307 'author email' ,
299308 'date and time' ,
300309 'changed files' ,
310+ 'commit id'
301311 )
302312 )
303313
0 commit comments