github: Do not process comment events for regular issues
Github uses the same webhook event for comments added to both regular issues and pull requests. Currently, Zuul will attempt to process non-PR issues which results in a number of API requests as it attempts to find non-existent pull requests. This needless traffic can cause rate-limiting issues in high traffic installations. The webhook body contains an extra key when comments originate from a PR, which we can use to filter. Change-Id: I9ab2cc7f37273126cfc669ebf2404215ca6c6f80
This commit is contained in:
parent
9dee755bb1
commit
83a2aa0d84
|
@ -702,7 +702,7 @@ class FakeGithubPullRequest(object):
|
|||
self.comments.append(message)
|
||||
self._updateTimeStamp()
|
||||
|
||||
def getCommentAddedEvent(self, text):
|
||||
def getIssueCommentAddedEvent(self, text):
|
||||
name = 'issue_comment'
|
||||
data = {
|
||||
'action': 'created',
|
||||
|
@ -721,6 +721,15 @@ class FakeGithubPullRequest(object):
|
|||
}
|
||||
return (name, data)
|
||||
|
||||
def getCommentAddedEvent(self, text):
|
||||
name, data = self.getIssueCommentAddedEvent(text)
|
||||
# A PR comment has an additional 'pull_request' key in the issue data
|
||||
data['issue']['pull_request'] = {
|
||||
'url': 'http://%s/api/v3/repos/%s/pull/%s' % (
|
||||
self.github.server, self.project, self.number)
|
||||
}
|
||||
return (name, data)
|
||||
|
||||
def getReviewAddedEvent(self, review):
|
||||
name = 'pull_request_review'
|
||||
data = {
|
||||
|
|
|
@ -101,6 +101,13 @@ class TestGithubDriver(ZuulTestCase):
|
|||
self.waitUntilSettled()
|
||||
self.assertEqual(2, len(self.history))
|
||||
|
||||
# Test an unmatched comment, history should remain the same
|
||||
C = self.fake_github.openFakePullRequest('org/project', 'master', 'C')
|
||||
self.fake_github.emitEvent(
|
||||
C.getIssueCommentAddedEvent('a non-PR issue comment'))
|
||||
self.waitUntilSettled()
|
||||
self.assertEqual(2, len(self.history))
|
||||
|
||||
@simple_layout('layouts/push-tag-github.yaml', driver='github')
|
||||
def test_tag_event(self):
|
||||
self.executor_server.hold_jobs_in_build = True
|
||||
|
|
|
@ -293,6 +293,9 @@ class GithubEventConnector(threading.Thread):
|
|||
action = body.get('action')
|
||||
if action != 'created':
|
||||
return
|
||||
if not body.get('issue', {}).get('pull_request'):
|
||||
# Do not process non-PR issue comment
|
||||
return
|
||||
pr_body = self._issue_to_pull_request(body)
|
||||
number = body.get('issue').get('number')
|
||||
project_name = body.get('repository').get('full_name')
|
||||
|
|
Loading…
Reference in New Issue