#71 Better Issue Matching
Merged 4 years ago by ralph. Opened 4 years ago by sidpremkumar.
sidpremkumar/sync-to-jira better-matching  into  develop

file modified
+28 -3
@@ -130,9 +130,17 @@ 

          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)

- 

+                 if check_comments_for_duplicate(client, result):

+                     final_results.append(result)

+             # 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):

+                 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
@@ -140,6 +148,23 @@ 

          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):
ralph commented 4 years ago

Do humans type this Marking as duplicate string into jira? Can you rely on it being in this specific format?

+             return False

+     return True

+ 

+ 

+ 

  def _find_comment_in_jira(comment, j_comments):

      """

      Helper function to filter out comments that are matching

file modified
+5 -1
@@ -36,7 +36,7 @@ 

          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:
@@ -46,6 +46,10 @@ 

      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')

Sometimes when a Repo is merged, issue links no longer correspond to the same title (i.e. if '[fake_user/fake_project] fake_issue' gets merged into a RedHat git repo, it becomes '[red-hat/fake_project] fake_issue' but the issue link remains the same. This causes an issue when we are trying to match upstream/downstream issues.

The proposed fix is to first check for a direct match or an ID match as before. But if that does not return anything check to see if the upstream titles match directly (i.e. even if [red-hat/fake_project] don't match, check if fake_issue is in the downstream title. If it is, spit out a warning and assume they are supposed to be matched.

Other fixes in this PR:
Check comments of an issue if it has been marked as a duplicate of another issue (skip if this is the case)
Assert issue ID should be a string

Do humans type this Marking as duplicate string into jira? Can you rely on it being in this specific format?

Do humans type this Marking as duplicate string into jira? Can you rely on it being in this specific format?

That string is made internally within sync2jira. See downstream.py:_close_as_duplicate

Pull-Request has been merged by ralph

4 years ago