← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:oci-project-of-project-git-namespace into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:oci-project-of-project-git-namespace into launchpad:master.

Commit message:
Adding support for GitNamespace of OCIProjects based on projects (not only distribution)

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395110
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:oci-project-of-project-git-namespace into launchpad:master.
diff --git a/lib/lp/code/model/gitlookup.py b/lib/lp/code/model/gitlookup.py
index a59134d..d4641ca 100644
--- a/lib/lp/code/model/gitlookup.py
+++ b/lib/lp/code/model/gitlookup.py
@@ -142,6 +142,19 @@ class ProjectGitTraversable(_BaseGitTraversable):
     From here, you can traverse to a named project repository.
     """
 
+    def traverse(self, owner, name, segments):
+        if name == "+oci":
+            try:
+                spn_name = next(segments)
+            except StopIteration:
+                raise InvalidNamespace("/".join(segments.traversed))
+            oci_project = self.context.getOCIProject(spn_name)
+            if oci_project is None:
+                raise NoSuchOCIProjectName(spn_name)
+            return owner, oci_project, None
+        return super(ProjectGitTraversable, self).traverse(
+            owner, name, segments)
+
     def getNamespace(self, owner):
         return getUtility(IGitNamespaceSet).get(owner, project=self.context)
 
diff --git a/lib/lp/code/model/tests/test_gitlookup.py b/lib/lp/code/model/tests/test_gitlookup.py
index d527b06..69f209b 100644
--- a/lib/lp/code/model/tests/test_gitlookup.py
+++ b/lib/lp/code/model/tests/test_gitlookup.py
@@ -1,4 +1,4 @@
-# Copyright 2015-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for the IGitLookup implementation."""
@@ -242,8 +242,8 @@ class TestGetByUrl(TestCaseWithFactory):
     def test_getByUrl_with_trailing_segments(self):
         # URLs with trailing segments beyond the repository are rejected.
         self.makeProjectRepository()
-        self.assertIsNone(
-            self.lookup.getByUrl("git://git.launchpad.test/~aa/bb/+git/cc/foo"))
+        self.assertIsNone(self.lookup.getByUrl(
+            "git://git.launchpad.test/~aa/bb/+git/cc/foo"))
 
     def test_getByUrl_with_git(self):
         # getByUrl recognises LP repositories for git URLs.
@@ -410,6 +410,16 @@ class TestGitTraverser(TestCaseWithFactory):
         path = "%s/+oci/%s" % (oci_project.pillar.name, oci_project.name)
         self.assertTraverses(path, None, oci_project)
 
+    def test_ociproject_based_on_project(self):
+        # `traverse_path` resolves '~person/product/+oci/ociproject' to the OCI
+        # project.
+        project = self.factory.makeProduct()
+        oci_project = self.factory.makeOCIProject(pillar=project)
+        path = "~%s/%s/+oci/%s" % (
+            oci_project.registrant.name, oci_project.pillar.name,
+            oci_project.name)
+        self.assertTraverses(path, oci_project.registrant, oci_project)
+
     def test_ociproject_no_named_repositories(self):
         # OCI projects do not have named repositories without an owner
         # context, so trying to traverse to them raises `InvalidNamespace`.

Follow ups