Files
zuul/zuul/driver/git/gitconnection.py
T
Tobias Henkel eca4620efa Optionally limit github to protected branches
When using a branch and pull model on a shared repository there are
usually one or more protected branches which are gated and a dynamic
number of temporary personal/feature branches which are the source for
the pull requests. These temporary branches while ungated can
potentially include broken zuul config and therefore break the global
tenant wide configuration.

In order to deal with this model add support for excluding unprotected
branches. This can be configured on tenant level and overridden per
project.

Change-Id: I8a45fd41539a3c964a84142f04c1644585c0fdcf
2017-08-03 11:50:26 +02:00

64 lines
2.1 KiB
Python

# Copyright 2011 OpenStack, LLC.
# Copyright 2012 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import urllib
import voluptuous as v
from zuul.connection import BaseConnection
class GitConnection(BaseConnection):
driver_name = 'git'
log = logging.getLogger("connection.git")
def __init__(self, driver, connection_name, connection_config):
super(GitConnection, self).__init__(driver, connection_name,
connection_config)
if 'baseurl' not in self.connection_config:
raise Exception('baseurl is required for git connections in '
'%s' % self.connection_name)
self.baseurl = self.connection_config.get('baseurl')
self.canonical_hostname = self.connection_config.get(
'canonical_hostname')
if not self.canonical_hostname:
r = urllib.parse.urlparse(self.baseurl)
if r.hostname:
self.canonical_hostname = r.hostname
else:
self.canonical_hostname = 'localhost'
self.projects = {}
def getProject(self, name):
return self.projects.get(name)
def addProject(self, project):
self.projects[project.name] = project
def getProjectBranches(self, project, tenant):
# TODO(jeblair): implement; this will need to handle local or
# remote git urls.
raise NotImplemented()
def getGitUrl(self, project):
url = '%s/%s' % (self.baseurl, project.name)
return url
def getSchema():
git_connection = v.Any(str, v.Schema(dict))
return git_connection