From 42f7d6f10084151d8aecb014effdde6eefa6ed8e Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Fri, 15 Dec 2017 16:09:43 +0100 Subject: Correctly use project name in getGitUrl The method getGitUrl is called via the project object and not string. While this doesn't matter when adding it to a string this breaks lookup of the installation key. Change-Id: I6632497af0b1e13f6e77b5b7b0a0ee105215a1f9 --- tests/unit/test_github_driver.py | 15 ++++++++++++--- zuul/driver/github/githubconnection.py | 12 ++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py index ebb5e1c85..6ab1a2650 100644 --- a/tests/unit/test_github_driver.py +++ b/tests/unit/test_github_driver.py @@ -243,19 +243,28 @@ class TestGithubDriver(ZuulTestCase): @simple_layout('layouts/basic-github.yaml', driver='github') def test_git_https_url(self): """Test that git_ssh option gives git url with ssh""" - url = self.fake_github.real_getGitUrl('org/project') + tenant = self.sched.abide.tenants.get('tenant-one') + _, project = tenant.getProject('org/project') + + url = self.fake_github.real_getGitUrl(project) self.assertEqual('https://github.com/org/project', url) @simple_layout('layouts/basic-github.yaml', driver='github') def test_git_ssh_url(self): """Test that git_ssh option gives git url with ssh""" - url = self.fake_github_ssh.real_getGitUrl('org/project') + tenant = self.sched.abide.tenants.get('tenant-one') + _, project = tenant.getProject('org/project') + + url = self.fake_github_ssh.real_getGitUrl(project) self.assertEqual('ssh://git@github.com/org/project.git', url) @simple_layout('layouts/basic-github.yaml', driver='github') def test_git_enterprise_url(self): """Test that git_url option gives git url with proper host""" - url = self.fake_github_ent.real_getGitUrl('org/project') + tenant = self.sched.abide.tenants.get('tenant-one') + _, project = tenant.getProject('org/project') + + url = self.fake_github_ent.real_getGitUrl(project) self.assertEqual('ssh://git@github.enterprise.io/org/project.git', url) @simple_layout('layouts/reporting-github.yaml', driver='github') diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py index f987f4712..0c8ac2ebb 100644 --- a/zuul/driver/github/githubconnection.py +++ b/zuul/driver/github/githubconnection.py @@ -34,7 +34,7 @@ import github3 import github3.exceptions from zuul.connection import BaseConnection -from zuul.model import Ref, Branch, Tag +from zuul.model import Ref, Branch, Tag, Project from zuul.exceptions import MergeFailure from zuul.driver.github.githubmodel import PullRequest, GithubTriggerEvent @@ -786,17 +786,17 @@ class GithubConnection(BaseConnection): return change - def getGitUrl(self, project): + def getGitUrl(self, project: Project): if self.git_ssh_key: - return 'ssh://git@%s/%s.git' % (self.server, project) + return 'ssh://git@%s/%s.git' % (self.server, project.name) if self.app_id: - installation_key = self._get_installation_key(project) + installation_key = self._get_installation_key(project.name) return 'https://x-access-token:%s@%s/%s' % (installation_key, self.server, - project) + project.name) - return 'https://%s/%s' % (self.server, project) + return 'https://%s/%s' % (self.server, project.name) def getGitwebUrl(self, project, sha=None): url = 'https://%s/%s' % (self.server, project) -- cgit v1.2.1