Add bug-deferral feature to process_bugs.py

Add a new --milestone selection option in process_bugs.py to allow
selection of all open bugs from a given milestone.

That lets you defer bugs using:
./process_bugs.py glance --milestone juno-2 --settarget juno-3

Change-Id: I50f0081d49a491aaaa07c34f9dd9d9a608468e7f
This commit is contained in:
Thierry Carrez 2014-06-24 14:51:54 +02:00
parent 9e5695c47e
commit c7d28d5581
1 changed files with 25 additions and 16 deletions

View File

@ -22,10 +22,12 @@ from launchpadlib.launchpad import Launchpad
from lazr.restfulclient.errors import ServerError
# Parameters
parser = ArgumentParser(description="Change bugs status in bulk")
parser = ArgumentParser(description="Change Launchpad bugs 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')
bugsfrom = parser.add_mutually_exclusive_group()
bugsfrom.add_argument('--status', default='Fix Committed',
help='All bugs with that status')
bugsfrom.add_argument('--milestone', help='All open bugs from this milestone')
parser.add_argument("--test", action='store_const', const='staging',
default='production', help='Use LP staging server to test')
parser.add_argument('--settarget',
@ -36,14 +38,6 @@ 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)
@ -54,9 +48,23 @@ proj = launchpad.projects[args.projectname]
changes = True
failed = set()
if args.settarget:
to_milestone = proj.getMilestone(name=args.settarget)
if not to_milestone:
parser.error('Target milestone %s does not exist' % args.milestone)
if args.milestone:
open_status = ['New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress']
from_milestone = proj.getMilestone(name=args.milestone)
if not from_milestone:
parser.error('Origin milestone %s does not exist' % args.milestone)
while changes:
changes = False
bugtasks = proj.searchTasks(status=args.status)
if args.milestone:
bugtasks = from_milestone.searchTasks(status=open_status)
else:
bugtasks = proj.searchTasks(status=args.status)
# Process bugs
for b in bugtasks:
@ -64,8 +72,9 @@ while changes:
# 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 the action is settarget and you're not in milestone selection
# mode, skip already-milestoned bugs with a different milestone
if (not args.milestone) and (args.settarget and b.milestone):
if b.milestone.name != args.settarget:
continue
print bug.id,
@ -73,8 +82,8 @@ while changes:
print " - excepted"
continue
if args.settarget:
if not b.milestone:
b.milestone = milestonelink
if b.milestone != to_milestone:
b.milestone = to_milestone
print " - milestoned",
else:
print " - milestone already set",