Skip to content

Commit

Permalink
Add `stable' subcommand.
Browse files Browse the repository at this point in the history
This command allows to file stabilisation requests from the CLI. Type:

$ lzilla stable --help

to find out more.
  • Loading branch information
monsieurp committed Jul 18, 2016
1 parent b935a36 commit d3178b4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 24 deletions.
62 changes: 53 additions & 9 deletions libzilla/cli/stable.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -37,11 +49,20 @@ def __init__(self, args):

self.maintainers = []
self.arches = []
self.cc = []

self.initialise_files(args['<ebuild>'])
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):
Expand Down Expand Up @@ -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)
42 changes: 27 additions & 15 deletions libzilla/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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

Expand Down Expand Up @@ -147,33 +148,44 @@ 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))

if comment and comment != '':
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
5 changes: 5 additions & 0 deletions libzilla/resturlmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit d3178b4

Please # to comment.