Merge "Handle GitHub comment reviews carefully" into feature/zuulv3

This commit is contained in:
Jenkins 2017-07-07 19:58:42 +00:00 committed by Gerrit Code Review
commit 56cc3b4817
2 changed files with 43 additions and 1 deletions

View File

@ -255,6 +255,37 @@ class TestGithubRequirements(ZuulTestCase):
self.assertEqual(len(self.history), 1)
self.assertEqual(self.history[0].name, 'project5-reviewuserstate')
@simple_layout('layouts/requirements-github.yaml', driver='github')
def test_pipeline_require_review_comment_masked(self):
"Test pipeline requirement: review comments on top of votes"
A = self.fake_github.openFakePullRequest('org/project5', 'master', 'A')
# Add derp to writers
A.writers.append('derp')
# A comment event that we will keep submitting to trigger
comment = A.getCommentAddedEvent('test me')
self.fake_github.emitEvent(comment)
self.waitUntilSettled()
# No positive review from derp so should not be enqueued
self.assertEqual(len(self.history), 0)
# The first negative review from derp should not cause it to be
# enqueued
A.addReview('derp', 'CHANGES_REQUESTED')
self.fake_github.emitEvent(comment)
self.waitUntilSettled()
self.assertEqual(len(self.history), 0)
# A positive review is required, so provide it
A.addReview('derp', 'APPROVED')
# Add a comment review on top to make sure we can still enqueue
A.addReview('derp', 'COMMENTED')
self.fake_github.emitEvent(comment)
self.waitUntilSettled()
self.assertEqual(len(self.history), 1)
self.assertEqual(self.history[0].name, 'project5-reviewuserstate')
@simple_layout('layouts/requirements-github.yaml', driver='github')
def test_require_review_newer_than(self):

View File

@ -776,8 +776,19 @@ class GithubConnection(BaseConnection):
# if there are multiple reviews per user, keep the newest
# note that this breaks the ability to set the 'older-than'
# option on a review requirement.
# BUT do not keep the latest if it's a 'commented' type and the
# previous review was 'approved' or 'changes_requested', as
# the GitHub model does not change the vote if a comment is
# added after the fact. THANKS GITHUB!
if review['grantedOn'] > reviews[user]['grantedOn']:
reviews[user] = review
if (review['type'] == 'commented' and reviews[user]['type']
in ('approved', 'changes_requested')):
self.log.debug("Discarding comment review %s due to "
"an existing vote %s" % (review,
reviews[user]))
pass
else:
reviews[user] = review
return reviews.values()