← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:ociproject-git-instructions into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:ociproject-git-instructions into launchpad:master with ~pappacena/launchpad:oci-project-of-project-git-namespace as a prerequisite.

Commit message:
Adding help message for OCIProject's git repository

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395174
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:ociproject-git-instructions into launchpad:master.
diff --git a/lib/lp/registry/browser/configure.zcml b/lib/lp/registry/browser/configure.zcml
index 7c97dc5..cdaa3da 100644
--- a/lib/lp/registry/browser/configure.zcml
+++ b/lib/lp/registry/browser/configure.zcml
@@ -620,7 +620,7 @@
     <browser:page
         name="+index"
         for="lp.registry.interfaces.ociproject.IOCIProject"
-        class="lp.services.webapp.LaunchpadView"
+        class="lp.registry.browser.ociproject.OCIProjectIndexView"
         permission="launchpad.View"
         template="../templates/ociproject-index.pt"
         />
diff --git a/lib/lp/registry/browser/ociproject.py b/lib/lp/registry/browser/ociproject.py
index fe5f8b4..c93426b 100644
--- a/lib/lp/registry/browser/ociproject.py
+++ b/lib/lp/registry/browser/ociproject.py
@@ -28,6 +28,7 @@ from lp.app.browser.launchpadform import (
 from lp.app.browser.tales import CustomizableFormatter
 from lp.app.errors import NotFoundError
 from lp.code.browser.vcslisting import TargetDefaultVCSNavigationMixin
+from lp.code.interfaces.gitnamespace import IGitNamespaceSet
 from lp.oci.interfaces.ocirecipe import IOCIRecipeSet
 from lp.registry.enums import DistributionDefaultTraversalPolicy
 from lp.registry.interfaces.distribution import IDistribution
@@ -212,6 +213,21 @@ class OCIProjectContextMenu(ContextMenu):
             '+recipes', 'View OCI recipes', icon='info', enabled=enabled)
 
 
+class OCIProjectIndexView(LaunchpadView):
+    @property
+    def git_repository(self):
+        namespace = getUtility(IGitNamespaceSet).get(
+            self.context.registrant, oci_project=self.context)
+        return namespace.getByName(self.context.name)
+
+    @property
+    def git_repository_path(self):
+        """The default git repository path, regardless if it exists or not."""
+        namespace = getUtility(IGitNamespaceSet).get(
+            self.context.registrant, oci_project=self.context)
+        return namespace.name
+
+
 class OCIProjectEditView(LaunchpadEditFormView):
     """Edit an OCI project."""
 
diff --git a/lib/lp/registry/browser/tests/test_ociproject.py b/lib/lp/registry/browser/tests/test_ociproject.py
index 9fb5822..ca8758e 100644
--- a/lib/lp/registry/browser/tests/test_ociproject.py
+++ b/lib/lp/registry/browser/tests/test_ociproject.py
@@ -107,6 +107,44 @@ class TestOCIProjectView(BrowserTestCase):
             Name: oci-name
             """, self.getMainText(oci_project))
 
+    def test_git_repo_hint(self):
+        owner = self.factory.makePerson(name="a-usr")
+        pillar = self.factory.makeProduct(name="a-pillar")
+        oci_project = self.factory.makeOCIProject(
+            pillar=pillar, registrant=owner, ociprojectname="oci-name")
+        self.assertTextMatchesExpressionIgnoreWhitespace("""\
+            OCI project oci-name for A-pillar
+            .*
+            You can create a git repositories for this OCI project in order
+            to build your OCI recipes by using the following commands:
+            git remote add origin
+            git\+ssh://a-usr@xxxxxxxxxxxxxxxxx/~a-usr/a-pillar/\+oci/oci-name
+            git push --set-upstream origin master
+
+            OCI project information
+            Project: A-pillar
+            Name: oci-name
+            """, self.getMainText(oci_project))
+
+    def test_shows_existing_git_repo(self):
+        owner = self.factory.makePerson(name="a-usr")
+        pillar = self.factory.makeProduct(name="a-pillar")
+        oci_project = self.factory.makeOCIProject(
+            pillar=pillar, registrant=owner, ociprojectname="oci-name")
+        self.factory.makeGitRepository(
+            name=oci_project.name,
+            target=oci_project, owner=owner, registrant=owner)
+        self.assertTextMatchesExpressionIgnoreWhitespace("""\
+            OCI project oci-name for A-pillar
+            .*
+            The default git repository for this project is
+            lp:~a-usr/a-pillar/\+oci/oci-name/\+git/oci-name.
+
+            OCI project information
+            Project: A-pillar
+            Name: oci-name
+            """, self.getMainText(oci_project))
+
 
 class TestOCIProjectEditView(BrowserTestCase):
 
diff --git a/lib/lp/registry/templates/ociproject-index.pt b/lib/lp/registry/templates/ociproject-index.pt
index 9a14cb7..c814ce1 100644
--- a/lib/lp/registry/templates/ociproject-index.pt
+++ b/lib/lp/registry/templates/ociproject-index.pt
@@ -26,6 +26,24 @@
   </metal:heading>
 
   <div metal:fill-slot="main">
+    <div tal:condition="python: view.git_repository is None">
+      <p>
+        You can create a git repositories for this OCI project in order to
+        build your OCI recipes by using the following commands:
+        <br />
+        <pre class="command">
+          git remote add origin git+ssh://<tal:name replace="context/registrant/name"/>@git.launchpad.net/<tal:name replace="view/git_repository_path"/>
+          git push --set-upstream origin master
+        </pre>
+      </p>
+    </div>
+    <div tal:define="repo view/git_repository"
+         tal:condition="repo">
+      The default git repository for this project is
+      <a tal:content="repo/display_name"
+         tal:attributes="href repo/fmt:url">lp:foo</a>.
+    </div>
+
     <h2>OCI project information</h2>
     <div class="two-column-list">
       <dl id="pillar" tal:define="pillar context/pillar">

Follow ups