1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 # This program and the accompanying materials are made available under the
5 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 # and is available at http://www.eclipse.org/legal/epl-v10.html
9 Embeds a simple table with issues.
13 from docutils import nodes
14 from docutils.parsers.rst import directives, Directive
16 from urllib.parse import quote
20 __copyright__ = "Copyright(c) 2021 PANTHEON.tech, s.r.o."
21 __license__ = "Eclipse Public License v1.0"
23 def jira_prj_versions(project, version_range):
24 jira = JIRA(server="https://jira.opendaylight.org")
25 prj = jira.project(project)
26 (from_ver, to_ver) = version_range.split('-', 1)
29 for ver in jira.project_versions(prj):
30 if ver.name >= from_ver and ver.name <= to_ver:
31 versions.add(ver.name)
32 versions = list(versions)
34 versions = ", ".join(versions)
36 return (jira, prj, from_ver, to_ver, versions)
38 def format_versions(versions):
40 for version in versions:
41 result.add(version.name)
44 return ", ".join(result)
46 class JiraFixedIssuesDirective(Directive):
48 JIRA Fixed Issues directive
51 required_arguments = 0
52 optional_arguments = 0
55 "project": directives.unchanged_required,
56 "versions": directives.unchanged_required,
60 (jira, prj, from_ver, to_ver, versions) = jira_prj_versions(self.options.get('project'), self.options.get('versions'))
62 query = 'project = %s AND resolution is not EMPTY AND fixVersion in (%s) ORDER BY type ASC' % (prj, versions)
63 issues = jira.search_issues(query)
65 # FIXME: this is not quite nice: can we emit the table markup directly
67 '.. list-table:: Issues resolved in versions %s through %s (`JIRA <https://jira.opendaylight.org/issues/?jql=%s>`__)' % (from_ver, to_ver, quote(query)),
80 table.append(' * - .. image:: %s' % issue.fields.issuetype.iconUrl)
81 table.append(' :align: center')
82 table.append(' :alt: %s' % issue.fields.issuetype.name)
83 table.append(' - `%s <https://jira.opendaylight.org/browse/%s>`_' % (issue.key, issue.key))
84 table.append(' - %s' % issue.fields.summary)
85 table.append(' - %s' % issue.fields.resolution)
86 table.append(' - %s' % format_versions(issue.fields.fixVersions))
90 for idx, line in enumerate(table):
91 self.content.data.insert(idx, line)
92 self.content.items.insert(idx, (None, idx))
94 node = nodes.container()
95 self.state.nested_parse(self.content, self.content_offset, node)
98 class JiraKnownIssuesDirective(Directive):
100 JIRA Known Issues directive
103 required_arguments = 0
104 optional_arguments = 0
107 "project": directives.unchanged_required,
108 "versions": directives.unchanged_required,
112 (jira, prj, from_ver, to_ver, versions) = jira_prj_versions(self.options.get('project'), self.options.get('versions'))
114 query = 'project = %s AND affectedVersion in (%s) AND fixVersion NOT in (%s) ORDER BY type ASC' % (prj, versions, versions)
115 issues = jira.search_issues(query)
117 # FIXME: this is not quite nice: can we emit the table markup directly
119 '.. list-table:: Issues affecting versions %s through %s (`JIRA <https://jira.opendaylight.org/issues/?jql=%s>`__)' % (from_ver, to_ver, quote(query)),
120 ' :class: datatable',
128 ' - Affected Version(s)',
133 fixVersions = format_versions(issue.fields.fixVersions)
134 affectvedVersions = format_versions(issue.fields.versions)
135 table.append(' * - .. image:: %s' % issue.fields.issuetype.iconUrl)
136 table.append(' :align: center')
137 table.append(' :alt: %s' % issue.fields.issuetype.name)
138 table.append(' - `%s <https://jira.opendaylight.org/browse/%s>`_' % (issue.key, issue.key))
139 table.append(' - %s' % issue.fields.summary)
140 table.append(' - %s' % issue.fields.status)
141 table.append(' - %s' % fixVersions)
142 table.append(' - %s' % affectvedVersions)
146 for idx, line in enumerate(table):
147 self.content.data.insert(idx, line)
148 self.content.items.insert(idx, (None, idx))
150 node = nodes.container()
151 self.state.nested_parse(self.content, self.content_offset, node)
156 :type app: sphinx.application.Sphinx
158 app.add_directive('jira_fixed_issues', JiraFixedIssuesDirective)
159 app.add_directive('jira_known_issues', JiraKnownIssuesDirective)
161 # https://datatables.net/ improvements to tables
162 app.add_css_file("https://cdn.datatables.net/1.11.2/css/jquery.dataTables.min.css")
163 app.add_js_file("https://cdn.datatables.net/1.11.2/js/jquery.dataTables.min.js")
164 app.add_js_file(None, **{"body": "$(document).ready( function () { $('table.datatable').DataTable(); } );", "type": "text/javascript", "class": "init"})
168 'parallel_read_safe': True,
169 'parallel_write_safe': True,