1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-23 05:26:16 +01:00

- request_interactive_review: support "-f" parameter to force a request state change

This commit is contained in:
Marcus Huewe 2012-10-26 15:19:00 +02:00
parent 6c5806c21e
commit b8dedd3f8f
2 changed files with 28 additions and 11 deletions

View File

@ -2033,7 +2033,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
for result in results: for result in results:
if days == 0 or result.state.when > since or result.state.name == 'new': if days == 0 or result.state.when > since or result.state.name == 'new':
if (opts.interactive or conf.config['request_show_interactive']) and not opts.non_interactive: if (opts.interactive or conf.config['request_show_interactive']) and not opts.non_interactive:
request_interactive_review(apiurl, result, group=opts.group) ignore_reviews = subcmd != 'review'
request_interactive_review(apiurl, result, group=opts.group, ignore_reviews=ignore_reviews)
else: else:
print result.list_view(), '\n' print result.list_view(), '\n'
else: else:
@ -2071,7 +2072,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
'(request has no \'submit\' action)') '(request has no \'submit\' action)')
return request_interactive_review(apiurl, r, 'e') return request_interactive_review(apiurl, r, 'e')
elif (opts.interactive or conf.config['request_show_interactive']) and not opts.non_interactive: elif (opts.interactive or conf.config['request_show_interactive']) and not opts.non_interactive:
return request_interactive_review(apiurl, r, group=opts.group) ignore_reviews = subcmd != 'review'
return request_interactive_review(apiurl, r, group=opts.group, ignore_reviews=ignore_reviews)
else: else:
print r print r
if opts.source_buildstatus: if opts.source_buildstatus:

View File

@ -6118,12 +6118,21 @@ def print_request_list(apiurl, project, package = None, states = ('new','review'
for r in requests: for r in requests:
print r.list_view(), '\n' print r.list_view(), '\n'
def request_interactive_review(apiurl, request, initial_cmd='', group=None): def request_interactive_review(apiurl, request, initial_cmd='', group=None, ignore_reviews=False):
"""review the request interactively""" """review the request interactively"""
import tempfile, re import tempfile, re
tmpfile = None tmpfile = None
def safe_change_request_state(*args, **kwargs):
try:
change_request_state(*args, **kwargs)
return True
except urllib2.HTTPError, e:
print >>sys.stderr, 'Server returned an error:', e
print >>sys.stderr, 'Try -f to force the state change'
return False
def print_request(request): def print_request(request):
print request print request
@ -6189,12 +6198,13 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None):
prompt = 'd(i)ff/(a)ccept/(b)uildstatus/(e)dit/(s)kip/(c)ancel > ' prompt = 'd(i)ff/(a)ccept/(b)uildstatus/(e)dit/(s)kip/(c)ancel > '
else: else:
state_map = {'a': 'accepted', 'd': 'declined', 'r': 'revoked'} state_map = {'a': 'accepted', 'd': 'declined', 'r': 'revoked'}
mo = re.search('^([adrl])(?:\s+-m\s+(.*))?$', repl) mo = re.search('^([adrl])(?:\s+(-f)?\s*-m\s+(.*))?$', repl)
if mo is None or orequest and mo.group(1) != 'a': if mo is None or orequest and mo.group(1) != 'a':
print >>sys.stderr, 'invalid choice: \'%s\'' % repl print >>sys.stderr, 'invalid choice: \'%s\'' % repl
continue continue
state = state_map.get(mo.group(1)) state = state_map.get(mo.group(1))
msg = mo.group(2) force = mo.group(2) is not None
msg = mo.group(3)
footer = '' footer = ''
msg_template = '' msg_template = ''
if not (state is None or request.state is None): if not (state is None or request.state is None):
@ -6216,18 +6226,23 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None):
msg = msg.strip('\'').strip('"') msg = msg.strip('\'').strip('"')
if not orequest is None: if not orequest is None:
request.create(apiurl) request.create(apiurl)
change_request_state(apiurl, request.reqid, 'accepted', msg) if not safe_change_request_state(apiurl, request.reqid, 'accepted', msg, force=force):
# an error occured
continue
repl = raw_input('Supersede original request? (y|N) ') repl = raw_input('Supersede original request? (y|N) ')
if repl in ('y', 'Y'): if repl in ('y', 'Y'):
change_request_state(apiurl, orequest.reqid, 'superseded', safe_change_request_state(apiurl, orequest.reqid, 'superseded',
'superseded by %s' % request.reqid, request.reqid) 'superseded by %s' % request.reqid, request.reqid, force=force)
elif state is None: elif state is None:
clone_request(apiurl, request.reqid, msg) clone_request(apiurl, request.reqid, msg)
else: else:
reviews = [r for r in request.reviews if r.state == 'new'] reviews = [r for r in request.reviews if r.state == 'new']
if not reviews: if not reviews or ignore_reviews:
change_request_state(apiurl, request.reqid, state, msg) if safe_change_request_state(apiurl, request.reqid, state, msg, force=force):
break break
else:
# an error occured
continue
group_reviews = [r for r in reviews if (r.by_group is not None group_reviews = [r for r in reviews if (r.by_group is not None
and r.by_group == group)] and r.by_group == group)]
if len(group_reviews) == 1 and conf.config['review_inherit_group']: if len(group_reviews) == 1 and conf.config['review_inherit_group']: