From 81d356dd03dbc08619c4a0b9c81445711fa637f5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 22 2018 09:56:51 +0000 Subject: Re-trigger the scratch build on pull-request notifications Signed-off-by: Pierre-Yves Chibon --- diff --git a/simple_koji_ci/consumers.py b/simple_koji_ci/consumers.py index a9c99cf..7b5969d 100644 --- a/simple_koji_ci/consumers.py +++ b/simple_koji_ci/consumers.py @@ -83,7 +83,8 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): 'org.fedoraproject.prod.pagure.pull-request.new', # Updates to an existing pull-request - #'org.fedoraproject.prod.pagure.pull-request.comment.added', + 'org.fedoraproject.stg.pagure.pull-request.comment.added', + 'org.fedoraproject.prod.pagure.pull-request.comment.added', # Anyways, we also listen for koji scratch builds to circle back: 'org.fedoraproject.stg.buildsys.task.state.change', @@ -192,7 +193,7 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): prid=prid, name=package, namespace=namespace, - uid=uid + uid=uid, commit=commit, ) @@ -209,6 +210,60 @@ class SimpleKojiCi(fedmsg.consumers.FedmsgConsumer): except Exception as e: _log.exception(e) + + def handle_pagure_pr_update(self, msg): + """ + Message handler for new pull-request opened in pagure. + + Topic: ``org.fedoraproject.pagure.pull-request.comment.added`` + + """ + _log.info("Handling pagure msg %r" % msg.get('msg_id', None)) + + prid = msg['msg']['pullrequest']['id'] + package = msg['msg']['pullrequest']['project']['name'] + namespace = msg['msg']['pullrequest']['project']['namespace'] + branch_to = msg['msg']['pullrequest']['branch'] + commit = msg['msg']['pullrequest'].get('commit_stop') + commit_label = ' for %s' % commit[:8] if commit else '' + + if msg['msg']['pullrequest']['status'] != 'Open': + _log.info('Pull-request not open, discarding') + return + + if not msg['msg']['pullrequest']['comments']: + _log.info('This is most odd, we\'re not seeing comments') + return + + last_comment = msg['msg']['pullrequest']['comments'][-1] + + if not last_comment or last_comment['notification'] is False: + _log.info('Comment was not a notification, discarding') + return + + try: + _log.info('Re-Kicking a scratch build for ' + str(package)) + # Kick off a scratch build.. + task_id = self.buildsys.handle( + package, prid, branch_to=branch_to) + + 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, + uid=uid, + commit=commit, + ) + + # 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': 'New build in progress%s' % commit_label, 'url': koji_url, }