diff options
author | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-05-13 18:25:35 +0100 |
---|---|---|
committer | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-06-01 15:31:19 +0100 |
commit | ddc2e9c97ddafed9e34aa9f4de2fdf9ffef20bcf (patch) | |
tree | cf719132b7917e60630396bfe7926f93e380cd31 /lorrycontroller/gitlab.py | |
parent | 4cce11af4ca0491b3da92321ddc44169909a6c26 (diff) | |
download | lorry-controller-ddc2e9c97ddafed9e34aa9f4de2fdf9ffef20bcf.tar.gz |
Move Upstream Host type-specific code into modules
* Introduce UpnstreamHost abstract base class
* Define a subclass of this for each Upstream Host type
* Define a name-type map for these in the lorrycontroller package,
* Use these classes to replace type-specific code elsewhere
Related to #5.
Diffstat (limited to 'lorrycontroller/gitlab.py')
-rw-r--r-- | lorrycontroller/gitlab.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lorrycontroller/gitlab.py b/lorrycontroller/gitlab.py index 90ba192..ab6df63 100644 --- a/lorrycontroller/gitlab.py +++ b/lorrycontroller/gitlab.py @@ -115,16 +115,26 @@ class GitlabDownstream(hosts.DownstreamHost): logging.info('Created %s project in local GitLab.', repo_path) -class Gitlab(object): - def __init__(self, host, token): - self.gl = _init_gitlab(host, token) +class GitlabUpstream(hosts.UpstreamHost): + @staticmethod + def check_host_type_params(validator, section): + validator.check_has_required_fields(section, ['private-token']) + + @staticmethod + def get_host_type_params(section): + return {'private-token': section['private-token']} - def list_projects(self): + def __init__(self, host_info): + self._protocol = host_info['protocol'] + self.gl = _init_gitlab(host_info['host'], + host_info['type_params']['private-token']) + + def list_repos(self): '''List projects on a GitLab instance.''' return [x.path_with_namespace for x in self.gl.projects.list()] - def get_project_url(self, protocol, project_path): + def get_repo_url(self, repo_path): '''Return the clone url for a GitLab project. Depending on the protocol specified, will return a suitable clone url. @@ -139,9 +149,13 @@ class Gitlab(object): project = self.gl.projects.get(repo_path) - if protocol == 'ssh': + if self._protocol == 'ssh': return project.ssh_url_to_repo - elif protocol in ('http', 'https'): + elif self._protocol in ('http', 'https'): split = urllib.parse.urlsplit(project.http_url_to_repo) return urllib.parse.urlunsplit(( - protocol, split.netloc, split.path, '', '')) + self._protocol, split.netloc, split.path, '', '')) + + def get_repo_metadata(self, repo_path): + # TODO + return {} |