From 45a8ceac3c87ca5545f85589ae3da7d66acd2480 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Jul 09 2019 19:56:33 +0000 Subject: [PATCH 1/4] added duplicate issue comment catching --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index b9b5c77..b341954 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -130,8 +130,14 @@ def _matching_jira_issue_query(client, issue, config, free=False): for result in results_of_query: # If the queried JIRA issue has the id of the upstream issue or the same title if issue.id in result.fields.description or issue.title == result.fields.summary: - # Add it to the final results - final_results.append(result) + # Check the comments to see if has been marked as a duplicate + to_add = True + for comment in client.comments(result): + if 'Marking as duplicate of' in comment.body: + to_add = False + # Add it to the final results if it's not a duplicate + if to_add: + final_results.append(result) # Return the final_results log.debug("Found %i results for query %r", len(final_results), query) From 8c8019c40fd901958f3beecaac5336f8f93c3351 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Jul 10 2019 12:54:45 +0000 Subject: [PATCH 2/4] Adding more checks for matching issues --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index b341954..57473df 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -128,17 +128,19 @@ def _matching_jira_issue_query(client, issue, config, free=False): # Loop through the results of the query and make sure the ids final_results = [] for result in results_of_query: + import pdb; pdb.set_trace() # If the queried JIRA issue has the id of the upstream issue or the same title if issue.id in result.fields.description or issue.title == result.fields.summary: - # Check the comments to see if has been marked as a duplicate - to_add = True - for comment in client.comments(result): - if 'Marking as duplicate of' in comment.body: - to_add = False - # Add it to the final results if it's not a duplicate - if to_add: + if check_comments_for_duplicate(client, result): + final_results.append(result) + elif re.search(r"\[[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\\|,.<>\/?]*" + r"\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\\|,.<>\/?]*\] " + issue.upstream_title, + result.fields.summary): + import pdb; pdb.set_trace() + if check_comments_for_duplicate(client, result): + log.warning(' Matching downstream issue %s to upstream issue %s' % + (result.fields.summary, issue.title)) final_results.append(result) - # Return the final_results log.debug("Found %i results for query %r", len(final_results), query) return final_results @@ -146,6 +148,23 @@ def _matching_jira_issue_query(client, issue, config, free=False): return results_of_query +def check_comments_for_duplicate(client, result): + """ + Checks comment of JIRA issue to see if it has been + marked as a duplicate + Args: + client (jira.client.JIRA): JIRA client) + result (jira.resource.Issue): JIRA issue + Returns: + return (bool): True/False if duplicate comment was found/not found + """ + for comment in client.comments(result): + if re.search(r'Marking as duplicate of (\w*)-(\d*)', comment.body): + return False + return True + + + def _find_comment_in_jira(comment, j_comments): """ Helper function to filter out comments that are matching diff --git a/sync2jira/intermediary.py b/sync2jira/intermediary.py index 66287c7..61bf195 100644 --- a/sync2jira/intermediary.py +++ b/sync2jira/intermediary.py @@ -46,6 +46,10 @@ class Issue(object): def title(self): return u'[%s] %s' % (self.upstream, self._title) + @property + def upstream_title(self): + return self._title + @classmethod def from_pagure(cls, upstream, issue, config): base = config['sync2jira'].get('pagure_url', 'https://pagure.io') From c77f03d646a5deb471702e4c581a05f6f3ee096e Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Jul 10 2019 12:57:27 +0000 Subject: [PATCH 3/4] Fixing issue when ID is interpreted as String --- diff --git a/sync2jira/intermediary.py b/sync2jira/intermediary.py index 61bf195..08d5ff4 100644 --- a/sync2jira/intermediary.py +++ b/sync2jira/intermediary.py @@ -36,7 +36,7 @@ class Issue(object): self.reporter = reporter self.assignee = assignee self.status = status - self.id = id + self.id = str(id) if not downstream: self.downstream = config['sync2jira']['map'][self.source][upstream] else: From 91da1256d43a870f28f3ecb09d91d412d34dad9c Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Jul 10 2019 13:02:04 +0000 Subject: [PATCH 4/4] Added title matching for Pagure --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index 57473df..30e0fe6 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -128,15 +128,15 @@ def _matching_jira_issue_query(client, issue, config, free=False): # Loop through the results of the query and make sure the ids final_results = [] for result in results_of_query: - import pdb; pdb.set_trace() # If the queried JIRA issue has the id of the upstream issue or the same title if issue.id in result.fields.description or issue.title == result.fields.summary: if check_comments_for_duplicate(client, result): final_results.append(result) - elif re.search(r"\[[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\\|,.<>\/?]*" - r"\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\\|,.<>\/?]*\] " + issue.upstream_title, + # If that's not the case, check if they have the same upstream title + # Upstream username/repo can change if repos are merged + elif re.search(r"\[[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\\|,.<>\/?]*\] " + + issue.upstream_title, result.fields.summary): - import pdb; pdb.set_trace() if check_comments_for_duplicate(client, result): log.warning(' Matching downstream issue %s to upstream issue %s' % (result.fields.summary, issue.title))