Add a JIRA filter link to generated tables 34/97634/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 26 Sep 2021 06:19:41 +0000 (08:19 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 26 Sep 2021 06:33:58 +0000 (08:33 +0200)
Our tables are a mirror of what JIRA exposes through filters and while
this view cannot be directly embedded, provide a link for readers to
jump to JIRA and see the current view of the filter.

Also clean up internal structure to reduce code duplication.

Change-Id: I808dfae3bdbcaa2d65d58079e6189611a96801da
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
docs/ext/odl-jira.py

index 7ca7ed6d6e73cee5d6c6e024d2b39a7a193ca7cd..d2d021ecdd41c2cff521b4669edf78bb00433b52 100644 (file)
@@ -13,12 +13,36 @@ Embeds a simple table with issues.
 from docutils import nodes
 from docutils.parsers.rst import directives, Directive
 from jira import JIRA
+from urllib.parse import quote
 import re
 import sphinx
 
 __copyright__ = "Copyright(c) 2021 PANTHEON.tech, s.r.o."
 __license__ = "Eclipse Public License v1.0"
 
+def jira_prj_versions(project, version_range):
+    jira = JIRA(server="https://jira.opendaylight.org")
+    prj = jira.project(project)
+    (from_ver, to_ver) = version_range.split('-', 1)
+
+    versions = set()
+    for ver in jira.project_versions(prj):
+        if ver.name >= from_ver and ver.name <= to_ver:
+            versions.add(ver.name)
+    versions = list(versions)
+    versions.sort()
+    versions = ", ".join(versions)
+
+    return (jira, prj, from_ver, to_ver, versions)
+
+def format_versions(versions):
+    result = set()
+    for version in versions:
+        result.add(version.name)
+    result = list(result)
+    result.sort()
+    return ", ".join(result)
+
 class JiraFixedIssuesDirective(Directive):
     """
     JIRA Fixed Issues directive
@@ -33,19 +57,14 @@ class JiraFixedIssuesDirective(Directive):
     }
 
     def run(self):
-        jira = JIRA(server="https://jira.opendaylight.org")
-        prj = jira.project(self.options.get('project'))
-        (from_ver, to_ver) = self.options.get('versions').split('-', 1)
+        (jira, prj, from_ver, to_ver, versions) = jira_prj_versions(self.options.get('project'), self.options.get('versions'))
 
-        versions = set()
-        for ver in jira.project_versions(prj):
-            if ver.name >= from_ver and ver.name <= to_ver:
-                versions.add(ver.name)
-        versions = ", ".join(versions)
+        query = 'project = %s AND resolution is not EMPTY AND fixVersion in (%s) ORDER BY type ASC' % (prj, versions)
+        issues = jira.search_issues(query)
 
         # FIXME: this is not quite nice: can we emit the table markup directly
         table = [
-            '.. list-table:: Issues resolved in versions %s through %s' % (from_ver, to_ver),
+            '.. list-table:: Issues resolved in versions %s through %s (`JIRA <https://jira.opendaylight.org/issues/?jql=%s>`__)' % (from_ver, to_ver, quote(query)),
             '   :class: datatable',
             '   :header-rows: 1',
             '   :widths: auto',
@@ -57,22 +76,14 @@ class JiraFixedIssuesDirective(Directive):
             '     - Fix Version(s)',
         ]
 
-        issues = jira.search_issues('project = %s AND resolution is not EMPTY AND fixVersion in (%s) ORDER BY type ASC' % (prj, versions))
         for issue in issues:
-            # Groom fixVersions
-            fixVersions = set()
-            for version in issue.fields.fixVersions:
-                fixVersions.add(version.name)
-            fixVersions = list(fixVersions)
-            fixVersions.sort()
-
             table.append('   * - .. image:: %s' % issue.fields.issuetype.iconUrl)
             table.append('          :align: center')
             table.append('          :alt: %s' % issue.fields.issuetype.name)
             table.append('     - `%s <https://jira.opendaylight.org/browse/%s>`_' % (issue.key, issue.key))
             table.append('     - %s' % issue.fields.summary)
             table.append('     - %s' % issue.fields.resolution)
-            table.append('     - %s' % ", ".join(fixVersions))
+            table.append('     - %s' % format_versions(issue.fields.fixVersions))
 
         table.append('')
 
@@ -98,19 +109,14 @@ class JiraKnownIssuesDirective(Directive):
     }
 
     def run(self):
-        jira = JIRA(server="https://jira.opendaylight.org")
-        prj = jira.project(self.options.get('project'))
-        (from_ver, to_ver) = self.options.get('versions').split('-', 1)
+        (jira, prj, from_ver, to_ver, versions) = jira_prj_versions(self.options.get('project'), self.options.get('versions'))
 
-        versions = set()
-        for ver in jira.project_versions(prj):
-            if ver.name >= from_ver and ver.name <= to_ver:
-                versions.add(ver.name)
-        versions = ", ".join(versions)
+        query = 'project = %s AND affectedVersion in (%s) AND fixVersion NOT in (%s) ORDER BY type ASC' % (prj, versions, versions)
+        issues = jira.search_issues(query)
 
         # FIXME: this is not quite nice: can we emit the table markup directly
         table = [
-            '.. list-table:: Issues affecting versions %s through %s' % (from_ver, to_ver),
+            '.. list-table:: Issues affecting versions %s through %s (`JIRA <https://jira.opendaylight.org/issues/?jql=%s>`__)' % (from_ver, to_ver, quote(query)),
             '   :class: datatable',
             '   :header-rows: 1',
             '   :widths: auto',
@@ -123,30 +129,17 @@ class JiraKnownIssuesDirective(Directive):
             '     - Fix Version(s)',
         ]
 
-        issues = jira.search_issues('project = %s AND affectedVersion in (%s) AND fixVersion NOT in (%s) ORDER BY type ASC' % (prj, versions, versions))
         for issue in issues:
-            # Groom fixVersions
-            fixVersions = set()
-            for version in issue.fields.fixVersions:
-                fixVersions.add(version.name)
-            fixVersions = list(fixVersions)
-            fixVersions.sort()
-
-            # Groom affectedVersions
-            affectedVersions = set()
-            for version in issue.fields.versions:
-                affectedVersions.add(version.name)
-            affectedVersions = list(affectedVersions)
-            affectedVersions.sort()
-
+            fixVersions = format_versions(issue.fields.fixVersions)
+            affectvedVersions = format_versions(issue.fields.versions)
             table.append('   * - .. image:: %s' % issue.fields.issuetype.iconUrl)
             table.append('          :align: center')
             table.append('          :alt: %s' % issue.fields.issuetype.name)
             table.append('     - `%s <https://jira.opendaylight.org/browse/%s>`_' % (issue.key, issue.key))
             table.append('     - %s' % issue.fields.summary)
             table.append('     - %s' % issue.fields.status)
-            table.append('     - %s' % ", ".join(affectedVersions))
-            table.append('     - %s' % ", ".join(fixVersions))
+            table.append('     - %s' % fixVersions)
+            table.append('     - %s' % affectvedVersions)
 
         table.append('')