summaryrefslogtreecommitdiff
path: root/lorrycontroller/gitlab.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/gitlab.py')
-rw-r--r--lorrycontroller/gitlab.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/lorrycontroller/gitlab.py b/lorrycontroller/gitlab.py
index 5c7e579..659d179 100644
--- a/lorrycontroller/gitlab.py
+++ b/lorrycontroller/gitlab.py
@@ -14,6 +14,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from __future__ import absolute_import
+import urlparse
import itertools
try:
import gitlab
@@ -82,3 +83,28 @@ class Gitlab(object):
}
self.gl.projects.create(project)
+ def list_projects(self):
+ return [x.path_with_namespace for x in self.gl.projects.list()]
+
+ def get_project_url(self, protocol, project_path):
+ '''Return the clone url for a GitLab project.
+
+ Depending on the protocol specified, will return a suitable clone url.
+ If 'ssh', a url in the format 'git@host:group/project.git' will be
+ returned.
+ If 'http' or 'https', the http_url_to_repo from the GitLab API is split
+ with urlparse into its constituent parts: the protocol (http by
+ default), the host, and the path ('group/project.git'). This is then
+ rejoined, replacing the protocol with what is specified. The resulting
+ format matching 'http(s)://host/group/project.git'.
+ '''
+
+ group, project = self.split_path(project_path)
+ project = self.find_project(group, project)
+
+ if protocol == 'ssh':
+ return project.ssh_url_to_repo
+ elif protocol in ('http', 'https'):
+ split = urlparse.urlsplit(project.http_url_to_repo)
+ return urlparse.urlunsplit((
+ protocol, split.netloc, split.path, '', ''))