~xnox/ubuntu-archive-tools/sru-report-autopkgtest-vomit

1125.2.1 by Łukasz 'sil2100' Zemczak
Extract the process_bug() function to a common module so that both sru-review and sru-accept use the same mechanics for updating SRU bugs after acceptance.
1
#!/usr/bin/python3
2
3
# Copyright (C) 2017  Canonical Ltd.
4
# Author: Brian Murray <brian.murray@canonical.com>
5
# Author: Lukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com>
6
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; version 3 of the License.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
1125.2.3 by Łukasz 'sil2100' Zemczak
Dumb docstring for the sru_workflow.py file.
19
"""Portions of SRU-related code that is re-used by various SRU tools."""
1125.2.1 by Łukasz 'sil2100' Zemczak
Extract the process_bug() function to a common module so that both sru-review and sru-accept use the same mechanics for updating SRU bugs after acceptance.
20
21
import re
22
23
24
def process_bug(launchpad, sourcepkg, version, release, num):
25
    bug_target_re = re.compile(
26
        r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
27
    bug = launchpad.bugs[num]
28
    sourcepkg_match = False
29
    distroseries_match = False
30
    for task in bug.bug_tasks:
31
        # Ugly; we have to do URL-parsing to figure this out.
32
        # /ubuntu/+source/foo can be fed to launchpad.load() to get a
33
        # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
34
        match = bug_target_re.search(task.target.self_link)
35
        if (not match or
36
            (sourcepkg and
37
             match.group('source') != sourcepkg)):
38
            print("Ignoring task %s in bug %s" % (task.web_link, num))
39
            continue
40
        sourcepkg_match = True
1158.1.1 by Łukasz 'sil2100' Zemczak
Propose not excluding tasks that are in 'invalid/released' states when handling sru-review bugs as otherwise the tool can crash trying to re-add a task for an existing suite.
41
        if match.group('suite') == release:
42
            if task.status in ("Invalid", "Won't Fix", "Fix Released"):
43
                print("Matching task was set to %s before accepting the SRU, "
1158.1.2 by Łukasz 'sil2100' Zemczak
Make the warning more verbose.
44
                      "please double-check if this bug is still liable for "
45
                      "fixing.  Switching to Fix Committed." % task.status)
1125.2.1 by Łukasz 'sil2100' Zemczak
Extract the process_bug() function to a common module so that both sru-review and sru-accept use the same mechanics for updating SRU bugs after acceptance.
46
            task.status = "Fix Committed"
47
            task.lp_save()
48
            print("Success: task %s in bug %s" % (task.web_link, num))
49
            distroseries_match = True
50
51
    if sourcepkg_match and not distroseries_match:
52
        # add a release task
53
        lp_url = launchpad._root_uri
54
        series_task_url = '%subuntu/%s/+source/%s' % \
55
                          (lp_url, release, sourcepkg)
56
        sourcepkg_target = launchpad.load(series_task_url)
57
        new_task = bug.addTask(target=sourcepkg_target)
58
        new_task.status = "Fix Committed"
59
        new_task.lp_save()
60
        print("LP: #%s added task for %s %s" % (num, sourcepkg, release))
61
    if not sourcepkg_match:
62
        # warn that the bug has no source package tasks
63
        print("LP: #%s has no %s tasks!" % (num, sourcepkg))
64
65
    # XXX: it might be useful if the package signer/sponsor was
66
    #   subscribed to the bug report
67
    bug.subscribe(person=launchpad.people['ubuntu-sru'])
68
    bug.subscribe(person=launchpad.people['sru-verification'])
69
70
    # there may be something else to sponsor so just warn
71
    subscribers = [sub.person for sub in bug.subscriptions]
72
    if launchpad.people['ubuntu-sponsors'] in subscribers:
73
        print('ubuntu-sponsors is still subscribed to LP: #%s. '
74
              'Is there anything left to sponsor?' % num)
75
76
    if not sourcepkg or 'linux' not in sourcepkg:
77
        # this dance is needed due to
78
        # https://bugs.launchpad.net/launchpadlib/+bug/254901
79
        btags = bug.tags
80
        for t in ('verification-failed', 'verification-failed-%s' % release,
81
                  'verification-done', 'verification-done-%s' % release):
82
            if t in btags:
83
                tags = btags
84
                tags.remove(t)
85
                bug.tags = tags
86
87
        if 'verification-needed' not in btags:
88
            btags.append('verification-needed')
89
            bug.tags = btags
90
91
        needed_tag = 'verification-needed-%s' % release
92
        if needed_tag not in btags:
93
            btags.append(needed_tag)
94
            bug.tags = btags
95
96
        bug.lp_save()
97
98
    text = ('Hello %s, or anyone else affected,\n\n' %
99
            re.split(r'[,\s]', bug.owner.display_name)[0])
100
101
    if sourcepkg:
102
        text += 'Accepted %s into ' % sourcepkg
103
    else:
104
        text += 'Accepted into '
105
    if sourcepkg and release:
106
        text += ('%s-proposed. The package will build now and be available at '
107
                 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
108
                 'and then in the -proposed repository.\n\n' % (
109
                     release, sourcepkg, version))
110
    else:
111
        text += ('%s-proposed. The package will build now and be available in '
112
                 'a few hours in the -proposed repository.\n\n' % (
113
                     release))
114
115
    text += ('Please help us by testing this new package.  ')
116
117
    if sourcepkg == 'casper':
118
        text += ('To properly test it you will need to obtain and boot '
119
                 'a daily build of a Live CD for %s.' % (release))
120
    else:
121
        text += ('See https://wiki.ubuntu.com/Testing/EnableProposed for '
122
                 'documentation on how to enable and use -proposed.')
123
124
    text += ('Your feedback will aid us getting this update out to other '
125
             'Ubuntu users.\n\nIf this package fixes the bug for you, '
126
             'please add a comment to this bug, mentioning the version of the '
127
             'package you tested and change the tag from '
128
             'verification-needed-%s to verification-done-%s. '
129
             'If it does not fix the bug for you, please add a comment '
1125.2.2 by Łukasz 'sil2100' Zemczak
Merge trunk, resolve conflicts.
130
             'stating that, and change the tag to verification-failed-%s. '
131
             'In either case, without details of your testing we will not '
132
             'be able to proceed.\n\nFurther information regarding the '
133
             'verification process can be found at '
1125.2.1 by Łukasz 'sil2100' Zemczak
Extract the process_bug() function to a common module so that both sru-review and sru-accept use the same mechanics for updating SRU bugs after acceptance.
134
             'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification .  '
135
             'Thank you in advance!' % (release, release, release))
136
    bug.newMessage(content=text, subject='Please test proposed package')