@@ -172,7 +172,7 @@ def get_time_to_first_attention(self, item):
172
172
other than the user who created the issue
173
173
"""
174
174
comment_dates = [str_to_datetime (comment ['created_at' ]) for comment in item ['comments_data' ]
175
- if item ['user' ]['login' ] != comment ['user' ]['login' ]]
175
+ if 'user' in comment and 'user' in item and item ['user' ]['login' ] != comment ['user' ]['login' ]]
176
176
if comment_dates :
177
177
return min (comment_dates )
178
178
return None
@@ -182,8 +182,8 @@ def get_num_of_comments_without_bot(self, item):
182
182
other than the user who created the issue and bot
183
183
"""
184
184
comments = [comment for comment in item ['comments_data' ]
185
- if item ['user' ]['login' ] != comment ['user' ]['login' ] \
186
- and not (comment ['user' ][ 'name' ] .endswith ("bot" ))]
185
+ if 'user' in comment and 'user' in item and item ['user' ]['login' ] != comment ['user' ]['login' ] \
186
+ and not (comment ['user' ]. get ( 'name' , '' ) .endswith ("bot" ))]
187
187
return len (comments )
188
188
189
189
#get first attendtion without bot
@@ -192,8 +192,8 @@ def get_time_to_first_attention_without_bot(self, item):
192
192
other than the user who created the issue and bot
193
193
"""
194
194
comment_dates = [str_to_datetime (comment ['created_at' ]) for comment in item ['comments_data' ]
195
- if item ['user' ]['login' ] != comment ['user' ]['login' ] \
196
- and not (comment ['user' ][ 'name' ] .endswith ("bot" ))]
195
+ if 'user' in comment and 'user' in item and item ['user' ]['login' ] != comment ['user' ]['login' ] \
196
+ and not (comment ['user' ]. get ( 'name' , '' ) .endswith ("bot" ))]
197
197
if comment_dates :
198
198
return min (comment_dates )
199
199
return None
@@ -203,9 +203,9 @@ def get_num_of_reviews_without_bot(self, item):
203
203
other than the user who created the issue and bot
204
204
"""
205
205
comments = [comment for comment in item ['review_comments_data' ]
206
- if item ['user' ]['login' ] != comment ['user' ]['login' ] \
207
- and not (comment ['user' ][ 'name' ] .endswith ("bot" )) \
208
- and not (comment ['user' ][ 'name' ] .endswith ("ci" ))]
206
+ if 'user' in comment and 'user' in item and item ['user' ]['login' ] != comment ['user' ]['login' ] \
207
+ and not (comment ['user' ]. get ( 'name' , '' ) .endswith ("bot" )) \
208
+ and not (comment ['user' ]. get ( 'name' , '' ) .endswith ("ci" ))]
209
209
return len (comments )
210
210
211
211
def get_time_to_merge_request_response (self , item ):
@@ -215,7 +215,10 @@ def get_time_to_merge_request_response(self, item):
215
215
review_dates = []
216
216
for comment in item ['review_comments_data' ]:
217
217
# skip comments of ghost users
218
- if not comment ['user' ]:
218
+ if 'user' not in comment or not comment ['user' ]:
219
+ continue
220
+
221
+ if 'user' not in item or not item ['user' ]:
219
222
continue
220
223
221
224
# skip comments of the pull request creator
@@ -235,8 +238,8 @@ def get_time_to_first_review_attention_without_bot(self, item):
235
238
other than the user who created the pr and bot
236
239
"""
237
240
comment_dates = [str_to_datetime (comment ['created_at' ]) for comment in item ['review_comments_data' ]
238
- if item ['user' ]['login' ] != comment ['user' ]['login' ] \
239
- and not (comment ['user' ][ 'name' ] .endswith ("bot" ))]
241
+ if 'user' in comment and 'user' in item and item ['user' ]['login' ] != comment ['user' ]['login' ] \
242
+ and not (comment ['user' ]. get ( 'name' , '' ) .endswith ("bot" ))]
240
243
if comment_dates :
241
244
return min (comment_dates )
242
245
return None
@@ -252,7 +255,7 @@ def get_latest_comment_date(self, item):
252
255
def get_num_commenters (self , item ):
253
256
"""Get the number of unique people who commented on the issue/pr"""
254
257
255
- commenters = [comment ['user' ]['login' ] for comment in item ['comments_data' ]]
258
+ commenters = [comment ['user' ]['login' ] for comment in item ['comments_data' ] if 'user' in comment ]
256
259
return len (set (commenters ))
257
260
258
261
def get_CVE_message (self , item ):
@@ -327,7 +330,7 @@ def __get_rich_pull(self, item):
327
330
else :
328
331
rich_pr ['time_open_days' ] = rich_pr ['time_to_close_days' ]
329
332
330
- rich_pr ['user_login' ] = pull_request [ 'user' ][ 'login' ]
333
+ rich_pr ['user_login' ] = pull_request . get ( 'user' , {}). get ( 'login' )
331
334
332
335
user = pull_request .get ('user_data' , None )
333
336
if user is not None and user :
@@ -382,6 +385,7 @@ def __get_rich_pull(self, item):
382
385
rich_pr ['merged_at' ] = pull_request ['merged_at' ]
383
386
rich_pr ['closed_at' ] = pull_request ['closed_at' ]
384
387
rich_pr ['url' ] = pull_request ['html_url' ]
388
+ rich_pr ['review_mode' ] = pull_request .get ('review_mode' )
385
389
labels = []
386
390
[labels .append (label ['name' ]) for label in pull_request ['labels' ] if 'labels' in pull_request ]
387
391
rich_pr ['labels' ] = labels
@@ -441,7 +445,7 @@ def __get_rich_issue(self, item):
441
445
# The real data
442
446
issue = item ['data' ]
443
447
444
- if issue ['finished_at' ] == '' :
448
+ if 'finished_at' not in issue or issue ['finished_at' ] == '' :
445
449
issue ['finished_at' ] = None
446
450
447
451
rich_issue ['time_to_close_days' ] = \
@@ -454,7 +458,7 @@ def __get_rich_issue(self, item):
454
458
else :
455
459
rich_issue ['time_open_days' ] = rich_issue ['time_to_close_days' ]
456
460
457
- rich_issue ['user_login' ] = issue [ 'user' ][ 'login' ]
461
+ rich_issue ['user_login' ] = issue . get ( 'user' , {}). get ( 'login' )
458
462
459
463
user = issue .get ('user_data' , None )
460
464
if user is not None and user :
@@ -500,7 +504,7 @@ def __get_rich_issue(self, item):
500
504
rich_issue ['updated_at' ] = issue ['updated_at' ]
501
505
rich_issue ['closed_at' ] = issue ['finished_at' ]
502
506
rich_issue ['url' ] = issue ['html_url' ]
503
- rich_issue ['issue_type' ] = None
507
+ rich_issue ['issue_type' ] = issue . get ( 'issue_type' )
504
508
labels = []
505
509
[labels .append (label ['name' ]) for label in issue ['labels' ] if 'labels' in issue ]
506
510
rich_issue ['labels' ] = labels
@@ -616,6 +620,9 @@ def __get_rich_repo(self, item):
616
620
return rich_repo
617
621
618
622
def get_event_type (self , action_type , content ):
623
+ if action_type is None :
624
+ return None
625
+
619
626
rules = [
620
627
(lambda : action_type == "label" and "add" in content , "LabeledEvent" ),
621
628
(lambda : action_type == "label" and "delete" in content , "UnlabeledEvent" ),
@@ -674,7 +681,7 @@ def __get_rich_event(self, item):
674
681
675
682
# move the issue reporter to level of actor. This is needed to
676
683
# allow `get_item_sh` adding SortingHat identities
677
- reporter = main_content [ 'user' ]
684
+ reporter = main_content . get ( 'user' , {})
678
685
item ['data' ]['reporter' ] = reporter
679
686
item ['data' ]['actor' ] = actor
680
687
@@ -684,8 +691,8 @@ def __get_rich_event(self, item):
684
691
rich_event ['user_login' ] = rich_event ['actor_username' ]
685
692
rich_event ['content' ] = event ['content' ]
686
693
rich_event ['created_at' ] = event ['created_at' ]
687
- rich_event ['action_type' ] = event [ 'action_type' ]
688
- rich_event ['event_type' ] = self .get_event_type (event [ 'action_type' ] , event ['content' ])
694
+ rich_event ['action_type' ] = event . get ( 'action_type' )
695
+ rich_event ['event_type' ] = self .get_event_type (event . get ( 'action_type' ) , event ['content' ])
689
696
rich_event ['repository' ] = item ["tag" ]
690
697
rich_event ['pull_request' ] = False if 'issue' in event else True
691
698
rich_event ['item_type' ] = 'issue' if 'issue' in event else 'pull request'
@@ -700,7 +707,7 @@ def __get_rich_event(self, item):
700
707
rich_event ['pull_state' ] = main_content ['state' ]
701
708
rich_event ['pull_created_at' ] = main_content ['created_at' ]
702
709
rich_event ['pull_updated_at' ] = main_content ['updated_at' ]
703
- rich_event ['pull_closed_at' ] = main_content ['closed_at' ]
710
+ rich_event ['pull_closed_at' ] = None if main_content [ 'closed_at' ] == '' else main_content ['closed_at' ]
704
711
rich_event ['pull_url' ] = main_content ['html_url' ]
705
712
rich_event ['pull_labels' ] = [label ['name' ] for label in main_content ['labels' ]]
706
713
rich_event ["pull_url_id" ] = rich_event ['gitcode_repo' ] + "/pull/" + rich_event ['pull_id_in_repo' ]
@@ -712,9 +719,9 @@ def __get_rich_event(self, item):
712
719
rich_event ['issue_state' ] = main_content ['state' ]
713
720
rich_event ['issue_created_at' ] = main_content ['created_at' ]
714
721
rich_event ['issue_updated_at' ] = main_content ['updated_at' ]
715
- rich_event ['issue_closed_at' ] = main_content ['finished_at' ]
716
- rich_event ['issue_finished_at' ] = main_content [ 'finished_at ' ]
717
- rich_event ['issue_url' ] = main_content ['html_url' ]
722
+ rich_event ['issue_closed_at' ] = None if main_content [ 'finished_at' ] == '' else main_content ['finished_at' ]
723
+ rich_event ['issue_finished_at' ] = rich_event [ 'issue_closed_at ' ]
724
+ rich_event ['issue_url' ] = main_content ['html_url' ]
718
725
rich_event ['issue_labels' ] = [label ['name' ] for label in main_content ['labels' ]]
719
726
rich_event ["issue_url_id" ] = rich_event ['gitcode_repo' ] + "/issues/" + rich_event ['issue_id_in_repo' ]
720
727
0 commit comments