From 51b7492e95bce924efdbafbac996d746a6b9cb18 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 4 Oct 2016 14:19:57 -0700 Subject: [PATCH] Add getProjectBranches to Source This lets us ask a source for all of the branches for a project. This uses the git protocol for now, but this can get much nicer in the future if we switch to using Gerrit's REST API. It should also be easy to do with github. The included comment indicates why it's being added -- implementation to follow in subsequent changes. Change-Id: I0dfcd61f343a235dcf935aea434b9772d6e746d9 --- zuul/configloader.py | 6 +++++- zuul/connection/gerrit.py | 6 ++++++ zuul/source/__init__.py | 4 ++++ zuul/source/gerrit.py | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/zuul/configloader.py b/zuul/configloader.py index b41dcc17ac..063889b5f2 100644 --- a/zuul/configloader.py +++ b/zuul/configloader.py @@ -550,7 +550,11 @@ class TenantParser(object): # Get in-project-repo config files which have a restricted # set of options. url = source.getGitUrl(project) - # TODOv3(jeblair): config should be branch specific + # TODOv3(jeblair): config should be branch specific. For + # each branch in the repo, get the zuul.yaml for that + # branch. Remember the branch and then implicitly add a + # branch selector to each job there. + source.getProjectBranches(project) job = merger.getFiles(project.name, url, 'master', files=['.zuul.yaml']) job.project = project diff --git a/zuul/connection/gerrit.py b/zuul/connection/gerrit.py index bf77bff219..5edc9a5ef8 100644 --- a/zuul/connection/gerrit.py +++ b/zuul/connection/gerrit.py @@ -572,6 +572,12 @@ class GerritConnection(BaseConnection): (record.get('number'),)) return changes + def getProjectBranches(self, project): + refs = self.getInfoRefs(project) + heads = [str(k[len('refs/heads/'):]) for k in refs.keys() + if k.startswith('refs/heads/')] + return heads + def addEvent(self, data): return self.event_queue.put((time.time(), data)) diff --git a/zuul/source/__init__.py b/zuul/source/__init__.py index d92d47af99..69dc162553 100644 --- a/zuul/source/__init__.py +++ b/zuul/source/__init__.py @@ -63,3 +63,7 @@ class BaseSource(object): @abc.abstractmethod def getProject(self, name): """Get a project.""" + + @abc.abstractmethod + def getProjectBranches(self, project): + """Get branches for a project""" diff --git a/zuul/source/gerrit.py b/zuul/source/gerrit.py index 0d28898d3e..8b85a46762 100644 --- a/zuul/source/gerrit.py +++ b/zuul/source/gerrit.py @@ -41,6 +41,9 @@ class GerritSource(BaseSource): def getProjectOpenChanges(self, project): return self.connection.getProjectOpenChanges(project) + def getProjectBranches(self, project): + return self.connection.getProjectBranches(project) + def getGitUrl(self, project): return self.connection.getGitUrl(project)