Support for github commit status
Github reporter sets commit status of pull request based on the result
of the pipeline.
Change-Id: Id95bf0dbaa710c555e3a1838d3430e18ac9501aa
Co-Authored-By: Jesse Keating <omgjlk@us.ibm.com>
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 1e5f6a6..9017ce9 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -13,6 +13,8 @@
# under the License.
import logging
+import re
+from testtools.matchers import MatchesRegex
from tests.base import ZuulTestCase, simple_layout, random_sha1
@@ -122,3 +124,44 @@
"""Test that git_ssh option gives git url with ssh"""
url = self.fake_github_ssh.real_getGitUrl('org/project')
self.assertEqual('ssh://git@github.com/org/project.git', url)
+
+ @simple_layout('layouts/reporting-github.yaml', driver='github')
+ def test_reporting(self):
+ # pipeline reports pull status both on start and success
+ self.executor_server.hold_jobs_in_build = True
+ pr = self.fake_github.openFakePullRequest('org/project', 'master')
+ self.fake_github.emitEvent(pr.getPullRequestOpenedEvent())
+ self.waitUntilSettled()
+ self.assertIn('check', pr.statuses)
+ check_status = pr.statuses['check']
+ self.assertEqual('Standard check', check_status['description'])
+ self.assertEqual('pending', check_status['state'])
+ self.assertEqual('http://zuul.example.com/status', check_status['url'])
+ self.assertEqual(0, len(pr.comments))
+
+ self.executor_server.hold_jobs_in_build = False
+ self.executor_server.release()
+ self.waitUntilSettled()
+ check_status = pr.statuses['check']
+ self.assertEqual('Standard check', check_status['description'])
+ self.assertEqual('success', check_status['state'])
+ self.assertEqual('http://zuul.example.com/status', check_status['url'])
+ self.assertEqual(1, len(pr.comments))
+ self.assertThat(pr.comments[0],
+ MatchesRegex('.*Build succeeded.*', re.DOTALL))
+
+ # pipeline does not report any status but does comment
+ self.executor_server.hold_jobs_in_build = True
+ self.fake_github.emitEvent(
+ pr.getCommentAddedEvent('reporting check'))
+ self.waitUntilSettled()
+ self.assertNotIn('reporting', pr.statuses)
+ # comments increased by one for the start message
+ self.assertEqual(2, len(pr.comments))
+ self.assertThat(pr.comments[1],
+ MatchesRegex('.*Starting reporting jobs.*', re.DOTALL))
+ self.executor_server.hold_jobs_in_build = False
+ self.executor_server.release()
+ self.waitUntilSettled()
+ self.assertNotIn('reporting', pr.statuses)
+ self.assertEqual(2, len(pr.comments))