summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-27 22:35:25 +0000
committerGerrit Code Review <review@openstack.org>2018-11-27 22:35:25 +0000
commit2baecbeb4122db2525be0b5dde72e7ff7166a8b9 (patch)
treea2a50d61641c06bf671c1230989deb5935c83fdb
parent1ac3eb9fb719600e82b67e645db10b45ae28373c (diff)
parentbc136cb40e7215f790fd40f2121ba4c8a6552c94 (diff)
Merge "Fix manual dequeue of github items"
-rw-r--r--tests/base.py8
-rw-r--r--tests/fakegithub.py2
-rw-r--r--tests/unit/test_github_driver.py65
-rw-r--r--zuul/driver/github/githubconnection.py7
4 files changed, 76 insertions, 6 deletions
diff --git a/tests/base.py b/tests/base.py
index 4aa3900..2c6e675 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -1228,7 +1228,7 @@ class FakeGithubConnection(githubconnection.GithubConnection):
1228 self.getGithubClient(project).addProject(project) 1228 self.getGithubClient(project).addProject(project)
1229 1229
1230 def _getPullReviews(self, owner, project, number): 1230 def _getPullReviews(self, owner, project, number):
1231 pr = self.pull_requests[number] 1231 pr = self.pull_requests[int(number)]
1232 return pr.reviews 1232 return pr.reviews
1233 1233
1234 def getGitUrl(self, project): 1234 def getGitUrl(self, project):
@@ -1246,13 +1246,13 @@ class FakeGithubConnection(githubconnection.GithubConnection):
1246 def commentPull(self, project, pr_number, message): 1246 def commentPull(self, project, pr_number, message):
1247 # record that this got reported 1247 # record that this got reported
1248 self.reports.append((project, pr_number, 'comment')) 1248 self.reports.append((project, pr_number, 'comment'))
1249 pull_request = self.pull_requests[pr_number] 1249 pull_request = self.pull_requests[int(pr_number)]
1250 pull_request.addComment(message) 1250 pull_request.addComment(message)
1251 1251
1252 def mergePull(self, project, pr_number, commit_message='', sha=None): 1252 def mergePull(self, project, pr_number, commit_message='', sha=None):
1253 # record that this got reported 1253 # record that this got reported
1254 self.reports.append((project, pr_number, 'merge')) 1254 self.reports.append((project, pr_number, 'merge'))
1255 pull_request = self.pull_requests[pr_number] 1255 pull_request = self.pull_requests[int(pr_number)]
1256 if self.merge_failure: 1256 if self.merge_failure:
1257 raise Exception('Pull request was not merged') 1257 raise Exception('Pull request was not merged')
1258 if self.merge_not_allowed_count > 0: 1258 if self.merge_not_allowed_count > 0:
@@ -1272,7 +1272,7 @@ class FakeGithubConnection(githubconnection.GithubConnection):
1272 def labelPull(self, project, pr_number, label): 1272 def labelPull(self, project, pr_number, label):
1273 # record that this got reported 1273 # record that this got reported
1274 self.reports.append((project, pr_number, 'label', label)) 1274 self.reports.append((project, pr_number, 'label', label))
1275 pull_request = self.pull_requests[pr_number] 1275 pull_request = self.pull_requests[int(pr_number)]
1276 pull_request.addLabel(label) 1276 pull_request.addLabel(label)
1277 1277
1278 def unlabelPull(self, project, pr_number, label): 1278 def unlabelPull(self, project, pr_number, label):
diff --git a/tests/fakegithub.py b/tests/fakegithub.py
index 581b306..6b951ef 100644
--- a/tests/fakegithub.py
+++ b/tests/fakegithub.py
@@ -379,7 +379,7 @@ class FakeGithubClient(object):
379 project_name, self._data) 379 project_name, self._data)
380 380
381 def pull_request(self, owner, project, number): 381 def pull_request(self, owner, project, number):
382 fake_pr = self._data.pull_requests[number] 382 fake_pr = self._data.pull_requests[int(number)]
383 return FakePull(fake_pr) 383 return FakePull(fake_pr)
384 384
385 def search_issues(self, query): 385 def search_issues(self, query):
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 1fca162..14b9979 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -23,6 +23,8 @@ from unittest import mock, skip
23import git 23import git
24import github3.exceptions 24import github3.exceptions
25 25
26import zuul.rpcclient
27
26from tests.base import ZuulTestCase, simple_layout, random_sha1 28from tests.base import ZuulTestCase, simple_layout, random_sha1
27from tests.base import ZuulWebFixture 29from tests.base import ZuulWebFixture
28 30
@@ -52,6 +54,8 @@ class TestGithubDriver(ZuulTestCase):
52 self.assertEqual(str(A.number), zuulvars['change']) 54 self.assertEqual(str(A.number), zuulvars['change'])
53 self.assertEqual(str(A.head_sha), zuulvars['patchset']) 55 self.assertEqual(str(A.head_sha), zuulvars['patchset'])
54 self.assertEqual('master', zuulvars['branch']) 56 self.assertEqual('master', zuulvars['branch'])
57 self.assertEquals('https://github.com/org/project/pull/1',
58 zuulvars['items'][0]['change_url'])
55 self.assertEqual(1, len(A.comments)) 59 self.assertEqual(1, len(A.comments))
56 self.assertThat( 60 self.assertThat(
57 A.comments[0], 61 A.comments[0],
@@ -935,6 +939,67 @@ class TestGithubDriver(ZuulTestCase):
935 new_sha='0' * 40, 939 new_sha='0' * 40,
936 modified_files=['README.md']) 940 modified_files=['README.md'])
937 941
942 @simple_layout('layouts/basic-github.yaml', driver='github')
943 def test_client_dequeue_change_github(self):
944 "Test that the RPC client can dequeue a github pull request"
945
946 client = zuul.rpcclient.RPCClient('127.0.0.1',
947 self.gearman_server.port)
948 self.addCleanup(client.shutdown)
949
950 self.executor_server.hold_jobs_in_build = True
951 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
952
953 self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
954 self.waitUntilSettled()
955
956 client.dequeue(
957 tenant='tenant-one',
958 pipeline='check',
959 project='org/project',
960 change='{},{}'.format(A.number, A.head_sha),
961 ref=None)
962
963 self.waitUntilSettled()
964
965 tenant = self.sched.abide.tenants.get('tenant-one')
966 check_pipeline = tenant.layout.pipelines['check']
967 self.assertEqual(check_pipeline.getAllItems(), [])
968 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
969
970 self.executor_server.hold_jobs_in_build = False
971 self.executor_server.release()
972 self.waitUntilSettled()
973
974 @simple_layout('layouts/basic-github.yaml', driver='github')
975 def test_client_enqueue_change_github(self):
976 "Test that the RPC client can enqueue a pull request"
977 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
978
979 client = zuul.rpcclient.RPCClient('127.0.0.1',
980 self.gearman_server.port)
981 self.addCleanup(client.shutdown)
982 r = client.enqueue(tenant='tenant-one',
983 pipeline='check',
984 project='org/project',
985 trigger='github',
986 change='{},{}'.format(A.number, A.head_sha))
987 self.waitUntilSettled()
988
989 self.assertEqual(self.getJobFromHistory('project-test1').result,
990 'SUCCESS')
991 self.assertEqual(self.getJobFromHistory('project-test2').result,
992 'SUCCESS')
993 self.assertEqual(r, True)
994
995 # check that change_url is correct
996 job1_params = self.getJobFromHistory('project-test1').parameters
997 job2_params = self.getJobFromHistory('project-test2').parameters
998 self.assertEquals('https://github.com/org/project/pull/1',
999 job1_params['zuul']['items'][0]['change_url'])
1000 self.assertEquals('https://github.com/org/project/pull/1',
1001 job2_params['zuul']['items'][0]['change_url'])
1002
938 1003
939class TestGithubUnprotectedBranches(ZuulTestCase): 1004class TestGithubUnprotectedBranches(ZuulTestCase):
940 config_file = 'zuul-github-driver.conf' 1005 config_file = 'zuul-github-driver.conf'
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 7eab222..84419d3 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -786,7 +786,12 @@ class GithubConnection(BaseConnection):
786 if event.change_number: 786 if event.change_number:
787 change = self._getChange(project, event.change_number, 787 change = self._getChange(project, event.change_number,
788 event.patch_number, refresh=refresh) 788 event.patch_number, refresh=refresh)
789 change.url = event.change_url 789 if hasattr(event, 'change_url') and event.change_url:
790 change.url = event.change_url
791 else:
792 # The event has no change url so just construct it
793 change.url = self.getPullUrl(
794 event.project_name, event.change_number)
790 change.uris = [ 795 change.uris = [
791 '%s/%s/pull/%s' % (self.server, project, change.number), 796 '%s/%s/pull/%s' % (self.server, project, change.number),
792 ] 797 ]