Skip to content

Commit 567b6f0

Browse files
committed
Update enrich issue comment and pull comment
Signed-off-by: lishengbao <[email protected]>
1 parent 59dc673 commit 567b6f0

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

grimoire_elk_gitcode/enriched/gitcode2.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def get_rich_pull_reviews(self, comments, eitem):
420420
# Copy data from the raw comment
421421
ecomment['body'] = comment['body'][:self.KEYWORD_MAX_LENGTH]
422422
ecomment['body_analyzed'] = comment['body']
423-
ecomment['url'] = comment['html_url']
423+
# ecomment['url'] = comment['html_url']
424424

425425
# extract reactions and add it to enriched item
426426
ecomment.update(self.__get_reactions(comment))
@@ -524,6 +524,11 @@ def __get_rich_pull(self, item):
524524
self.copy_raw_fields(self.RAW_FIELDS_COPY, item, rich_pr)
525525
# The real data
526526
pull_request = item['data']
527+
528+
if pull_request['closed_at'] == '':
529+
pull_request['closed_at'] = None
530+
if pull_request['merged_at'] == '':
531+
pull_request['merged_at'] = None
527532

528533
rich_pr['time_to_close_days'] = \
529534
get_time_diff_days(pull_request['created_at'], pull_request['closed_at'])
@@ -541,26 +546,26 @@ def __get_rich_pull(self, item):
541546
rich_pr['user_name'] = user['name']
542547
rich_pr['author_name'] = user['name']
543548
rich_pr['user_email'] = user.get('email', None)
544-
rich_pr["user_domain"] = self.get_email_domain(user['email']) if user['email'] else None
545-
rich_pr['user_org'] = user['company']
546-
# rich_pr['user_location'] = user['location']
549+
rich_pr["user_domain"] = self.get_email_domain(user['email']) if user.get('email', None) else None
550+
rich_pr['user_org'] = user.get('company', None)
551+
rich_pr['user_location'] = user.get('location', None)
547552
rich_pr['user_geolocation'] = None
548553
else:
549554
rich_pr['user_name'] = None
555+
rich_pr['user_email'] = None
550556
rich_pr["user_domain"] = None
551557
rich_pr['user_org'] = None
552558
rich_pr['user_location'] = None
553559
rich_pr['user_geolocation'] = None
554560
rich_pr['author_name'] = None
555-
rich_pr['user_email'] = None
556561

557562
merged_by = pull_request.get('merged_by_data', None)
558563
if merged_by and merged_by != USER_NOT_AVAILABLE:
559564
rich_pr['merge_author_login'] = merged_by['login']
560565
rich_pr['merge_author_name'] = merged_by['name']
561-
rich_pr["merge_author_domain"] = self.get_email_domain(merged_by['email']) if merged_by['email'] else None
562-
rich_pr['merge_author_org'] = merged_by['company']
563-
# rich_pr['merge_author_location'] = merged_by['location']
566+
rich_pr["merge_author_domain"] = self.get_email_domain(merged_by['email']) if merged_by.get('email', None) else None
567+
rich_pr['merge_author_org'] = merged_by.get('company', None)
568+
rich_pr['merge_author_location'] = merged_by.get('location', None)
564569
rich_pr['merge_author_geolocation'] = None
565570
else:
566571
rich_pr['merge_author_name'] = None
@@ -635,12 +640,15 @@ def __get_rich_issue(self, item):
635640
self.copy_raw_fields(self.RAW_FIELDS_COPY, item, rich_issue)
636641
# The real data
637642
issue = item['data']
643+
644+
if issue['finished_at'] == '':
645+
issue['finished_at'] = None
638646

639647
rich_issue['time_to_close_days'] = \
640648
get_time_diff_days(issue['created_at'], issue['finished_at'])
641649

642-
#issue have four status: open,progressing, closed, rejected.
643-
if issue['state'] == 'open' or issue['state'] == 'progressing':
650+
#issue have four status: open, closed.
651+
if issue['state'] == 'open':
644652
rich_issue['time_open_days'] = \
645653
get_time_diff_days(issue['created_at'], datetime_utcnow().replace(tzinfo=None))
646654
else:
@@ -653,26 +661,26 @@ def __get_rich_issue(self, item):
653661
rich_issue['user_name'] = user['name']
654662
rich_issue['author_name'] = user['name']
655663
rich_issue['user_email'] = user.get('email', None)
656-
rich_issue["user_domain"] = self.get_email_domain(user['email']) if user['email'] else None
657-
rich_issue['user_org'] = user['company']
658-
# rich_issue['user_location'] = user['location']
664+
rich_issue["user_domain"] = self.get_email_domain(user['email']) if user.get('email', None) else None
665+
rich_issue['user_org'] = user.get('company', None)
666+
rich_issue['user_location'] = user.get('location', None)
659667
rich_issue['user_geolocation'] = None
660668
else:
661669
rich_issue['user_name'] = None
670+
rich_issue['user_email'] = None
662671
rich_issue["user_domain"] = None
663672
rich_issue['user_org'] = None
664673
rich_issue['user_location'] = None
665674
rich_issue['user_geolocation'] = None
666675
rich_issue['author_name'] = None
667-
rich_issue['user_email'] = None
668676

669677
assignee = issue.get('assignee_data', None)
670678
if assignee and assignee != USER_NOT_AVAILABLE:
671679
rich_issue['assignee_login'] = assignee['login']
672680
rich_issue['assignee_name'] = assignee['name']
673-
rich_issue["assignee_domain"] = self.get_email_domain(assignee['email']) if assignee['email'] else None
674-
rich_issue['assignee_org'] = assignee['company']
675-
# rich_issue['assignee_location'] = assignee['location']
681+
rich_issue["assignee_domain"] = self.get_email_domain(assignee['email']) if assignee.get('email', None) else None
682+
rich_issue['assignee_org'] = assignee.get('company', None)
683+
rich_issue['assignee_location'] = assignee.get('location', None)
676684
rich_issue['assignee_geolocation'] = None
677685
else:
678686
rich_issue['assignee_name'] = None
@@ -703,9 +711,7 @@ def __get_rich_issue(self, item):
703711
rich_issue['issue_labels'] = labels
704712

705713
rich_issue['item_type'] = ISSUE_TYPE
706-
rich_issue['issue_pull_request'] = True
707-
if 'head' not in issue.keys() and 'pull_request' not in issue.keys():
708-
rich_issue['issue_pull_request'] = False
714+
rich_issue['issue_pull_request'] = False
709715

710716
rich_issue['gitcode_repo'] = rich_issue['repository'].replace(GITCODE, '')
711717
rich_issue['gitcode_repo'] = re.sub('.git$', '', rich_issue['gitcode_repo'])

0 commit comments

Comments
 (0)