diff options
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 {} |