-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_bugs.py
executable file
·97 lines (88 loc) · 3.33 KB
/
process_bugs.py
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
#
# Script to apply bulk changes to Launchpad bugs
#
# Copyright 2011-2013 Thierry Carrez <[email protected]>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from argparse import ArgumentParser
from launchpadlib.launchpad import Launchpad
from lazr.restfulclient.errors import ServerError
# Parameters
parser = ArgumentParser(description="Change bugs status in bulk")
parser.add_argument('projectname', help='The project to act on')
parser.add_argument('--status', default='Fix Committed',
help='Which bug status to bulk-change')
parser.add_argument("--test", action='store_const', const='staging',
default='production', help='Use LP staging server to test')
parser.add_argument('--settarget',
help='ACTION: set the milestone to specified target')
parser.add_argument('--fixrelease', action='store_true',
help='ACTION: mark bugs fix released')
parser.add_argument('exceptions', type=int, nargs='*', help='Bugs to ignore')
args = parser.parse_args()
if args.settarget:
if args.test == 'staging':
site = "https://api.staging.launchpad.net/1.0"
else:
site = "https://api.launchpad.net/1.0"
milestonelink = "%s/%s/+milestone/%s" \
% (site, args.projectname, args.settarget)
# Connect to Launchpad
print "Connecting to Launchpad..."
launchpad = Launchpad.login_with('openstack-releasing', args.test)
# Retrieve bugs
print "Retrieving project..."
proj = launchpad.projects[args.projectname]
changes = True
failed = set()
while changes:
changes = False
bugtasks = proj.searchTasks(status=args.status)
# Process bugs
for b in bugtasks:
bug = b.bug
# Skip bugs which triggered timeouts in previous runs
if bug.id in failed:
continue
# Skip already-milestoned bugs with a different milestone
if args.settarget and b.milestone:
if b.milestone.name != args.settarget:
continue
print bug.id,
if bug.id in args.exceptions:
print " - excepted"
continue
if args.settarget:
if not b.milestone:
b.milestone = milestonelink
print " - milestoned",
else:
print " - milestone already set",
if args.fixrelease:
print " - fixreleased",
b.status = 'Fix Released'
try:
b.lp_save()
if (args.settarget and not b.milestone) or args.fixrelease:
changes = True
except ServerError as e:
print " - TIMEOUT during save !",
failed.add(bug.id)
print
if failed:
print
print "Some bugs could not be automatically updated due to LP timeouts:"
for bugid in failed:
print "http://bugs.launchpad.net/bugs/%d" % bugid