mirror of
https://github.com/openSUSE/osc.git
synced 2024-09-20 01:06:17 +02:00
- review a request interactively
per default this "feature" is disabled
This commit is contained in:
parent
3e4f6fdc9e
commit
3a909cf75b
@ -1015,6 +1015,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
help='only show requests created by yourself')
|
||||
@cmdln.option('-B', '--bugowner', action='store_true',
|
||||
help='also show requests about packages where I am bugowner')
|
||||
@cmdln.option('-i', '--interactive', action='store_true',
|
||||
help='interactive review of request')
|
||||
@cmdln.alias("rq")
|
||||
@cmdln.alias("review")
|
||||
def do_request(self, subcmd, opts, *args):
|
||||
@ -1191,6 +1193,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
r = get_request(conf.config['apiurl'], reqid)
|
||||
if opts.brief:
|
||||
print r.list_view()
|
||||
elif opts.interactive or conf.config['request_show_interactive']:
|
||||
return request_interactive_review(conf.config['apiurl'], r)
|
||||
else:
|
||||
print r
|
||||
# fixme: will inevitably fail if the given target doesn't exist
|
||||
|
@ -110,6 +110,7 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org',
|
||||
'check_for_request_on_action': '0',
|
||||
# what to do with the source package if the submitrequest has been accepted
|
||||
'submitrequest_on_accept_action': '',
|
||||
'request_show_interactive': '0',
|
||||
'linkcontrol': '0',
|
||||
|
||||
# Maintenance defaults to OBS instance defaults
|
||||
@ -123,7 +124,7 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org',
|
||||
config = DEFAULTS.copy()
|
||||
|
||||
boolean_opts = ['debug', 'do_package_tracking', 'http_debug', 'post_mortem', 'traceback', 'check_filelist', 'plaintext_passwd',
|
||||
'checkout_no_colon', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress']
|
||||
'checkout_no_colon', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress', 'request_show_interactive']
|
||||
|
||||
new_conf_template = """
|
||||
[general]
|
||||
@ -202,6 +203,9 @@ apiurl = %(apiurl)s
|
||||
# nothing is specified the API default is used
|
||||
#submitrequest_on_accept_action = cleanup|update|noupdate
|
||||
|
||||
#review requests interactively (default: off)
|
||||
#request_show_review = 1
|
||||
|
||||
[%(apiurl)s]
|
||||
user = %(user)s
|
||||
pass = %(pass)s
|
||||
|
40
osc/core.py
40
osc/core.py
@ -4602,3 +4602,43 @@ def print_request_list(apiurl, project, package = None, states = ('new', ), forc
|
||||
print msg % ('package', '/'.join([project, package]), len(requests))
|
||||
for r in requests:
|
||||
print r.list_view()
|
||||
|
||||
def request_interactive_review(apiurl, request):
|
||||
"""review the request interactively"""
|
||||
import tempfile, subprocess, re
|
||||
|
||||
tmpfile = None
|
||||
print request
|
||||
try:
|
||||
while True:
|
||||
repl = raw_input('d(i)ff/(a)ccept/(d)ecline/(r)evoke/(c)ancel > ')
|
||||
if repl == 'i':
|
||||
if tmpfile is None:
|
||||
tmpfile = tempfile.NamedTemporaryFile()
|
||||
tmpfile.write(server_diff(apiurl, request.actions[0].dst_project, request.actions[0].dst_package, None,
|
||||
request.actions[0].src_project, request.actions[0].src_package, request.actions[0].src_rev, True))
|
||||
pager = os.getenv('EDITOR', default='less')
|
||||
subprocess.call('%s %s' % (pager, tmpfile.name), shell=True)
|
||||
elif repl == 'c':
|
||||
print >>sys.stderr, 'Aborting'
|
||||
sys.exit(1)
|
||||
else:
|
||||
state_map = {'a': 'accepted', 'd': 'decline', 'r': 'revoke'}
|
||||
mo = re.search('^([adr])(?:\s+-m\s+(.*))?$', repl)
|
||||
if mo is None:
|
||||
raise oscerr.WrongOptions('invalid choice: \'%s\'' % repl)
|
||||
state = state_map[mo.group(1)]
|
||||
msg = mo.group(2)
|
||||
footer = str(request)
|
||||
if tmpfile is not None:
|
||||
tmpfile.seek(0)
|
||||
# the read bytes probably have a moderate size so the str won't be too large
|
||||
footer += '\n\n' + tmpfile.read()
|
||||
if msg is None:
|
||||
msg = edit_message(footer = footer)
|
||||
else:
|
||||
msg = msg.strip('\'').strip('"')
|
||||
change_request_state(apiurl, str(request.reqid), state, msg)
|
||||
finally:
|
||||
if tmpfile is not None:
|
||||
tmpfile.close()
|
||||
|
Loading…
Reference in New Issue
Block a user