From 3c2b5c6ed2dd772d4d9e11d291abdf7710356867 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Thu, 5 Sep 2019 09:55:52 +0200 Subject: Pagure - handle initial comment change event The "initial comment" is the first comment of a PR on Pagure. It is used to provide the Depends-on stanza. Recently Pagure added the capability to send an event when that initial comment is changed: https://pagure.io/pagure/issue/4398 This change handles the event as a PR changed to retrigger the attached jobs. Change-Id: I62d4e783e94528126cd4a7d85b3e664e84758bf1 --- tests/base.py | 6 ++++++ tests/unit/test_pagure_driver.py | 5 +++++ zuul/driver/pagure/pagureconnection.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/base.py b/tests/base.py index 885a070d0..01b8da1ac 100644 --- a/tests/base.py +++ b/tests/base.py @@ -851,6 +851,7 @@ class FakePagurePullRequest(object): 'commit_start': self.commit_start, 'commit_stop': self.commit_stop, 'date_created': '0', + 'initial_comment': self.initial_comment, 'id': self.number, 'project': { 'fullname': self.project, @@ -882,6 +883,11 @@ class FakePagurePullRequest(object): self.addComment(message) return self._getPullRequestEvent('pull-request.comment.added') + def getPullRequestInitialCommentEvent(self, message): + self.initial_comment = message + self._updateTimeStamp() + return self._getPullRequestEvent('pull-request.initial_comment.edited') + def getPullRequestStatusSetEvent(self, status): self.addFlag( status, "https://url", "Build %s" % status) diff --git a/tests/unit/test_pagure_driver.py b/tests/unit/test_pagure_driver.py index f0e8e121d..4643b8620 100644 --- a/tests/unit/test_pagure_driver.py +++ b/tests/unit/test_pagure_driver.py @@ -140,6 +140,11 @@ class TestPagureDriver(ZuulTestCase): self.waitUntilSettled() self.assertEqual(4, len(self.history)) + self.fake_pagure.emitEvent( + A.getPullRequestInitialCommentEvent('Initial comment edited')) + self.waitUntilSettled() + self.assertEqual(6, len(self.history)) + @simple_layout('layouts/basic-pagure.yaml', driver='pagure') def test_pull_request_with_dyn_reconf(self): diff --git a/zuul/driver/pagure/pagureconnection.py b/zuul/driver/pagure/pagureconnection.py index 2b5519c5f..8d91df223 100644 --- a/zuul/driver/pagure/pagureconnection.py +++ b/zuul/driver/pagure/pagureconnection.py @@ -75,8 +75,6 @@ from zuul.driver.pagure.paguremodel import PagureTriggerEvent, PullRequest # https://pagure.io/pagure/issue/4399 (merged so need to be used) # - Pagure does not reset the score when a PR code is updated # https://pagure.io/pagure/issue/3985 -# Pagure does not send an event when initial_comment is updated -# https://pagure.io/pagure/issue/4398 (merged need to be used) # - CI status flag updated field unit is second, better to have millisecond # unit to avoid unpossible sorting to get last status if two status set the # same second. @@ -201,6 +199,8 @@ class PagureEventConnector(threading.Thread): 'pull-request.new': self._event_pull_request, 'pull-request.flag.added': self._event_flag_added, 'git.receive': self._event_ref_updated, + 'pull-request.initial_comment.edited': + self._event_issue_initial_comment } def stop(self): @@ -265,6 +265,12 @@ class PagureEventConnector(threading.Thread): event.type = 'pg_push' return event, data + def _event_issue_initial_comment(self, body): + """ Handles pull request initial comment change """ + event, _ = self._event_base(body) + event.action = 'changed' + return event + def _event_issue_comment(self, body): """ Handles pull request comments """ # https://fedora-fedmsg.readthedocs.io/en/latest/topics.html#pagure-pull-request-comment-added -- cgit v1.2.1