Skip to content

Commit 59dc673

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

File tree

1 file changed

+49
-68
lines changed

1 file changed

+49
-68
lines changed

grimoire_elk_gitcode/enriched/gitcode.py

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -614,75 +614,50 @@ def __get_rich_repo(self, item):
614614
rich_repo.update(self.get_grimoire_fields(item['metadata__updated_on'], "repository"))
615615

616616
return rich_repo
617-
617+
618618
def get_event_type(self, action_type, content):
619-
if action_type == "label" and "add" in content:
620-
return "LabeledEvent"
621-
elif action_type == "label" and "delete" in content:
622-
return "UnlabeledEvent"
623-
elif action_type == "closed":
624-
return "ClosedEvent"
625-
elif action_type == "opened":
626-
return "ReopenedEvent"
627-
elif action_type == "assignee" and "assigned" in content:
628-
return "AssignedEvent"
629-
elif action_type == "assignee" and "unassigned" in content:
630-
return "UnassignedEvent"
631-
632-
633-
634-
switch_event_type = {
635-
"add_label": "LabeledEvent",
636-
"remove_label": "UnlabeledEvent",
637-
"closed_pr": "ClosedEvent",
638-
"reopened_pr": "ReopenedEvent",
639-
"set_assignee": "AssignedEvent",
640-
"setting_assignee": "AssignedEvent",
641-
"unset_assignee": "UnassignedEvent",
642-
"change_assignee": "UnassignedEvent",
643-
"set_milestone": "MilestonedEvent",
644-
"setting_milestone": "MilestonedEvent",
645-
"unset_milestone": "DemilestonedEvent",
646-
"change_milestone": "DemilestonedEvent",
647-
"update_title": "RenamedTitleEvent",
648-
"change_title": "RenamedTitleEvent",
649-
"merged_pr": "MergedEvent",
650-
"update_description": "ChangeDescriptionEvent",
651-
"change_description": "ChangeDescriptionEvent",
652-
"setting_priority": "SettingPriorityEvent",
653-
"change_priority": "ChangePriorityEvent"
654-
}
655-
if action_type in switch_event_type:
656-
return switch_event_type[action_type]
657-
else:
658-
return ''.join(word.capitalize() for word in action_type.split('_')) + "Event"
619+
rules = [
620+
(lambda: action_type == "label" and "add" in content, "LabeledEvent"),
621+
(lambda: action_type == "label" and "delete" in content, "UnlabeledEvent"),
622+
(lambda: action_type == "closed", "ClosedEvent"),
623+
(lambda: action_type == "opened", "ReopenedEvent"),
624+
(lambda: action_type == "milestone" and "changed" in content, "MilestonedEvent"),
625+
(lambda: action_type == "milestone" and "removed" in content, "DemilestonedEvent"),
626+
(lambda: action_type == "locked", "LockedEvent"),
627+
(lambda: action_type == "unlocked", "UnlockedEvent"),
628+
(lambda: action_type == "title", "RenamedTitleEvent"),
629+
(lambda: action_type == "merged", "MergedEvent"),
630+
(lambda: action_type == "description", "ChangeDescriptionEvent"),
631+
(lambda: action_type == "add_mr_issue_link", "LinkIssueEvent"),
632+
(lambda: action_type == "delete_mr_issue_link", "UnlinkIssueEvent"),
633+
(lambda: action_type == "add_issue_mr_link", "LinkPullRequestEvent"),
634+
(lambda: action_type == "delete_issue_mr_link", "UnlinkPullRequestEvent"),
635+
(lambda: action_type == "add_issue_branch_link", "SettingBranchEvent"),
636+
(lambda: action_type == "delete_issue_branch_link", "ChangeBranchEvent"),
637+
(lambda: action_type == "discussion", "DiscussionEvent"),
638+
(lambda: action_type == "confidential", "ConfidentialEvent"),
639+
(lambda: (action_type == "assignee" and "assigned" in content) or (action_type == "mr_change" and ("Add assignees" in content or "Add approvers" in content)),"AssignedEvent"),
640+
(lambda: (action_type == "assignee" and "unassigned" in content) or (action_type == "mr_change" and ("Delete assignees" in content or "Delete approvers" in content)),"UnassignedEvent"),
641+
(lambda: action_type == "mr_change" and "Add testers" in content, "SetTesterEvent"),
642+
(lambda: action_type == "mr_change" and "deleted testers" in content, "UnsetTesterEvent"),
643+
(lambda: action_type == "mr_change" and "Add reviewers" in content ,"SetReviewerEvent"),
644+
(lambda: action_type == "mr_change" and "Delete reviewers" in content ,"UnsetReviewerEvent"),
645+
(lambda: action_type == "mr_change" and "Approval Gate : pass" in content, "CheckPassEvent"),
646+
(lambda: action_type == "mr_change" and "Test Gate : pass" in content, "TestPassEvent"),
647+
(lambda: action_type == "mr_change" and "Review Gate : pass" in content, "ReviewPassEvent"),
648+
(lambda: action_type == "mr_change" and "Approval Gate : reset" in content, "ResetAssignResultEvent"),
649+
(lambda: action_type == "mr_change" and "Test Gate : reset" in content, "ResetTestResultEvent"),
650+
(lambda: action_type == "mr_change" and "Review Gate : reset" in content, "ResetReviewResultEvent"),
651+
(lambda: action_type == "mr_change" and "Approval Gate : reject" in content, "CheckRejectEvent"),
652+
(lambda: action_type == "mr_change" and "Test Gate : reject" in content, "TestRejectEvent"),
653+
(lambda: action_type == "mr_change" and "Review Gate : reject" in content, "ReviewRejectEvent"),
654+
]
655+
656+
for condition, event_type in rules:
657+
if condition():
658+
return event_type
659+
return None
659660

660-
def get_event_type(self, action_type, content):
661-
switch_event_type = {
662-
"add_label": "LabeledEvent",
663-
"remove_label": "UnlabeledEvent",
664-
"closed_pr": "ClosedEvent",
665-
"reopened_pr": "ReopenedEvent",
666-
"set_assignee": "AssignedEvent",
667-
"setting_assignee": "AssignedEvent",
668-
"unset_assignee": "UnassignedEvent",
669-
"change_assignee": "UnassignedEvent",
670-
"set_milestone": "MilestonedEvent",
671-
"setting_milestone": "MilestonedEvent",
672-
"unset_milestone": "DemilestonedEvent",
673-
"change_milestone": "DemilestonedEvent",
674-
"update_title": "RenamedTitleEvent",
675-
"change_title": "RenamedTitleEvent",
676-
"merged_pr": "MergedEvent",
677-
"update_description": "ChangeDescriptionEvent",
678-
"change_description": "ChangeDescriptionEvent",
679-
"setting_priority": "SettingPriorityEvent",
680-
"change_priority": "ChangePriorityEvent"
681-
}
682-
if action_type in switch_event_type:
683-
return switch_event_type[action_type]
684-
else:
685-
return ''.join(word.capitalize() for word in action_type.split('_')) + "Event"
686661

687662
def __get_rich_event(self, item):
688663
rich_event = {}
@@ -710,7 +685,7 @@ def __get_rich_event(self, item):
710685
rich_event['content'] = event['content']
711686
rich_event['created_at'] = event['created_at']
712687
rich_event['action_type'] = event['action_type']
713-
rich_event['event_type'] = self.get_event_type(event['action_type'], ) #待定
688+
rich_event['event_type'] = self.get_event_type(event['action_type'], event['content'])
714689
rich_event['repository'] = item["tag"]
715690
rich_event['pull_request'] = False if 'issue' in event else True
716691
rich_event['item_type'] = 'issue' if 'issue' in event else 'pull request'
@@ -794,6 +769,7 @@ def __get_rich_stargazer(self, item):
794769
rich_stargazer['user_email'] = user.get('email', None)
795770
rich_stargazer["user_domain"] = self.get_email_domain(user['email']) if user.get('email', None) else None
796771
rich_stargazer['user_company'] = user.get('company', None)
772+
rich_stargazer['user_location'] = user.get('location', None)
797773
rich_stargazer["user_remark"] = user.get("remark", None)
798774
rich_stargazer["user_type"] = user["type"]
799775

@@ -806,6 +782,7 @@ def __get_rich_stargazer(self, item):
806782
rich_stargazer['user_email'] = None
807783
rich_stargazer["user_domain"] = None
808784
rich_stargazer['user_company'] = None
785+
rich_stargazer['user_location'] = None
809786
rich_stargazer["user_remark"] = None
810787
rich_stargazer["user_type"] = None
811788

@@ -838,6 +815,7 @@ def __get_rich_fork(self, item):
838815
rich_fork['user_email'] = user.get('email', None)
839816
rich_fork["user_domain"] = self.get_email_domain(user['email']) if user.get('email', None) else None
840817
rich_fork['user_company'] = user.get('company', None)
818+
rich_fork['user_location'] = user.get('location', None)
841819
rich_fork["user_remark"] = user.get("remark", None)
842820
rich_fork["user_type"] = user["type"]
843821

@@ -850,6 +828,7 @@ def __get_rich_fork(self, item):
850828
rich_fork['user_email'] = None
851829
rich_fork['user_domain'] = None
852830
rich_fork['user_company'] = None
831+
rich_fork['user_location'] = None
853832
rich_fork["user_remark"] = None
854833
rich_fork["user_type"] = None
855834

@@ -882,6 +861,7 @@ def __get_rich_watch(self, item):
882861
rich_watch['user_email'] = user.get('email', None)
883862
rich_watch["user_domain"] = self.get_email_domain(user['email']) if user.get('email', None) else None
884863
rich_watch['user_company'] = user.get('company', None)
864+
rich_watch['user_location'] = user.get('location', None)
885865
rich_watch["user_remark"] = user.get("remark", None)
886866
rich_watch["user_type"] = user["type"]
887867

@@ -894,6 +874,7 @@ def __get_rich_watch(self, item):
894874
rich_watch['user_email'] = None
895875
rich_watch['user_demain'] = None
896876
rich_watch['user_company'] = None
877+
rich_watch['user_location'] = None
897878
rich_watch["user_remark"] = None
898879
rich_watch["user_type"] = None
899880

0 commit comments

Comments
 (0)