@@ -172,7 +172,7 @@ def get_time_to_first_attention(self, item):
172172 other than the user who created the issue
173173 """
174174 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' ]]
176176 if comment_dates :
177177 return min (comment_dates )
178178 return None
@@ -182,8 +182,8 @@ def get_num_of_comments_without_bot(self, item):
182182 other than the user who created the issue and bot
183183 """
184184 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" ))]
187187 return len (comments )
188188
189189 #get first attendtion without bot
@@ -192,8 +192,8 @@ def get_time_to_first_attention_without_bot(self, item):
192192 other than the user who created the issue and bot
193193 """
194194 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" ))]
197197 if comment_dates :
198198 return min (comment_dates )
199199 return None
@@ -203,9 +203,9 @@ def get_num_of_reviews_without_bot(self, item):
203203 other than the user who created the issue and bot
204204 """
205205 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" ))]
209209 return len (comments )
210210
211211 def get_time_to_merge_request_response (self , item ):
@@ -215,7 +215,10 @@ def get_time_to_merge_request_response(self, item):
215215 review_dates = []
216216 for comment in item ['review_comments_data' ]:
217217 # 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' ]:
219222 continue
220223
221224 # skip comments of the pull request creator
@@ -235,8 +238,8 @@ def get_time_to_first_review_attention_without_bot(self, item):
235238 other than the user who created the pr and bot
236239 """
237240 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" ))]
240243 if comment_dates :
241244 return min (comment_dates )
242245 return None
@@ -252,7 +255,7 @@ def get_latest_comment_date(self, item):
252255 def get_num_commenters (self , item ):
253256 """Get the number of unique people who commented on the issue/pr"""
254257
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 ]
256259 return len (set (commenters ))
257260
258261 def get_CVE_message (self , item ):
@@ -327,7 +330,7 @@ def __get_rich_pull(self, item):
327330 else :
328331 rich_pr ['time_open_days' ] = rich_pr ['time_to_close_days' ]
329332
330- rich_pr ['user_login' ] = pull_request [ 'user' ][ 'login' ]
333+ rich_pr ['user_login' ] = pull_request . get ( 'user' , {}). get ( 'login' )
331334
332335 user = pull_request .get ('user_data' , None )
333336 if user is not None and user :
@@ -382,6 +385,7 @@ def __get_rich_pull(self, item):
382385 rich_pr ['merged_at' ] = pull_request ['merged_at' ]
383386 rich_pr ['closed_at' ] = pull_request ['closed_at' ]
384387 rich_pr ['url' ] = pull_request ['html_url' ]
388+ rich_pr ['review_mode' ] = pull_request .get ('review_mode' )
385389 labels = []
386390 [labels .append (label ['name' ]) for label in pull_request ['labels' ] if 'labels' in pull_request ]
387391 rich_pr ['labels' ] = labels
@@ -441,7 +445,7 @@ def __get_rich_issue(self, item):
441445 # The real data
442446 issue = item ['data' ]
443447
444- if issue ['finished_at' ] == '' :
448+ if 'finished_at' not in issue or issue ['finished_at' ] == '' :
445449 issue ['finished_at' ] = None
446450
447451 rich_issue ['time_to_close_days' ] = \
@@ -454,7 +458,7 @@ def __get_rich_issue(self, item):
454458 else :
455459 rich_issue ['time_open_days' ] = rich_issue ['time_to_close_days' ]
456460
457- rich_issue ['user_login' ] = issue [ 'user' ][ 'login' ]
461+ rich_issue ['user_login' ] = issue . get ( 'user' , {}). get ( 'login' )
458462
459463 user = issue .get ('user_data' , None )
460464 if user is not None and user :
@@ -500,7 +504,7 @@ def __get_rich_issue(self, item):
500504 rich_issue ['updated_at' ] = issue ['updated_at' ]
501505 rich_issue ['closed_at' ] = issue ['finished_at' ]
502506 rich_issue ['url' ] = issue ['html_url' ]
503- rich_issue ['issue_type' ] = None
507+ rich_issue ['issue_type' ] = issue . get ( 'issue_type' )
504508 labels = []
505509 [labels .append (label ['name' ]) for label in issue ['labels' ] if 'labels' in issue ]
506510 rich_issue ['labels' ] = labels
@@ -616,6 +620,9 @@ def __get_rich_repo(self, item):
616620 return rich_repo
617621
618622 def get_event_type (self , action_type , content ):
623+ if action_type is None :
624+ return None
625+
619626 rules = [
620627 (lambda : action_type == "label" and "add" in content , "LabeledEvent" ),
621628 (lambda : action_type == "label" and "delete" in content , "UnlabeledEvent" ),
@@ -674,7 +681,7 @@ def __get_rich_event(self, item):
674681
675682 # move the issue reporter to level of actor. This is needed to
676683 # allow `get_item_sh` adding SortingHat identities
677- reporter = main_content [ 'user' ]
684+ reporter = main_content . get ( 'user' , {})
678685 item ['data' ]['reporter' ] = reporter
679686 item ['data' ]['actor' ] = actor
680687
@@ -684,8 +691,8 @@ def __get_rich_event(self, item):
684691 rich_event ['user_login' ] = rich_event ['actor_username' ]
685692 rich_event ['content' ] = event ['content' ]
686693 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' ])
689696 rich_event ['repository' ] = item ["tag" ]
690697 rich_event ['pull_request' ] = False if 'issue' in event else True
691698 rich_event ['item_type' ] = 'issue' if 'issue' in event else 'pull request'
@@ -700,7 +707,7 @@ def __get_rich_event(self, item):
700707 rich_event ['pull_state' ] = main_content ['state' ]
701708 rich_event ['pull_created_at' ] = main_content ['created_at' ]
702709 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' ]
704711 rich_event ['pull_url' ] = main_content ['html_url' ]
705712 rich_event ['pull_labels' ] = [label ['name' ] for label in main_content ['labels' ]]
706713 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):
712719 rich_event ['issue_state' ] = main_content ['state' ]
713720 rich_event ['issue_created_at' ] = main_content ['created_at' ]
714721 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' ]
718725 rich_event ['issue_labels' ] = [label ['name' ] for label in main_content ['labels' ]]
719726 rich_event ["issue_url_id" ] = rich_event ['gitcode_repo' ] + "/issues/" + rich_event ['issue_id_in_repo' ]
720727
0 commit comments