From 374d472ecb57e820ad2ff8288d0ee501267efcc5 Mon Sep 17 00:00:00 2001 From: Max Lin Date: Mon, 18 Apr 2016 19:26:47 +0800 Subject: [PATCH] New staging repair command Mainly fix the request review if the request got reopened. --- osc-staging.py | 6 ++++- osclib/repair_command.py | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 osclib/repair_command.py diff --git a/osc-staging.py b/osc-staging.py index a73660f3..f4272b9e 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -36,6 +36,7 @@ from osclib.obslock import OBSLock from osclib.select_command import SelectCommand from osclib.stagingapi import StagingAPI from osclib.unselect_command import UnselectCommand +from osclib.repair_command import RepairCommand OSC_STAGING_VERSION = '0.0.1' @@ -120,6 +121,7 @@ def do_staging(self, subcmd, opts, *args): osc staging list [--supersede] osc staging select [--no-freeze] [--move [--from PROJECT]] LETTER REQUEST... osc staging unselect REQUEST... + osc staging repair REQUEST... """ if opts.version: self._print_version() @@ -128,7 +130,7 @@ def do_staging(self, subcmd, opts, *args): if len(args) == 0: raise oscerr.WrongArgs('No command given, see "osc help staging"!') cmd = args[0] - if cmd in ('freeze', 'frozenage'): + if cmd in ('freeze', 'frozenage', 'repair'): min_args, max_args = 1, None elif cmd == 'check': min_args, max_args = 0, 2 @@ -231,3 +233,5 @@ def do_staging(self, subcmd, opts, *args): ListCommand(api).perform(args[1:], supersede=opts.supersede) elif cmd == 'adi': AdiCommand(api).perform(args[1:], move=opts.move, by_dp=opts.by_develproject) + elif cmd == 'repair': + RepairCommand(api).perform(args[1:]) diff --git a/osclib/repair_command.py b/osclib/repair_command.py new file mode 100644 index 00000000..9cdc687e --- /dev/null +++ b/osclib/repair_command.py @@ -0,0 +1,55 @@ +from __future__ import print_function + +import re + +from osc import oscerr +from osc.core import change_review_state +from osc.core import get_request +from osclib.request_finder import RequestFinder + + +class RepairCommand(object): + + def __init__(self, api): + self.api = api + + def repair(self, request): + reviews = [] + reqid = str(request) + req = get_request(self.api.apiurl, reqid) + + if not req: + raise oscerr.WrongArgs('Request {} not found'.format(reqid)) + + if req.state.name != 'review': + print('Request "{}" is not in review state'.format(reqid)) + return + + reviews = [r.by_project for r in req.reviews if ':Staging:' in str(r.by_project) and r.state == 'new'] + + if reviews: + if len(reviews) > 1: + raise oscerr.WrongArgs('Request {} had multiple review opened by different staging project'.format(reqid)) + else: + raise oscerr.WrongArgs('Request {} is not for staging project'.format(reqid)) + + staging_project = reviews[0] + data = self.api.get_prj_pseudometa(staging_project) + for request in data['requests']: + if request['id'] == reqid: + print('Request "{}" had the good setup in "{}"'.format(reqid, staging_project)) + return + + # a bad request setup found + print('Repairing "{}"'.format(reqid)) + change_review_state(self.api.apiurl, reqid, newstate='accepted', message='Re-evaluation needed', by_project=staging_project) + self.api.add_review(reqid, by_group=self.api.cstaging_group, msg='Requesting new staging review') + + def perform(self, packages): + """ + Repair request in staging project or move it out + :param packages: packages/requests to repair in staging projects + """ + + for reqid in RequestFinder.find_sr(packages, self.api): + self.repair(reqid)