diff options
author | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-06-08 19:17:36 +0000 |
---|---|---|
committer | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-06-08 19:17:36 +0000 |
commit | 54d0672b8cfe7bc1273ce1631f3dc7c730198a45 (patch) | |
tree | 6c2cb0a0409a22c439203343e3682ede05548d28 | |
parent | 47013c66f48f824de7870917fc74062060b42b43 (diff) | |
parent | c93ddc0f4c82695c9f1d2e0ca4212a2308864cba (diff) | |
download | lorry-controller-54d0672b8cfe7bc1273ce1631f3dc7c730198a45.tar.gz |
Merge branch 'bwh/gitlab-config' into 'master'
Improve repo/group configuration on GitLab downstream
Closes #6
See merge request CodethinkLabs/lorry-controller!10
-rwxr-xr-x | lorry-controller-webapp | 5 | ||||
-rw-r--r-- | lorrycontroller/gerrit.py | 7 | ||||
-rw-r--r-- | lorrycontroller/gitano.py | 6 | ||||
-rw-r--r-- | lorrycontroller/gitlab.py | 36 |
4 files changed, 44 insertions, 10 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp index e60f00c..1cb7e16 100755 --- a/lorry-controller-webapp +++ b/lorry-controller-webapp @@ -153,6 +153,11 @@ class WEBAPP(cliapp.Application): 'URL for Downstream Host HTTP(S) service (GitLab)', metavar='URL') + self.settings.choice( + ['downstream-visibility'], + ['private', 'internal', 'public'], + 'Visibility of repositories created on Downstream Host (GitLab)') + for downstream_type in lorrycontroller.downstream_types.values(): downstream_type.add_app_settings(self.settings) diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py index 629d00d..c2c81b8 100644 --- a/lorrycontroller/gerrit.py +++ b/lorrycontroller/gerrit.py @@ -21,7 +21,6 @@ from . import hosts class GerritDownstream(hosts.DownstreamHost): - '''Run commands on a Gerrit instance. This uses the SSH API to Gerrit. The REST API is actually much nicer to @@ -39,6 +38,12 @@ class GerritDownstream(hosts.DownstreamHost): default='All-Projects', metavar='PROJECT') + @staticmethod + def check_app_settings(app_settings): + if app_settings['downstream-visibility'] != 'private': + raise cliapp.ApplicationError( + 'Cannot create non-private repositories in Gerrit') + def __init__(self, app_settings): url = app_settings['downstream-ssh-url'] if url is None: diff --git a/lorrycontroller/gitano.py b/lorrycontroller/gitano.py index 499bb5d..87e2182 100644 --- a/lorrycontroller/gitano.py +++ b/lorrycontroller/gitano.py @@ -144,6 +144,12 @@ class _LocalTroveGitanoCommand(_GitanoCommand): class GitanoDownstream(hosts.DownstreamHost): + @staticmethod + def check_app_settings(app_settings): + if app_settings['downstream-visibility'] != 'private': + raise cliapp.ApplicationError( + 'Cannot create non-private repositories in Gitano') + def __init__(self, app_settings): self._gitano = _LocalTroveGitanoCommand() diff --git a/lorrycontroller/gitlab.py b/lorrycontroller/gitlab.py index e77e4bb..4fdbab2 100644 --- a/lorrycontroller/gitlab.py +++ b/lorrycontroller/gitlab.py @@ -65,6 +65,8 @@ class GitlabDownstream(hosts.DownstreamHost): url = 'http://localhost/' self.gl = _init_gitlab(url, app_settings['gitlab-private-token']) + self._visibility = app_settings['downstream-visibility'] + def prepare_repo(self, repo_path, metadata): try: @@ -100,21 +102,37 @@ class GitlabDownstream(hosts.DownstreamHost): except gitlab.GitlabGetError as e: if e.response_code != 404: raise - data = {'name': group_name, 'path': group_name} + data = { + 'name': group_name, + 'path': group_name, + 'visibility': self._visibility, + } if parent_group is not None: data['parent_id'] = parent_group.id group = self.gl.groups.create(data) parent_group = group - project = { - 'name': path_comps[-1], - 'public': True, - 'merge_requests_enabled': False, - 'namespace_id': group.id, - 'default_branch': metadata.get('head'), - 'description': metadata.get('description'), + proj_create = { + 'name': path_comps[-1], + 'visibility': self._visibility, + 'namespace_id': group.id, + 'default_branch': metadata.get('head'), + 'description': metadata.get('description'), + 'pages_access_level': 'disabled', + 'container_registry_enabled': False, + 'autoclose_referenced_issues': False, + 'lfs_enabled': False, + 'auto_devops_enabled': False, } - self.gl.projects.create(project) + project = self.gl.projects.create(proj_create) + + # Disabling these during creation doesn't work (as of GitLab + # 12.10.1) so do it immediately after + for attr_name in ['issues_access_level', 'merge_requests_access_level', + 'builds_access_level', 'wiki_access_level', + 'snippets_access_level']: + setattr(project, attr_name, 'disabled') + project.save() logging.info('Created %s project in local GitLab.', repo_path) |