summaryrefslogtreecommitdiff
path: root/lorrycontroller
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-06-08 19:08:44 +0000
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-06-08 19:08:44 +0000
commit47013c66f48f824de7870917fc74062060b42b43 (patch)
tree754d380bb2cf690d16a6a68a46da8862f64a898b /lorrycontroller
parent171a639eec9ad21456b114a83b5ef1e9087e357b (diff)
parentb8d097d9c8a45b9e862cad2f24a63282943b75a7 (diff)
downloadlorry-controller-47013c66f48f824de7870917fc74062060b42b43.tar.gz
Merge branch 'bwh/gerrit-config' into 'master'
Improve repo configuration on Gerrit downstream Closes #10, #8, #4, and #7 See merge request CodethinkLabs/lorry-controller!11
Diffstat (limited to 'lorrycontroller')
-rw-r--r--lorrycontroller/gerrit.py40
1 files changed, 28 insertions, 12 deletions
diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py
index 0970d63..629d00d 100644
--- a/lorrycontroller/gerrit.py
+++ b/lorrycontroller/gerrit.py
@@ -31,6 +31,14 @@ class GerritDownstream(hosts.DownstreamHost):
'''
+ @staticmethod
+ def add_app_settings(app_settings):
+ app_settings.string(
+ ['gerrit-parent-project'],
+ 'parent project for repositories on Gerrit',
+ default='All-Projects',
+ metavar='PROJECT')
+
def __init__(self, app_settings):
url = app_settings['downstream-ssh-url']
if url is None:
@@ -41,6 +49,8 @@ class GerritDownstream(hosts.DownstreamHost):
self._ssh_command = hosts.SshCommand(
url, StrictHostKeyChecking=key_check)
+ self._parent_project = app_settings['gerrit-parent-project']
+
def _has_project(self, name):
# There's no 'does this project exist' command in Gerrit 2.9.4; 'list
# all projects with this prefix' is as close we can get.
@@ -64,18 +74,24 @@ class GerritDownstream(hosts.DownstreamHost):
if self._has_project(name):
logging.info('Project %s exists in local Gerrit already.',
name)
- else:
- self._ssh_command.run(['gerrit', 'create-project', name])
- logging.info('Created %s project in local Gerrit.', name)
- # We can only set this metadata if we're the owner of the
- # repository. For now, ignore failures.
- try:
+ # We can only set this metadata if we're the owner of the
+ # repository. For now, ignore failures.
+ try:
+ if 'head' in metadata:
+ self._ssh_command.run(['gerrit', 'set-head', name,
+ '--new-head', metadata['head']])
+ if 'description' in metadata:
+ self._ssh_command.run(['gerrit', 'set-project', name,
+ '-d', metadata['description']])
+ except cliapp.AppException:
+ pass
+ else:
+ create_args = ['gerrit', 'create-project', name,
+ '-p', self._parent_project]
if 'head' in metadata:
- self._ssh_command.run(['gerrit', 'set-head', name,
- '--new-head', metadata['head']])
+ create_args.extend(['-b', metadata['head']])
if 'description' in metadata:
- self._ssh_command.run(['gerrit', 'set-project', name,
- '-d', metadata['description']])
- except cliapp.AppException:
- pass
+ create_args.extend(['-d', metadata['description']])
+ self._ssh_command.run(create_args)
+ logging.info('Created %s project in local Gerrit.', name)