maintaineremail.py 3.61 KB
Newer Older
1
#   maintaineremail.py - maintaineremail plugin
Jonny Lamb's avatar
Jonny Lamb committed
2
#
Baptiste Beauplat's avatar
Baptiste Beauplat committed
3
4
#   This file is part of debexpo -
#   https://salsa.debian.org/mentors.debian.net-team/debexpo
Jonny Lamb's avatar
Jonny Lamb committed
5
#
Jonny Lamb's avatar
Jonny Lamb committed
6
#   Copyright © 2008 Jonny Lamb <jonny@debian.org>
7
#   Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
8
#   Copyright © 2020 Baptiste Beauplat <lyknode@cilg.org>
Jonny Lamb's avatar
Jonny Lamb committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
#   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.

31
import email.utils
32
import re
Jonny Lamb's avatar
Jonny Lamb committed
33

34
from debexpo.plugins.models import BasePlugin, PluginSeverity
Jonny Lamb's avatar
Jonny Lamb committed
35
36


37
38
39
40
class PluginMaintainerEmail(BasePlugin):
    @property
    def name(self):
        return 'maintainer-email'
Jonny Lamb's avatar
Jonny Lamb committed
41

42
    def run(self, changes, source):
Jonny Lamb's avatar
Jonny Lamb committed
43
44
45
        """
        Tests whether the maintainer email is the same as the uploader email.
        """
46
47
48
        if not changes.maintainer:
            self.failed('No maintainer address found')

49
50
        uploader_emails = []
        maintainer_emails = email.utils.getaddresses([changes.maintainer])
51
        maintainer_email = maintainer_emails[0][1]
52
53
54
55
56
57
58
59
60
61
62
63

        if changes.dsc.uploaders:
            for _, uploader_email in \
                    email.utils.getaddresses([changes.dsc.uploaders]):
                uploader_emails.append(uploader_email)

        severity = PluginSeverity.info
        if changes.uploader.email == maintainer_email:
            outcome = '"Maintainer" email is the same as the uploader'
        elif changes.uploader.email in uploader_emails:
            outcome = 'The uploader is in the package\'s "Uploaders" ' \
                      'field'
64
        else:
65
66
67
68
69
70
71
72
73
            outcome = 'The uploader is not in the package\'s ' \
                      '"Maintainer" or "Uploaders" fields'
            severity = PluginSeverity.warning

        team_upload = re.compile(r'\b[Tt]eam\b\s*\b[Uu]pload*\b')
        if team_upload.search(changes.changes) is not None:
            outcome += ' (Team upload)'
            severity = PluginSeverity.info

74
75
76
77
78
79
80
81
82
        qa_upload = re.compile(r'\b[Qq][Aa]\b\s*\b[Uu]pload*\b')
        if qa_upload.search(changes.changes) is not None:
            if maintainer_email == 'packages@qa.debian.org':
                outcome = 'Maintainer is Debian QA Team (QA Upload)'
                severity = PluginSeverity.info
            else:
                outcome = 'Maintainer is not Debian QA Team (QA Upload)'
                severity = PluginSeverity.error

83
84
85
86
87
88
89
90
        data = {
            'user_is_maintainer': (severity == PluginSeverity.info),
            'user_email': changes.uploader.email,
            'maintainer_email': maintainer_email,
            'uploader_emails': uploader_emails,
            }

        self.add_result('maintainer-email', outcome, data, severity)