summaryrefslogtreecommitdiff
path: root/lorrycontroller/gerrit.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/gerrit.py')
-rw-r--r--lorrycontroller/gerrit.py62
1 files changed, 36 insertions, 26 deletions
diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py
index c5498e2..c2c81b8 100644
--- a/lorrycontroller/gerrit.py
+++ b/lorrycontroller/gerrit.py
@@ -31,32 +31,36 @@ 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')
+
+ @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):
- # XXX These need to be configurable
- host = 'localhost'
- port = 29418
- user = 'lorry'
-
- self._ssh_command_args = [
- 'ssh', '-oStrictHostKeyChecking=no', '-oBatchMode=yes', '-p%i' % port,
- '%s@%s' % (user, host)]
+ url = app_settings['downstream-ssh-url']
+ if url is None:
+ url = 'ssh://lorry@localhost:29418'
+ key_check = 'no'
+ else:
+ key_check = 'yes'
+ self._ssh_command = hosts.SshCommand(
+ url, StrictHostKeyChecking=key_check)
- def _ssh_command(self, command):
- out = cliapp.runcmd(self._ssh_command_args + command)
- if isinstance(out, bytes):
- out = out.decode('utf-8', errors='replace')
- return out
+ 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.
- output = self._ssh_command([
+ output = self._ssh_command.run([
'gerrit', 'ls-projects', '--type=ALL', '--prefix=%s' % name])
projects = output.strip().split('\n')
@@ -75,18 +79,24 @@ class GerritDownstream(hosts.DownstreamHost):
if self._has_project(name):
logging.info('Project %s exists in local Gerrit already.',
name)
- else:
- self._ssh_command(['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(['gerrit', 'set-head', name,
- '--new-head', metadata['head']])
+ create_args.extend(['-b', metadata['head']])
if 'description' in metadata:
- self._ssh_command(['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)