Include broken package status information

This commit is contained in:
Alberto Planas 2014-09-16 17:59:34 +02:00
parent 13a05ba8d3
commit 92f7eff846

View File

@ -16,6 +16,7 @@
import argparse import argparse
from datetime import datetime, timedelta from datetime import datetime, timedelta
from collections import defaultdict
import json import json
from osclib.comments import CommentAPI from osclib.comments import CommentAPI
@ -25,11 +26,18 @@ import osc
MARGIN_HOURS = 4 MARGIN_HOURS = 4
class OpenQAReport(object): class OpenQAReport(object):
def __init__(self, api): def __init__(self, api):
self.api = api self.api = api
self.comment = CommentAPI(self.api.apiurl) self.comment = CommentAPI(self.api.apiurl)
def _package_url(self, package):
link = 'https://build.opensuse.org/package/live_build_log/%s/%s/%s/%s' % (
package['project'], package['package'], package['repository'], package['arch'])
text = '[%s](%s)' % (package['arch'], link)
return text
def _openQA_url(self, job): def _openQA_url(self, job):
test_name = job['name'].split('-')[-1] test_name = job['name'].split('-')[-1]
link = 'https://openqa.opensuse.org/tests/%s' % job['id'] link = 'https://openqa.opensuse.org/tests/%s' % job['id']
@ -48,7 +56,7 @@ class OpenQAReport(object):
safe_margin = timedelta(hours=MARGIN_HOURS) safe_margin = timedelta(hours=MARGIN_HOURS)
return safe_margin <= time_delta return safe_margin <= time_delta
def get_openQA_status(self, project): def get_info(self, project):
_prefix = 'openSUSE:{}:Staging:'.format(self.api.opensuse) _prefix = 'openSUSE:{}:Staging:'.format(self.api.opensuse)
if project.startswith(_prefix): if project.startswith(_prefix):
project = project.replace(_prefix, '') project = project.replace(_prefix, '')
@ -57,9 +65,21 @@ class OpenQAReport(object):
url = api.makeurl(('project', 'staging_projects', url = api.makeurl(('project', 'staging_projects',
'openSUSE:%s' % api.opensuse, project), query=query) 'openSUSE:%s' % api.opensuse, project), query=query)
info = json.load(api.retried_GET(url)) info = json.load(api.retried_GET(url))
return info['openqa_jobs'] if 'openqa_jobs' in info else None return info
def update_openQA_status_comment(self, project, report): def get_broken_package_status(self, info):
status = info['broken_packages']
for subproject in info['subprojects']:
status.extend(subproject['broken_packages'])
return status
def get_openQA_status(self, info):
status = info['openqa_jobs']
for subproject in info['subprojects']:
status.extend(subproject['openqa_jobs'])
return status
def update_status_comment(self, project, report):
signature = '<!-- openQA status -->' signature = '<!-- openQA status -->'
report = '%s\n%s' % (signature, str(report)) report = '%s\n%s' % (signature, str(report))
@ -81,10 +101,25 @@ class OpenQAReport(object):
if write_comment: if write_comment:
self.comment.add_comment(project_name=project, comment=report) self.comment.add_comment(project_name=project, comment=report)
def _report(self, project): def _report_broken_packages(self, info):
broken_package_status = self.get_broken_package_status(info)
# Group packages by name
groups = defaultdict(list)
for package in broken_package_status:
groups[package['package']].append(package)
failing_lines = [
'* Build failed %s (%s)' % (key, ', '.join(self._package_url(p) for p in value))
for key, value in groups.iteritems()
]
return '\n'.join(failing_lines)
def _report_openQA(self, info):
failing_lines, green_lines = [], [] failing_lines, green_lines = [], []
openQA_status = self.get_openQA_status(project) openQA_status = self.get_openQA_status(info)
for job in openQA_status: for job in openQA_status:
test_name = job['name'].split('-')[-1] test_name = job['name'].split('-')[-1]
fails = [ fails = [
@ -106,12 +141,14 @@ class OpenQAReport(object):
return '\n'.join((failing_report, green_report)) return '\n'.join((failing_report, green_report))
def report(self, project): def report(self, project):
report = self._report(project) info = self.get_info(project)
report_dvd = self._report(project+':DVD') report_broken_packages = self._report_broken_packages(info)
report_openQA = self._report_openQA(info)
if report or report_dvd: if report_broken_packages or report_openQA:
report = report + '\n\nFor DVD:\n\n' + report_dvd report = report_broken_packages + '\n\n' + report_openQA
self.update_openQA_status_comment(project, report) print report
# self.update_openQA_status_comment(project, report)
if __name__ == '__main__': if __name__ == '__main__':
@ -138,7 +175,7 @@ if __name__ == '__main__':
openQA = OpenQAReport(api) openQA = OpenQAReport(api)
if args.staging: if args.staging:
openQA.report(api.prj_from_letter(args.staging)) openQA.report(api.prj_from_letter(args.staging))
else: else:
for staging in api.get_staging_projects(): for staging in api.get_staging_projects():
if not staging.endswith(':DVD'): if not staging.endswith(':DVD'):