From 1a883937e3422601d52ecf29d074dd18897279ed Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Thu, 21 Dec 2017 09:29:09 +0100 Subject: [PATCH] Reprime the installation map in getGitUrl if needed The getGitUrl is also used by the mergers and executors. In order to work with github apps they need to know the mapping of projects to installation ids. However as they don't receive webhook events they currently only create this mapping on startup. Thus we need to refresh the installation map if the project is not found. Change-Id: I4e0f4473e0402ea0d619b83e56eb2a3f4fbe6698 --- zuul/driver/github/githubconnection.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py index cb2de209c8..e9a1d2f54a 100644 --- a/zuul/driver/github/githubconnection.py +++ b/zuul/driver/github/githubconnection.py @@ -535,12 +535,21 @@ class GithubConnection(BaseConnection): return headers - def _get_installation_key(self, project, user_id=None, inst_id=None): + def _get_installation_key(self, project, user_id=None, inst_id=None, + reprime=False): installation_id = inst_id if project is not None: installation_id = self.installation_map.get(project) if not installation_id: + if reprime: + # prime installation map and try again without refreshing + self._prime_installation_map() + return self._get_installation_key(project, + user_id=user_id, + inst_id=inst_id, + reprime=False) + self.log.error("No installation ID available for project %s", project) return '' @@ -809,7 +818,12 @@ class GithubConnection(BaseConnection): self._prime_installation_map() if self.app_id: - installation_key = self._get_installation_key(project.name) + # We may be in the context of a merger or executor here. The + # mergers and executors don't receive webhook events so they miss + # new repository installations. In order to cope with this we need + # to reprime the installation map if we don't find the repo there. + installation_key = self._get_installation_key(project.name, + reprime=True) return 'https://x-access-token:%s@%s/%s' % (installation_key, self.server, project.name)