New staging repair command
Mainly fix the request review if the request got reopened.
This commit is contained in:
parent
7106a1cfaf
commit
374d472ecb
@ -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:])
|
||||
|
55
osclib/repair_command.py
Normal file
55
osclib/repair_command.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user