Merge lp:~sil2100/ubuntu-archive-tools/common-sru-process-bug into lp:ubuntu-archive-tools

Proposed by Łukasz Zemczak
Status: Merged
Merged at revision: 1132
Proposed branch: lp:~sil2100/ubuntu-archive-tools/common-sru-process-bug
Merge into: lp:ubuntu-archive-tools
Diff against target: 427 lines (+142/-234)
3 files modified
sru-accept (+4/-117)
sru-review (+4/-117)
sru_workflow.py (+134/-0)
To merge this branch: bzr merge lp:~sil2100/ubuntu-archive-tools/common-sru-process-bug
Reviewer Review Type Date Requested Status
Brian Murray Approve
Ubuntu Package Archive Administrators Pending
Review via email: mp+333980@code.launchpad.net

Commit message

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. This also slightly changes the behavior of sru-accept for more than one series.

Description of the change

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. This also slightly changes the behavior of sru-accept for more than one series.

Currently we had two versions of process_bug and the sru-accept one was outdated. Having to maintain two of those was crazy.

Also, with this change, sru-accept when called with multiple targets now just runs process_bug() multiple times (e.g. adding one comment per series) instead of once with multiple series in the bug comment. I changed this because it was easier to do and mimics what happens when you use the sru-review tool.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

This looks good to me thanks for working on it - I think a docstring in sru_workflow.py would be good though. Additionally, a change of mine was recently merged to ubuntu-archive-tools which changed the content of the comment added to bug reports requesting feed back (lines 121-132) so please be sure not to loose that.

Thanks!

review: Approve
1127. By Łukasz Zemczak

Merge trunk, resolve conflicts.

1128. By Łukasz Zemczak

Dumb docstring for the sru_workflow.py file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sru-accept'
2--- sru-accept 2016-06-07 22:36:28 +0000
3+++ sru-accept 2017-12-07 16:28:26 +0000
4@@ -24,126 +24,11 @@
5
6 import launchpadlib.errors
7 from launchpadlib.launchpad import Launchpad
8+from sru_workflow import process_bug
9
10
11 CONSUMER_KEY = "sru-accept"
12
13-bug_target_re = re.compile(
14- r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
15-
16-
17-def join_english_list(words):
18- num_words = len(words)
19- assert num_words > 0
20- if num_words > 2:
21- # Yes, I use the Oxford comma. Deal with it.
22- return '%s, and %s' % (', '.join(words[:-1]), words[-1])
23- elif num_words == 2:
24- return '%s and %s' % (words[0], words[1])
25- else:
26- return words[0]
27-
28-
29-def process_bug(launchpad, options, num):
30- bug = launchpad.bugs[num]
31- sourcepkg_match = False
32- distroseries_match = False
33-
34- for task in bug.bug_tasks:
35- # Ugly; we have to do URL-parsing to figure this out.
36- # /ubuntu/+source/foo can be fed to launchpad.load() to get a
37- # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
38- match = bug_target_re.search(task.target.self_link)
39- if (not match or
40- (options.package and
41- match.group('source') != options.package)):
42- print("Ignoring task %s in bug %s" % (task.web_link, num))
43- continue
44- sourcepkg_match = True
45- if (match.group('suite') in options.targets and
46- task.status not in ("Invalid", "Won't Fix",
47- "Fix Released")):
48- task.status = "Fix Committed"
49- task.lp_save()
50- print("Success: task %s in bug %s" % (task.web_link, num))
51- distroseries_match = True
52-
53- if sourcepkg_match and not distroseries_match:
54- # add a release task
55- lp_url = launchpad._root_uri
56- for series in options.targets:
57- series_task_url = '%subuntu/%s/+source/%s' % \
58- (lp_url, series, options.package)
59- sourcepkg_target = launchpad.load(series_task_url)
60- new_task = bug.addTask(target=sourcepkg_target)
61- new_task.status = "Fix Committed"
62- new_task.lp_save()
63- print("LP: #%s added task for %s %s" %
64- (num, options.package, series))
65- if not sourcepkg_match:
66- # warn that the bug has no source package tasks
67- print("LP: #%s has no %s tasks!" % (num, options.package))
68-
69- bug.subscribe(person=launchpad.people['ubuntu-sru'])
70- bug.subscribe(person=launchpad.people['sru-verification'])
71-
72- if not options.package or 'linux' not in options.package:
73- for t in ('verification-failed', 'verification-done'):
74- if t in bug.tags:
75- # this dance is needed due to
76- # https://bugs.launchpad.net/launchpadlib/+bug/254901
77- tags = bug.tags
78- tags.remove(t)
79- bug.tags = tags
80- bug.lp_save()
81-
82- if 'verification-needed' not in bug.tags:
83- # this dance is needed due to
84- # https://bugs.launchpad.net/launchpadlib/+bug/254901
85- tags = bug.tags
86- tags.append('verification-needed')
87- bug.tags = tags
88- bug.lp_save()
89-
90- text = ('Hello %s, or anyone else affected,\n\n' %
91- re.split(r'[,\s]', bug.owner.display_name)[0])
92-
93- if options.package:
94- text += 'Accepted %s into ' % options.package
95- else:
96- text += 'Accepted into '
97- if options.package and options.version:
98- text += ('%s. The package will build now and be available at '
99- 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
100- 'and then in the -proposed repository.\n\n' % (
101- join_english_list([
102- '%s-proposed' % target
103- for target in options.targets]),
104- options.package, options.version))
105- else:
106- text += ('%s. The package will build now and be available in a few '
107- 'hours in the -proposed repository.\n\n' % (
108- join_english_list([
109- '%s-proposed' % target
110- for target in options.targets])))
111-
112- text += ('Please help us by testing this new package. See '
113- 'https://wiki.ubuntu.com/Testing/EnableProposed for '
114- 'documentation how to enable and use -proposed. Your feedback '
115- 'will aid us getting this update out to other Ubuntu users.\n\n'
116- 'If this package fixes the bug for you, please add a comment to '
117- 'this bug, mentioning the version of the package you tested, and '
118- 'change the tag from verification-needed to verification-done. '
119- 'If it does not fix the bug for you, please add a comment '
120- 'stating that, and change the tag to verification-failed. In '
121- 'either case, details of your testing will help us make a better '
122- 'decision.\n\n'
123- 'Further information regarding the verification process can be '
124- 'found at '
125- 'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . '
126- 'Thank you in advance!')
127- bug.newMessage(content=text, subject='Please test proposed package')
128-
129
130 def append_series(option, opt_str, value, parser):
131 if value.endswith('-proposed'):
132@@ -184,7 +69,9 @@
133 if series.status == "Current Stable Release"][0]]
134 try:
135 for num in args:
136- process_bug(launchpad, options, num)
137+ for series in options.targets:
138+ process_bug(
139+ launchpad, options.package, options.version, series, num)
140 except launchpadlib.errors.HTTPError as err:
141 print("There was an error:")
142 print(err.content)
143
144=== modified file 'sru-review' (properties changed: +x to -x)
145--- sru-review 2017-12-04 21:56:46 +0000
146+++ sru-review 2017-12-07 16:28:26 +0000
147@@ -43,6 +43,7 @@
148 import webbrowser
149
150 from launchpadlib.launchpad import Launchpad
151+from sru_workflow import process_bug
152 from time import sleep
153
154
155@@ -245,122 +246,6 @@
156 subject='Proposed package upload rejected')
157
158
159-def process_bug(launchpad, upload, num):
160- bug_target_re = re.compile(
161- r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
162- bug = launchpad.bugs[num]
163- sourcepkg = upload.package_name
164- release = upload.distroseries.name
165- sourcepkg_match = False
166- distroseries_match = False
167- for task in bug.bug_tasks:
168- # Ugly; we have to do URL-parsing to figure this out.
169- # /ubuntu/+source/foo can be fed to launchpad.load() to get a
170- # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
171- match = bug_target_re.search(task.target.self_link)
172- if (not match or
173- (sourcepkg and
174- match.group('source') != sourcepkg)):
175- print("Ignoring task %s in bug %s" % (task.web_link, num))
176- continue
177- sourcepkg_match = True
178- if (match.group('suite') == release and
179- task.status not in ("Invalid", "Won't Fix",
180- "Fix Released")):
181- task.status = "Fix Committed"
182- task.lp_save()
183- print("Success: task %s in bug %s" % (task.web_link, num))
184- distroseries_match = True
185-
186- if sourcepkg_match and not distroseries_match:
187- # add a release task
188- lp_url = launchpad._root_uri
189- series_task_url = '%subuntu/%s/+source/%s' % \
190- (lp_url, release, sourcepkg)
191- sourcepkg_target = launchpad.load(series_task_url)
192- new_task = bug.addTask(target=sourcepkg_target)
193- new_task.status = "Fix Committed"
194- new_task.lp_save()
195- print("LP: #%s added task for %s %s" % (num, sourcepkg, release))
196- if not sourcepkg_match:
197- # warn that the bug has no source package tasks
198- print("LP: #%s has no %s tasks!" % (num, sourcepkg))
199-
200- # XXX: it might be useful if the package signer/sponsor was
201- # subscribed to the bug report
202- bug.subscribe(person=launchpad.people['ubuntu-sru'])
203- bug.subscribe(person=launchpad.people['sru-verification'])
204-
205- # there may be something else to sponsor so just warn
206- subscribers = [sub.person for sub in bug.subscriptions]
207- if launchpad.people['ubuntu-sponsors'] in subscribers:
208- print('ubuntu-sponsors is still subscribed to LP: #%s. '
209- 'Is there anything left to sponsor?' % num)
210-
211- if not sourcepkg or 'linux' not in sourcepkg:
212- # this dance is needed due to
213- # https://bugs.launchpad.net/launchpadlib/+bug/254901
214- btags = bug.tags
215- for t in ('verification-failed', 'verification-failed-%s' % release,
216- 'verification-done', 'verification-done-%s' % release):
217- if t in btags:
218- tags = btags
219- tags.remove(t)
220- bug.tags = tags
221-
222- if 'verification-needed' not in btags:
223- btags.append('verification-needed')
224- bug.tags = btags
225-
226- needed_tag = 'verification-needed-%s' % release
227- if needed_tag not in btags:
228- btags.append(needed_tag)
229- bug.tags = btags
230-
231- bug.lp_save()
232-
233-
234- text = ('Hello %s, or anyone else affected,\n\n' %
235- re.split(r'[,\s]', bug.owner.display_name)[0])
236-
237- if sourcepkg:
238- text += 'Accepted %s into ' % sourcepkg
239- else:
240- text += 'Accepted into '
241- if sourcepkg and release:
242- text += ('%s-proposed. The package will build now and be available at '
243- 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
244- 'and then in the -proposed repository.\n\n' % (
245- release, sourcepkg, upload.package_version))
246- else:
247- text += ('%s-proposed. The package will build now and be available in '
248- 'a few hours in the -proposed repository.\n\n' % (
249- release))
250-
251- text += ('Please help us by testing this new package. ')
252-
253- if sourcepkg == 'casper':
254- text += ('To properly test it you will need to obtain and boot '
255- 'a daily build of a Live CD for %s.' % (release))
256- else:
257- text += ('See https://wiki.ubuntu.com/Testing/EnableProposed for '
258- 'documentation on how to enable and use -proposed.')
259-
260- text += ('Your feedback will aid us getting this update out to other '
261- 'Ubuntu users.\n\nIf this package fixes the bug for you, '
262- 'please add a comment to this bug, mentioning the version of the '
263- 'package you tested and change the tag from '
264- 'verification-needed-%s to verification-done-%s. '
265- 'If it does not fix the bug for you, please add a comment '
266- 'stating that, and change the tag to verification-failed-%s. '
267- 'In either case, without details of your testing we will not '
268- 'be able to proceed.\n\nFurther information regarding the '
269- 'verification process can be found at '
270- 'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . '
271- 'Thank you in advance!' % (release, release, release))
272- bug.newMessage(content=text, subject='Please test proposed package')
273-
274-
275 if __name__ == '__main__':
276
277 default_release = 'artful'
278@@ -472,7 +357,9 @@
279 print("Accepted")
280 if changes['bugs']:
281 for bug_num in changes['bugs']:
282- process_bug(launchpad, upload, bug_num)
283+ process_bug(
284+ launchpad, upload.package_name, upload.package_version,
285+ upload.distroseries.name, bug_num)
286 else:
287 print("REJECT the package from -proposed? [yN] ", end="")
288 response = sys.stdin.readline()
289
290=== added file 'sru_workflow.py'
291--- sru_workflow.py 1970-01-01 00:00:00 +0000
292+++ sru_workflow.py 2017-12-07 16:28:26 +0000
293@@ -0,0 +1,134 @@
294+#!/usr/bin/python3
295+
296+# Copyright (C) 2017 Canonical Ltd.
297+# Author: Brian Murray <brian.murray@canonical.com>
298+# Author: Lukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com>
299+
300+# This program is free software: you can redistribute it and/or modify
301+# it under the terms of the GNU General Public License as published by
302+# the Free Software Foundation; version 3 of the License.
303+#
304+# This program is distributed in the hope that it will be useful,
305+# but WITHOUT ANY WARRANTY; without even the implied warranty of
306+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
307+# GNU General Public License for more details.
308+#
309+# You should have received a copy of the GNU General Public License
310+# along with this program. If not, see <http://www.gnu.org/licenses/>.
311+
312+"""Portions of SRU-related code that is re-used by various SRU tools."""
313+
314+import re
315+
316+
317+def process_bug(launchpad, sourcepkg, version, release, num):
318+ bug_target_re = re.compile(
319+ r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
320+ bug = launchpad.bugs[num]
321+ sourcepkg_match = False
322+ distroseries_match = False
323+ for task in bug.bug_tasks:
324+ # Ugly; we have to do URL-parsing to figure this out.
325+ # /ubuntu/+source/foo can be fed to launchpad.load() to get a
326+ # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
327+ match = bug_target_re.search(task.target.self_link)
328+ if (not match or
329+ (sourcepkg and
330+ match.group('source') != sourcepkg)):
331+ print("Ignoring task %s in bug %s" % (task.web_link, num))
332+ continue
333+ sourcepkg_match = True
334+ if (match.group('suite') == release and
335+ task.status not in ("Invalid", "Won't Fix",
336+ "Fix Released")):
337+ task.status = "Fix Committed"
338+ task.lp_save()
339+ print("Success: task %s in bug %s" % (task.web_link, num))
340+ distroseries_match = True
341+
342+ if sourcepkg_match and not distroseries_match:
343+ # add a release task
344+ lp_url = launchpad._root_uri
345+ series_task_url = '%subuntu/%s/+source/%s' % \
346+ (lp_url, release, sourcepkg)
347+ sourcepkg_target = launchpad.load(series_task_url)
348+ new_task = bug.addTask(target=sourcepkg_target)
349+ new_task.status = "Fix Committed"
350+ new_task.lp_save()
351+ print("LP: #%s added task for %s %s" % (num, sourcepkg, release))
352+ if not sourcepkg_match:
353+ # warn that the bug has no source package tasks
354+ print("LP: #%s has no %s tasks!" % (num, sourcepkg))
355+
356+ # XXX: it might be useful if the package signer/sponsor was
357+ # subscribed to the bug report
358+ bug.subscribe(person=launchpad.people['ubuntu-sru'])
359+ bug.subscribe(person=launchpad.people['sru-verification'])
360+
361+ # there may be something else to sponsor so just warn
362+ subscribers = [sub.person for sub in bug.subscriptions]
363+ if launchpad.people['ubuntu-sponsors'] in subscribers:
364+ print('ubuntu-sponsors is still subscribed to LP: #%s. '
365+ 'Is there anything left to sponsor?' % num)
366+
367+ if not sourcepkg or 'linux' not in sourcepkg:
368+ # this dance is needed due to
369+ # https://bugs.launchpad.net/launchpadlib/+bug/254901
370+ btags = bug.tags
371+ for t in ('verification-failed', 'verification-failed-%s' % release,
372+ 'verification-done', 'verification-done-%s' % release):
373+ if t in btags:
374+ tags = btags
375+ tags.remove(t)
376+ bug.tags = tags
377+
378+ if 'verification-needed' not in btags:
379+ btags.append('verification-needed')
380+ bug.tags = btags
381+
382+ needed_tag = 'verification-needed-%s' % release
383+ if needed_tag not in btags:
384+ btags.append(needed_tag)
385+ bug.tags = btags
386+
387+ bug.lp_save()
388+
389+ text = ('Hello %s, or anyone else affected,\n\n' %
390+ re.split(r'[,\s]', bug.owner.display_name)[0])
391+
392+ if sourcepkg:
393+ text += 'Accepted %s into ' % sourcepkg
394+ else:
395+ text += 'Accepted into '
396+ if sourcepkg and release:
397+ text += ('%s-proposed. The package will build now and be available at '
398+ 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
399+ 'and then in the -proposed repository.\n\n' % (
400+ release, sourcepkg, version))
401+ else:
402+ text += ('%s-proposed. The package will build now and be available in '
403+ 'a few hours in the -proposed repository.\n\n' % (
404+ release))
405+
406+ text += ('Please help us by testing this new package. ')
407+
408+ if sourcepkg == 'casper':
409+ text += ('To properly test it you will need to obtain and boot '
410+ 'a daily build of a Live CD for %s.' % (release))
411+ else:
412+ text += ('See https://wiki.ubuntu.com/Testing/EnableProposed for '
413+ 'documentation on how to enable and use -proposed.')
414+
415+ text += ('Your feedback will aid us getting this update out to other '
416+ 'Ubuntu users.\n\nIf this package fixes the bug for you, '
417+ 'please add a comment to this bug, mentioning the version of the '
418+ 'package you tested and change the tag from '
419+ 'verification-needed-%s to verification-done-%s. '
420+ 'If it does not fix the bug for you, please add a comment '
421+ 'stating that, and change the tag to verification-failed-%s. '
422+ 'In either case, without details of your testing we will not '
423+ 'be able to proceed.\n\nFurther information regarding the '
424+ 'verification process can be found at '
425+ 'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . '
426+ 'Thank you in advance!' % (release, release, release))
427+ bug.newMessage(content=text, subject='Please test proposed package')

Subscribers

People subscribed via source and target branches