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
This commit is contained in:
Fabien Boucher 2019-09-05 09:55:52 +02:00
parent 795520d286
commit 3c2b5c6ed2
3 changed files with 19 additions and 2 deletions

View File

@ -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)

View File

@ -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):

View File

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