From 2a67eb1f5d95822179af66036262324c380b6b17 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 21 2018 11:20:30 +0000 Subject: Flag the PR once the build has been submitted This way the users will be able to see the build in progress and will have a better idea if simple-koji-ci is working or not. Fixes https://pagure.io/fedora-ci/simple-koji-ci/issue/4 Signed-off-by: Pierre-Yves Chibon --- diff --git a/simple_koji_ci/consumers.py b/simple_koji_ci/consumers.py index b4f8e8e..7111943 100644 --- a/simple_koji_ci/consumers.py +++ b/simple_koji_ci/consumers.py @@ -22,6 +22,7 @@ Authors: Ralph Bean """ import logging +import uuid from requests.packages.urllib3.util import retry import fedmsg @@ -180,9 +181,25 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): # Kick off a scratch build.. task_id = self.buildsys.handle(package, prid) + uid = uuid.uuid4().hex + # Map that koji task_id to the pull-request we want to flag self.scratch_builds[task_id] = dict( - prid=prid, name=package, namespace=namespace) + prid=prid, name=package, namespace=namespace, + uid=uid + ) + + # Flag the PR that the build is in progress + koji_url = self.buildsys.url_for(task_id) + data = { + 'username': 'simple-koji-ci', + 'status': 'pending', + 'comment': 'Build in progress', + 'url': koji_url, + } + + self._flag_pr(task_id, koji_url, data) + except Exception as e: _log.exception(e) @@ -228,6 +245,20 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): return koji_url = _koji_link(msg) + data = { + 'username': 'simple-koji-ci', + 'status': 'success' if state == 'CLOSED' else 'failure', + 'comment': 'Build %s' % done_states[state], + 'url': koji_url, + } + + self._flag_pr(task_id, koji_url, data) + + del(self.scratch_builds[task_id]) + + def _flag_pr(self, task_id, koji_url, data): + """ Flag a specified pull-request with the given dataload. + """ pk_info = self.scratch_builds[task_id] pagure_url = self.config["simple-koji-ci.pagure_url"].rstrip('/') @@ -248,12 +279,8 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): + self.config["simple-koji-ci.pagure_token"], 'User-Agent': 'simple-koji-ci %s' % __version__, } - data = { - 'username': 'simple-koji-ci', - 'percent': 100 if state == 'CLOSED' else 0, - 'comment': 'Build %s' % done_states[state], - 'url': koji_url, - } + + data['uid'] = pk_info['uid'] _log.debug('payload: %s' % data) @@ -269,5 +296,3 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): _log.debug(req.text) else: _log.debug('All clear') - - del(self.scratch_builds[task_id])