maintaineremail.py 4.77 KB
Newer Older
Jonny Lamb's avatar
Jonny Lamb committed
1
2
3
4
# -*- coding: utf-8 -*-
#
#   maintaineremail.py — maintaineremail plugin
#
Arno Töll's avatar
Arno Töll committed
5
#   This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
Jonny Lamb's avatar
Jonny Lamb committed
6
#
Jonny Lamb's avatar
Jonny Lamb committed
7
#   Copyright © 2008 Jonny Lamb <jonny@debian.org>
8
#   Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
9
#   Copyright © 2012 Clément Schreiner <clement@mux.me>
Jonny Lamb's avatar
Jonny Lamb committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
#   Permission is hereby granted, free of charge, to any person
#   obtaining a copy of this software and associated documentation
#   files (the "Software"), to deal in the Software without
#   restriction, including without limitation the rights to use,
#   copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following
#   conditions:
#
#   The above copyright notice and this permission notice shall be
#   included in all copies or substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#   OTHER DEALINGS IN THE SOFTWARE.

"""
Holds the maintaineremail plugin.
"""

__author__ = 'Jonny Lamb'
37
38
39
__copyright__ = ', '.join([
        'Copyright © 2008 Jonny Lamb',
        'Copyright © 2012 Nicolas Dandrimont',
40
        'Copyright © 2012 Clément Schreiner',
41
        ])
Jonny Lamb's avatar
Jonny Lamb committed
42
43
__license__ = 'MIT'

44
import email.utils
Jonny Lamb's avatar
Jonny Lamb committed
45
46
47
import logging
import re

48
49
from debian import deb822

Jonny Lamb's avatar
Jonny Lamb committed
50
from debexpo.lib import constants
51
from debexpo.plugins.api import *
Jonny Lamb's avatar
Jonny Lamb committed
52
53
54
55
from debexpo.model.users import User

log = logging.getLogger(__name__)

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@test_result
class MaintainerEmailTest(PluginResult):
    """ Result of the maintaineremail QA test. """

    user_is_maintainer = bool_field('user_is_maintainer')
    user_in_uploaders = bool_field('user_in_uploaders')

    def __str__(self):
        if self.user_is_maintainer:
            return '"Maintainer" email is the same as the uploader'
        elif self.user_in_uploaders:
            return 'The uploader is in the package\'s "Uploaders" field'
        else:
            return 'The uploader is not in the package\'s "Maintainer"' \
                ' or "Uploaders" fields'

class UploaderEmail(PluginResult):
    """ Email address of one of the package's co-maintainers """
Jonny Lamb's avatar
Jonny Lamb committed
74

75
76
77
78
79
80
    def __str__(self):
        return self['email']

class MaintainerEmailPlugin(QAPlugin):

    @importercmd
Jonny Lamb's avatar
Jonny Lamb committed
81
82
83
84
    def test_maintainer_email(self):
        """
        Tests whether the maintainer email is the same as the uploader email.
        """
85
86
        user_id = self.kw.get('user_id', None)
        if user_id is None:
87
            log.warning('Could not get the uploader\'s user details from the database')
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
            return

        log.debug('Checking whether the maintainer email is the same as the uploader email')

        user = self.session.query(User).get(user_id)

        log.debug('Checking whether the maintainer email is the same as'
                  ' the uploader email')

        user = self.package_version.package.user

        if user is not None:
            maintainer_name, maintainer_email = email.utils.parseaddr(
                self.changes['Maintainer'])
            uploader_emails = []

            dsc = deb822.Dsc(file(self.changes.get_dsc()))

            if 'Uploaders' in dsc:
                for uploader_name, uploader_email in email.utils.getaddresses(
                        [dsc['Uploaders']]):
                    uploader_emails.append(uploader_email)

            severity = constants.PLUGIN_SEVERITY_INFO
            user_is_maintainer = True

            if user.email == maintainer_email:
                log.debug('"Maintainer" email is the same as the uploader')
            elif user.email in uploader_emails:
                user_in_uploaders = True
                log.debug('The uploader is in the package\'s "Uploaders" field')
            else:
                log.warning('%s != %s' % (user.email, maintainer_email))
                severity = constants.PLUGIN_SEVERITY_WARNING
                user_is_maintainer = False

            result = self.new_test_result(severity=severity,
                                          user_is_maintainer=user_is_maintainer,
                                          user_email=user.email,
                                          maintainer_email=maintainer_email)

            for uploader in uploaders_emails:
                self.new_result(UploaderEmail, email='uploader')

Jonny Lamb's avatar
Jonny Lamb committed
132
133

plugin = MaintainerEmailPlugin
134
135
136
137
models = [
    MaintainerEmailTest,
    UploaderEmail,
    ]