Commit e6d3d8e6 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont 🤔
Browse files

Overhaul the maintaineremail plugin

parent 89207b3a
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# This file is part of debexpo - http://debexpo.workaround.org # This file is part of debexpo - http://debexpo.workaround.org
# #
# Copyright © 2008 Jonny Lamb <jonny@debian.org> # Copyright © 2008 Jonny Lamb <jonny@debian.org>
# Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
# #
# Permission is hereby granted, free of charge, to any person # Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation # obtaining a copy of this software and associated documentation
...@@ -32,9 +33,13 @@ Holds the maintaineremail plugin. ...@@ -32,9 +33,13 @@ Holds the maintaineremail plugin.
""" """
__author__ = 'Jonny Lamb' __author__ = 'Jonny Lamb'
__copyright__ = 'Copyright © 2008 Jonny Lamb' __copyright__ = ', '.join([
'Copyright © 2008 Jonny Lamb',
'Copyright © 2012 Nicolas Dandrimont',
])
__license__ = 'MIT' __license__ = 'MIT'
import email.utils
import logging import logging
import re import re
...@@ -60,36 +65,36 @@ class MaintainerEmailPlugin(BasePlugin): ...@@ -60,36 +65,36 @@ class MaintainerEmailPlugin(BasePlugin):
user = meta.session.query(User).get(self.user_id) user = meta.session.query(User).get(self.user_id)
if user is not None: if user is not None:
regex = re.compile(r'^(.*) ?(<.+@.+>)$') maintainer_name, maintainer_email = email.utils.parseaddr(self.changes['Maintainer'])
maintainer_email = regex.match(self.changes['Maintainer']).group(2)[1:-1]
uploader_emails = [] uploader_emails = []
dsc = deb822.Dsc(file(self.changes.get_dsc())) dsc = deb822.Dsc(file(self.changes.get_dsc()))
if 'Uploaders' in dsc: if 'Uploaders' in dsc:
for uploader in dsc['Uploaders'].split(','): for uploader_name, uploader_email in email.utils.getaddresses([dsc['Uploaders']]):
match = regex.match(uploader) uploader_emails.append(uploader_email)
if match:
uploader_emails.append(match.group(2)[1:-1])
severity = constants.PLUGIN_SEVERITY_INFO
if user.email == maintainer_email: if user.email == maintainer_email:
log.debug('Maintainer email is the same as the uploader') log.debug('"Maintainer" email is the same as the uploader')
self.passed('maintainer-is-uploader', None, constants.PLUGIN_SEVERITY_INFO) outcome = '"Maintainer" email is the same as the uploader'
elif user.email in uploader_emails: elif user.email in uploader_emails:
log.debug('The uploader is in the package\'s "Uploaders" field') log.debug('The uploader is in the package\'s "Uploaders" field')
self.passed('uploader-in-uploaders', None, constants.PLUGIN_SEVERITY_INFO) outcome = 'The uploader is in the package\'s "Uploaders" field'
else: else:
log.warning('%s != %s' % (user.email, maintainer_email)) log.warning('%s != %s' % (user.email, maintainer_email))
self.failed('maintainer-is-not-uploader', '%s != %s' % (user.email, maintainer_email), outcome = 'The uploader is not in the package\'s "Maintainer" or "Uploaders" fields'
constants.PLUGIN_SEVERITY_WARNING) severity = constants.PLUGIN_SEVERITY_WARNING
data = {
'user-is-maintainer': (severity == constants.PLUGIN_SEVERITY_INFO),
'user-email': user.email,
'maintainer-email': maintainer_email,
'uploader-emails': uploader_emails,
}
self.failed(outcome, data, severity)
else: else:
log.warning('Could not get the uploader\'s user details from the database') log.warning('Could not get the uploader\'s user details from the database')
plugin = MaintainerEmailPlugin plugin = MaintainerEmailPlugin
outcomes = {
'maintainer-is-uploader' : { 'name' : 'The maintainer and uploader emails are the same' },
'uploader-in-uploaders' : { 'name' : 'The uploader is in the package\'s "Uploaders" field' },
'maintainer-is-not-uploader' : { 'name' : 'The maintainer and uploader emails are not the same' },
}
<div class="qa-header">
${o.outcome}
</div>
%if not o.rich_data["user-is-maintainer"]:
<div class="qa-content">
<dl>
<dt>User email</dt>
<dd><a href="mailto:${o.rich_data["user-email"]}">${o.rich_data["user-email"]}</a></dd>
<dt>"Maintainer" email</dt>
<dd><a href="mailto:${o.rich_data["maintainer-email"]}">${o.rich_data["maintainer-email"]}</a></dd>
%if o.rich_data["uploader-emails"]:
<dt>"Uploaders" emails</dt>
<dd>
<ul>
%for email in o.rich_data["uploader-emails"]:
<li><a href="mailto:${email}">${email}</a></li>
%endfor
</ul>
</dd>
%endif
</dl>
</div>
%endif
${o.outcome}
%if not o.rich_data["user-is-maintainer"]:
- User email: ${o.rich_data["user-email"]}
- "Maintainer" email: ${o.rich_data["maintainer-email"]}
%if o.rich_data["uploader-emails"]:
- "Uploaders" emails:
%for email in o.rich_data["uploader-emails"]:
- ${email}
%endfor
%endif
%endif
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