summaryrefslogtreecommitdiff
path: root/lorrycontroller/gitlab.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/gitlab.py')
-rw-r--r--lorrycontroller/gitlab.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/lorrycontroller/gitlab.py b/lorrycontroller/gitlab.py
index ab6df63..4f70f0a 100644
--- a/lorrycontroller/gitlab.py
+++ b/lorrycontroller/gitlab.py
@@ -66,19 +66,22 @@ class GitlabDownstream(hosts.DownstreamHost):
self.gl = _init_gitlab(host, app_settings['gitlab-private-token'])
- def _has_project(self, repo_path):
- try:
- self.gl.projects.get(repo_path)
- return True
- except gitlab.GitlabGetError:
- return False
-
def prepare_repo(self, repo_path, metadata):
- # TODO: set metadata
- if self._has_project(repo_path):
+ try:
+ project = self.gl.projects.get(repo_path)
+ except gitlab.GitlabGetError:
+ pass
+ else:
logging.info('Project %s exists in local GitLab already.',
repo_path)
+ if 'head' in metadata \
+ and project.default_branch != metadata['head']:
+ project.default_branch = metadata['head']
+ if 'description' in metadata \
+ and project.description != metadata['description']:
+ project.description = metadata['description']
+ project.save()
return
path_comps = repo_path.split('/')
@@ -109,6 +112,8 @@ class GitlabDownstream(hosts.DownstreamHost):
'public': True,
'merge_requests_enabled': False,
'namespace_id': group.id,
+ 'default_branch': metadata.get('head'),
+ 'description': metadata.get('description'),
}
self.gl.projects.create(project)
@@ -157,5 +162,10 @@ class GitlabUpstream(hosts.UpstreamHost):
self._protocol, split.netloc, split.path, '', ''))
def get_repo_metadata(self, repo_path):
- # TODO
- return {}
+ project = self.gl.projects.get(repo_path)
+ metadata = {}
+ if project.default_branch is not None:
+ metadata['head'] = project.default_branch
+ if project.description is not None:
+ metadata['description'] = project.description
+ return metadata