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

« back to all changes in this revision

Viewing changes to sru_workflow.py

  • Committer: Łukasz 'sil2100' Zemczak
  • Date: 2017-11-20 16:33:04 UTC
  • mto: This revision was merged to the branch mainline in revision 1132.
  • Revision ID: lukasz.zemczak@canonical.com-20171120163304-oekn0evfycwu7kz1
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
 
 
20
import re
 
21
 
 
22
 
 
23
def process_bug(launchpad, sourcepkg, version, release, num):
 
24
    bug_target_re = re.compile(
 
25
        r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
 
26
    bug = launchpad.bugs[num]
 
27
    sourcepkg_match = False
 
28
    distroseries_match = False
 
29
    for task in bug.bug_tasks:
 
30
        # Ugly; we have to do URL-parsing to figure this out.
 
31
        # /ubuntu/+source/foo can be fed to launchpad.load() to get a
 
32
        # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
 
33
        match = bug_target_re.search(task.target.self_link)
 
34
        if (not match or
 
35
            (sourcepkg and
 
36
             match.group('source') != sourcepkg)):
 
37
            print("Ignoring task %s in bug %s" % (task.web_link, num))
 
38
            continue
 
39
        sourcepkg_match = True
 
40
        if (match.group('suite') == release and
 
41
            task.status not in ("Invalid", "Won't Fix",
 
42
                                "Fix Released")):
 
43
            task.status = "Fix Committed"
 
44
            task.lp_save()
 
45
            print("Success: task %s in bug %s" % (task.web_link, num))
 
46
            distroseries_match = True
 
47
 
 
48
    if sourcepkg_match and not distroseries_match:
 
49
        # add a release task
 
50
        lp_url = launchpad._root_uri
 
51
        series_task_url = '%subuntu/%s/+source/%s' % \
 
52
                          (lp_url, release, sourcepkg)
 
53
        sourcepkg_target = launchpad.load(series_task_url)
 
54
        new_task = bug.addTask(target=sourcepkg_target)
 
55
        new_task.status = "Fix Committed"
 
56
        new_task.lp_save()
 
57
        print("LP: #%s added task for %s %s" % (num, sourcepkg, release))
 
58
    if not sourcepkg_match:
 
59
        # warn that the bug has no source package tasks
 
60
        print("LP: #%s has no %s tasks!" % (num, sourcepkg))
 
61
 
 
62
    # XXX: it might be useful if the package signer/sponsor was
 
63
    #   subscribed to the bug report
 
64
    bug.subscribe(person=launchpad.people['ubuntu-sru'])
 
65
    bug.subscribe(person=launchpad.people['sru-verification'])
 
66
 
 
67
    # there may be something else to sponsor so just warn
 
68
    subscribers = [sub.person for sub in bug.subscriptions]
 
69
    if launchpad.people['ubuntu-sponsors'] in subscribers:
 
70
        print('ubuntu-sponsors is still subscribed to LP: #%s. '
 
71
              'Is there anything left to sponsor?' % num)
 
72
 
 
73
    if not sourcepkg or 'linux' not in sourcepkg:
 
74
        # this dance is needed due to
 
75
        # https://bugs.launchpad.net/launchpadlib/+bug/254901
 
76
        btags = bug.tags
 
77
        for t in ('verification-failed', 'verification-failed-%s' % release,
 
78
                  'verification-done', 'verification-done-%s' % release):
 
79
            if t in btags:
 
80
                tags = btags
 
81
                tags.remove(t)
 
82
                bug.tags = tags
 
83
 
 
84
        if 'verification-needed' not in btags:
 
85
            btags.append('verification-needed')
 
86
            bug.tags = btags
 
87
 
 
88
        needed_tag = 'verification-needed-%s' % release
 
89
        if needed_tag not in btags:
 
90
            btags.append(needed_tag)
 
91
            bug.tags = btags
 
92
 
 
93
        bug.lp_save()
 
94
 
 
95
    text = ('Hello %s, or anyone else affected,\n\n' %
 
96
            re.split(r'[,\s]', bug.owner.display_name)[0])
 
97
 
 
98
    if sourcepkg:
 
99
        text += 'Accepted %s into ' % sourcepkg
 
100
    else:
 
101
        text += 'Accepted into '
 
102
    if sourcepkg and release:
 
103
        text += ('%s-proposed. The package will build now and be available at '
 
104
                 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
 
105
                 'and then in the -proposed repository.\n\n' % (
 
106
                     release, sourcepkg, version))
 
107
    else:
 
108
        text += ('%s-proposed. The package will build now and be available in '
 
109
                 'a few hours in the -proposed repository.\n\n' % (
 
110
                     release))
 
111
 
 
112
    text += ('Please help us by testing this new package.  ')
 
113
 
 
114
    if sourcepkg == 'casper':
 
115
        text += ('To properly test it you will need to obtain and boot '
 
116
                 'a daily build of a Live CD for %s.' % (release))
 
117
    else:
 
118
        text += ('See https://wiki.ubuntu.com/Testing/EnableProposed for '
 
119
                 'documentation on how to enable and use -proposed.')
 
120
 
 
121
    text += ('Your feedback will aid us getting this update out to other '
 
122
             'Ubuntu users.\n\nIf this package fixes the bug for you, '
 
123
             'please add a comment to this bug, mentioning the version of the '
 
124
             'package you tested and change the tag from '
 
125
             'verification-needed-%s to verification-done-%s. '
 
126
             'If it does not fix the bug for you, please add a comment '
 
127
             'stating that, and change the tag to verification-failed-%s. In '
 
128
             'either case, details of your testing will help us make a better '
 
129
             'decision.\n\nFurther information regarding the verification '
 
130
             'process can be found at '
 
131
             'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification .  '
 
132
             'Thank you in advance!' % (release, release, release))
 
133
    bug.newMessage(content=text, subject='Please test proposed package')