From d3178b4472c296e1c05855369d4ed0ac8bf9dd22 Mon Sep 17 00:00:00 2001 From: Patrice Clement Date: Mon, 18 Jul 2016 18:01:20 +0200 Subject: [PATCH] Add `stable' subcommand. This command allows to file stabilisation requests from the CLI. Type: $ lzilla stable --help to find out more. --- libzilla/cli/stable.py | 62 ++++++++++++++++++++++++++++++++++------ libzilla/connection.py | 42 +++++++++++++++++---------- libzilla/resturlmaker.py | 5 ++++ 3 files changed, 85 insertions(+), 24 deletions(-) diff --git a/libzilla/cli/stable.py b/libzilla/cli/stable.py index 8c308c0..9a5997d 100644 --- a/libzilla/cli/stable.py +++ b/libzilla/cli/stable.py @@ -1,4 +1,6 @@ +from libzilla.promptmaker import prompt from portage.xml.metadata import MetaDataXML +from libzilla.connection import Connection import portage import sys import os @@ -14,6 +16,16 @@ 'ebuild': 'Error! File \"{0}\" is not an ebuild!' } +DESCRIPTION = """Arch teams, + +Please stabilise: +{0} + +Target arches: +{1} + +Thank you!""" + class StableCommand: """lzilla stable: File a stabilisation request. @@ -37,11 +49,20 @@ def __init__(self, args): self.maintainers = [] self.arches = [] + self.cc = [] self.initialise_files(args['']) self.look_for_maintainers() self.look_for_keywords() - self.file_stabilisation_request() + + self.conn = Connection() + self.conn.login() + + promptmsg = """Ebuild: {0} +Arches: {1} +File stabilisation request? [y/n] """.format(self.ebuild, ', '.join(self.arches)) + if prompt(promptmsg) == 'y': + self.file_stabilisation_request() def initialise_files(self, ebuild): if not os.path.isfile(ebuild): @@ -71,26 +92,49 @@ def look_for_keywords(self): # work out ebuild's name ebuild = os.path.basename(self.ebuild) ebuild = os.path.splitext(ebuild)[0] - ebuild = '{0}/{1}'.format(cat, ebuild) + self.ebuild = '{0}/{1}'.format(cat, ebuild) # perform look up mysettings = portage.config(local_config=False) dbapi = portage.portdbapi(mysettings=mysettings) dbapi.porttrees = [dbapi.porttree_root] - keywords = dbapi.aux_get(ebuild, ['KEYWORDS'], dbapi.porttree_root)[0] + keywords = dbapi.aux_get(self.ebuild, ['KEYWORDS'], dbapi.porttree_root)[0] if len(keywords) == 0: sys.exit(ERROR_MESSAGES['keywords'].format(ebuild)) for arch in keywords.split(): - # only keep keywords in ~arch + # keep keywords in ~arch only if '~' in arch: # skip "exotic" arches such as ~amd64-macos and such if '-' in arch: continue - self.arches.append( - arch.strip('~') + '@gentoo.org' - ) + arch = arch.strip('~') + self.arches.append(arch) + self.cc.append(arch + '@gentoo.org') def file_stabilisation_request(self): - print('Maintainers: ' + str(self.maintainers)) - print('Arches: ' + str(self.arches)) + assignee = self.maintainers.pop() + if len(self.maintainers) > 0: + for maintainer in self.maintainers: + self.cc.append(maintainer) + + summary = '={0}: stabilisation request'.format(self.ebuild) + + stablereq = { + 'status': 'CONFIRMED', + 'summary': summary, + 'assigned_to': assignee, + 'version': 'unspecified', + 'product': 'Gentoo Linux', + 'severity': 'normal', + 'component': 'Current packages', + 'description': DESCRIPTION.format( + '=' + self.ebuild, + ', '.join(self.arches) + ), + 'priority': 'normal', + 'cc': self.cc, + 'keywords': ['STABLEREQ'] + } + + self.conn.file_bug(stablereq) diff --git a/libzilla/connection.py b/libzilla/connection.py index c1e5634..2a87ad2 100644 --- a/libzilla/connection.py +++ b/libzilla/connection.py @@ -60,14 +60,14 @@ def login(self): return self.connected - def send_request(self, request_type='', url=None, payload=None): - if payload: payload = json.dumps(payload) + def send_request(self, request_type='', url=None, data=None): + if data: data = json.dumps(data) http_request = { 'headers': { 'Content-Type': 'application/json' }, - 'data': payload, + 'data': data, 'url': url } @@ -82,8 +82,9 @@ def send_request(self, request_type='', url=None, payload=None): sys.exit(1) if response.status_code != 200: - logger.error('Bad request sent to server! HTTP code returned: {0}' - .format(response.status_code)) + logger.error('HTTP code returned: {0} -> {1}' + .format(response.status_code, + response.reason)) return response @@ -147,19 +148,19 @@ def update_bugs(self, list_of_bugs): .format(bug_number)) break - payload = { + data = { 'ids': bug_number, 'token': self.token, 'comment': {'body': comment} } if status and status != '': - payload['status'] = status + data['status'] = status logger.info('Setting STATUS to {0} ...' .format(status)) if resolution and resolution != '': - payload['resolution'] = resolution + data['resolution'] = resolution logger.info('Setting RESOLUTION to {0} ...' .format(resolution)) @@ -167,13 +168,24 @@ def update_bugs(self, list_of_bugs): logger.info('Posting comment to bug #{0} ...' .format(bug_number)) - response = self.send_request('PUT', url, payload) + response = self.send_request('PUT', url, data) - if not response.ok: - logger.error('An error occured whilst updating bug #{0}' - .format(bug_number)) - logger.error('The HTTP server returned the following error: {0}' - .format(response.reason)) - sys.exit(1) + if not response.ok: sys.exit(1) logger.info('OK!') + + def file_bug(self, data): + url = self.resturlmaker.make_new_bug_url() + data['token'] = self.token + logger.info('Filing bug ...') + response = self.send_request('POST', url, data) + + if not response.ok: sys.exit(1) + + logger.info('OK!') + + bug_id = response.json()['id'] + logger.info('New bug filed at https://bugs.gentoo.org/{0}' + .format(bug_id)) + + return response diff --git a/libzilla/resturlmaker.py b/libzilla/resturlmaker.py index 2275d70..15f0a00 100644 --- a/libzilla/resturlmaker.py +++ b/libzilla/resturlmaker.py @@ -20,3 +20,8 @@ def make_bug_url(self, bug_number=''): url=self.url, bug_number=bug_number ) + + def make_new_bug_url(self): + return Template('$url/bug').substitute( + url=self.url + )