Commit 3992e34c authored by Nicolas Dandrimont's avatar Nicolas Dandrimont 🤔
Browse files

Overhaul the closed bugs plugin

parent b27c6e99
...@@ -36,6 +36,7 @@ __author__ = 'Arno Töll' ...@@ -36,6 +36,7 @@ __author__ = 'Arno Töll'
__copyright__ = 'Copyright © 2011 Arno Töll' __copyright__ = 'Copyright © 2011 Arno Töll'
__license__ = 'MIT' __license__ = 'MIT'
from collections import defaultdict
import logging import logging
from debexpo.lib import constants from debexpo.lib import constants
...@@ -53,64 +54,73 @@ class ClosedBugsPlugin(BasePlugin): ...@@ -53,64 +54,73 @@ class ClosedBugsPlugin(BasePlugin):
Check to make sure the bugs closed belong to the package. Check to make sure the bugs closed belong to the package.
""" """
try: if 'Closes' not in self.changes:
self.changes['Closes']
except KeyError:
log.debug('Package does not close any bugs') log.debug('Package does not close any bugs')
return return
log.debug('Checking whether the bugs closed in the package belong to the package') log.debug('Checking whether the bugs closed in the package belong to the package')
bugs = [int(x) for x in self.changes['Closes'].split(' ')] bugs = [int(x) for x in self.changes['Closes'].split()]
binary_packages = self.changes['Description'].split('\n') binary_packages = self.changes['Description'].split('\n')
binary_packages = [t.strip() for t in binary_packages] binary_packages = [t.strip() for t in binary_packages]
if (len(bugs)): if bugs:
log.debug('Creating SOAP proxy to bugs.debian.org') log.debug('Creating SOAP proxy to bugs.debian.org')
try: try:
server = SOAPpy.SOAPProxy( ClosedBugsPlugin.URL, ClosedBugsPlugin.NS, simplify_objects = 1 ) server = SOAPpy.SOAPProxy(self.URL, self.NS, simplify_objects = 1)
bugs_retrieved = server.get_status( *bugs ) bugs_retrieved = server.get_status( *bugs )
bugs_retrieved = bugs_retrieved['item'] if 'item' in bugs_retrieved:
bugs_retrieved = bugs_retrieved['item']
else:
bugs_retrieved = []
# Force argument to be a list, SOAPpy returns a dictionary instead of a dictionary list # Force argument to be a list, SOAPpy returns a dictionary instead of a dictionary list
# if only one bug was found # if only one bug was found
if ( not isinstance( bugs_retrieved, list ) ): if not isinstance(bugs_retrieved, list):
bugs_retrieved = ( bugs_retrieved, ) bugs_retrieved = [bugs_retrieved]
except Exception as e: except Exception as e:
log.critical('An error occurred when creating the SOAP proxy at "%s" (ns: "%s"): %s' log.critical('An error occurred when creating the SOAP proxy at "%s" (ns: "%s"): %s'
% (ClosedBugsPlugin.URL, ClosedBugsPlugin.NS, e)) % (self.URL, self.NS, e))
self.failed('invalid-bug-specified', "%s: One or more bugs closed in this package do not exist" % (self.changes['Closes']), constants.PLUGIN_SEVERITY_ERROR)
return return
data = {
'buglist': bugs,
'raw': {},
'errors': [],
'bugs': defaultdict(list),
}
# Index bugs retrieved # Index bugs retrieved
bugs_bts = {}
for bug in bugs_retrieved: for bug in bugs_retrieved:
if 'key' in bug and 'value' in bug: if 'key' in bug and 'value' in bug:
bugs_bts[int(bug['key'])] = bug['value'] data["raw"][int(bug['key'])] = bug['value']
else: else:
continue continue
severity = constants.PLUGIN_SEVERITY_INFO
for bug in bugs: for bug in bugs:
if not bug in bugs_bts: if not bug in data['raw']:
log.error('Bug #%s does not exist' % bug) data["errors"].append('Bug #%s does not exist' % bug)
self.failed('bug-does-not-exist', bug, constants.PLUGIN_SEVERITY_ERROR) severity = max(severity, constants.PLUGIN_SEVERITY_ERROR)
name = bugs_bts[bug]['package']
if self._package_in_descriptions(name, binary_packages):
message = ('Closes bug #%d: "%s" in package %s' %
(bugs_bts[bug]['bug_num'], bugs_bts[bug]['subject'], bugs_bts[bug]['package']))
log.debug(message)
self.passed('bug-in-package', message, constants.PLUGIN_SEVERITY_INFO)
elif name == 'wnpp':
message = ('Closes WNPP bug #%d: "%s"' % (bugs_bts[bug]['bug_num'], bugs_bts[bug]['subject']))
log.debug(message)
self.passed('bug-in-package', message, constants.PLUGIN_SEVERITY_INFO)
else:
log.error('Bug #%s does not belong to this package' % bug)
self.failed('bug-not-in-package', bug, constants.PLUGIN_SEVERITY_ERROR)
name = data["raw"][bug]['package']
if self._package_in_descriptions(name, binary_packages) or name == "wnpp":
data["bugs"][name].append((bug, data["raw"][bug]["subject"], data["raw"][bug]["severity"]))
else:
data["errors"].append('Bug #%s does not belong to this package' % bug)
severity = max(severity, constants.PLUGIN_SEVERITY_ERROR)
if severity != constants.PLUGIN_SEVERITY_INFO:
outcome = "Package closes bugs in a wrong way"
elif "wnpp" in data["bugs"] and len(data["bugs"]) == 1:
outcome = "Package closes a WNPP bug"
else:
outcome = "Package closes bug%s" % ("s" if len(bugs) > 1 else "")
self.failed(outcome, data, severity)
else: else:
log.debug('Package does not close any bugs') log.debug('Package does not close any bugs')
...@@ -133,9 +143,3 @@ class ClosedBugsPlugin(BasePlugin): ...@@ -133,9 +143,3 @@ class ClosedBugsPlugin(BasePlugin):
return False return False
plugin = ClosedBugsPlugin plugin = ClosedBugsPlugin
outcomes = {
'invalid-bug-specified': {'name': 'One or more bugs closed in this package do not exist'},
'bug-not-in-package' : { 'name' : 'A bug closed in this package doesn\'t belong to this package' },
'bug-in-package' : { 'name' : 'A bug closed in this package belongs to this package' },
}
...@@ -968,6 +968,18 @@ ul.qa { ...@@ -968,6 +968,18 @@ ul.qa {
background-color: #C7EA3C; background-color: #C7EA3C;
} }
/* Closed bugs plugin */
.qa .bugs-closed {
margin: 0;
margin-bottom: 1em;
list-style-type: none;
}
.qa .bugs-closed ul {
list-style-type: none;
}
/* Lintian plugin */ /* Lintian plugin */
.qa .lintian-E { .qa .lintian-E {
......
<div class="qa-header">
${o.outcome}
</div>
<div class="qa-content">
%if o.rich_data["errors"]:
Errors:
<ul class="bugs-errors">
% for error in o.rich_data["errors"]:
<li>${error}</li>
% endfor
</ul>
%endif
<ul class="bugs-closed">
%for package in o.rich_data["bugs"]:
<li>
<a href="http://bugs.debian.org/${package}">${package}</a>:
<ul>
%for bugnum, title, severity in o.rich_data["bugs"][package]:
<li>
<a href="http://bugs.debian.org/${bugnum}">#${bugnum}</a> (${severity}): ${title}
</li>
%endfor
</ul>
</li>
%endfor
</ul>
</div>
${o.outcome}
%if o.rich_data["errors"]:
Errors:
% for error in o.rich_data["errors"]:
- ${error}
% endfor
%endif
%for package in o.rich_data["bugs"]:
Bugs closed in ${package}:
%for bugnum, title, severity in o.rich_data["bugs"][package]:
- #${bugnum} (${severity}): ${title}
%endfor
%endfor
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment