seveas / git-spindle

Abandoned command-line interface to GitHub and other central git services
Other
172 stars 35 forks source link

Support nested namespaces (GitLab) #164

Closed kadrach closed 2 years ago

kadrach commented 7 years ago

GitLab not too long ago introduced nested namespaces, called subgroups on Gitlab.

git config --get-regexp "remote\..*\.url"                                                                                                                          
remote.origin.url git@gitlab.local:dept/team/project/component.git

Something like the snippet below works for my usecase, but I've simply removed the sanity check.

diff --git lib/gitspindle/gitlab.py lib/gitspindle/gitlab.py
index de1f3ad..cbc05b9 100644
--- lib/gitspindle/gitlab.py
+++ lib/gitspindle/gitlab.py
@@ -71,7 +71,15 @@ class GitLab(GitSpindle):
         self.my_login = self.me.username

     def parse_url(self, url):
-        return ([self.my_login] + url.path.split('/'))[-2:]
+        path = url.path.lstrip('/').split('/')
+
+        if len(path) > 1:
+            owner = path[0]
+            namespace = '/'.join(path[1:])
+        else:
+            owner = self.my_login
+            namespace = path[0]
+        return [owner, namespace]

     def get_repo(self, remote, user, repo):
         if remote:
@@ -79,7 +87,7 @@ class GitLab(GitSpindle):
             if id and id.isdigit():
                 return self.gl.Project(id)

-        repo_ = self.find_repo(user=user, name=repo)
+        repo_ = self.find_repo(user=user, name=repo.replace('/','%2F'))
         if not repo_:
             # Name and path don't always match, and we clone using the name
             repo_ = self.find_repo(user, name=os.path.basename(os.getcwd()))
@@ -104,8 +112,10 @@ class GitLab(GitSpindle):
         try:
             project = self.gl.Project('%s%%2F%s' % (user, name))
             # Yes, we need to check the name. Requesting foo.broken returns the foo project.
-            if project.path != name:
-                return None
+            #  print(project.path)
+            #  print(name)
+            #  if project.path != name:
+            #      return None
             return project
         except glapi.GitlabGetError:
             pass
seveas commented 7 years ago

Hmm. How does that combine with having the root of gitlab at gitlab.example.com/gitlab/ ? Or does gitlab not support having its root in a subdirectory?

kadrach commented 7 years ago

Only tested for my own usecase :)

I agree, this would need to be addressed. Not sure what's the best way there.

Gitlab supports relative context paths (whatever these are called), see https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-a-relative-url-for-gitlab

CircleCode commented 6 years ago

Hmm. How does that combine with having the root of gitlab at gitlab.example.com/gitlab/

maybe I am a bit naive, but I don't get the problem with gitlab being in a given path from the host:

you can substract the gitlab path from the url path, isn't it?

seveas commented 6 years ago

Except that the code as posted does not do this :smile:

I don't object to this feature, but the implementation above is not good enough. If you implement it the way you describe, it should be good to go.