From 9bada17eb805c5bd9e9f8d282f1bcf66e4682a4d Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 2 Jun 2023 15:54:06 +0200 Subject: [PATCH] Ref #548, #407: filter see_also for configured project --- jbi/models.py | 6 ++++-- jbi/runner.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jbi/models.py b/jbi/models.py index 1cbd3077..9b33e908 100644 --- a/jbi/models.py +++ b/jbi/models.py @@ -239,7 +239,7 @@ def issue_type(self) -> str: type_map: dict = {"enhancement": "Task", "task": "Task", "defect": "Bug"} return type_map.get(self.type, "Task") - def extract_from_see_also(self): + def extract_from_see_also(self, project_key): """Extract Jira Issue Key from see_also if jira url present""" if not self.see_also or len(self.see_also) == 0: return None @@ -262,8 +262,10 @@ def extract_from_see_also(self): continue if any(part in JIRA_HOSTNAMES for part in host_parts): + # URL ending with / parsed_jira_key = parsed_url.path.rstrip("/").split("/")[-1] - if parsed_jira_key: # URL ending with / + # eg. filter for specified project SNT-1234 + if parsed_jira_key and project_key in parsed_jira_key: return parsed_jira_key return None diff --git a/jbi/runner.py b/jbi/runner.py index f4d4ca5a..26df7206 100644 --- a/jbi/runner.py +++ b/jbi/runner.py @@ -73,7 +73,9 @@ def execute_action( f"private bugs are not valid for action {action.whiteboard_tag!r}" ) - linked_issue_key: Optional[str] = bug.extract_from_see_also() + linked_issue_key: Optional[str] = bug.extract_from_see_also( + project_key=action.jira_project_key + ) action_context = ActionContext( rid=request.rid,