← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:fix-a-small-ui-thing into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:fix-a-small-ui-thing into launchpad:master.

Commit message:
Add git repository import status to Product code overview.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1923596 in Launchpad itself: "Product:+git doesn't clearly indicate when a git repository is an import"
  https://bugs.launchpad.net/launchpad/+bug/1923596

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/401474

Add whether the git repository for a product is imported from another repository.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:fix-a-small-ui-thing into launchpad:master.
diff --git a/lib/lp/code/browser/tests/test_codeimport.py b/lib/lp/code/browser/tests/test_codeimport.py
index a54a500..86cf64c 100644
--- a/lib/lp/code/browser/tests/test_codeimport.py
+++ b/lib/lp/code/browser/tests/test_codeimport.py
@@ -10,6 +10,7 @@ __metaclass__ = type
 import re
 
 from testtools.matchers import StartsWith
+from zope.component import getUtility
 from zope.security.interfaces import Unauthorized
 
 from lp.code.enums import (
@@ -17,7 +18,9 @@ from lp.code.enums import (
     RevisionControlSystems,
     TargetRevisionControlSystems,
     )
+from lp.code.interfaces.gitrepository import IGitRepositorySet
 from lp.code.tests.helpers import GitHostingFixture
+from lp.registry.enums import VCSType
 from lp.services.webapp import canonical_url
 from lp.testing import (
     admin_logged_in,
@@ -36,18 +39,19 @@ class TestImportDetails(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer
 
-    def assertImportDetailsDisplayed(self, code_import, details_id,
+    def assertImportDetailsDisplayed(self, context, details_id,
                                      prefix_text, span_title=None):
         """A code import has its details displayed properly.
 
-        :param code_import: An `ICodeImport`.
+        :param context: A context object (`ICodeImport` or `IProduct`).
         :param details_id: The HTML tag id to search for.
         :param prefix_text: An expected prefix of the details text.
         :param span_title: If present, the expected contents of a span title
             attribute.
         """
-        browser = self.getUserBrowser(canonical_url(code_import.target))
+        browser = self.getUserBrowser(canonical_url(context, rootsite='code'))
         details = find_tag_by_id(browser.contents, details_id)
+        self.assertIsNotNone(details)
         if span_title is not None:
             self.assertEqual(span_title, details.span['title'])
         text = re.sub(r'\s+', ' ', extract_text(details))
@@ -59,7 +63,7 @@ class TestImportDetails(TestCaseWithFactory):
         code_import = self.factory.makeCodeImport(
             rcs_type=RevisionControlSystems.BZR_SVN)
         self.assertImportDetailsDisplayed(
-            code_import, 'svn-import-details',
+            code_import.target, 'svn-import-details',
             'This branch is an import of the Subversion branch',
             span_title=RevisionControlSystems.BZR_SVN.title)
 
@@ -71,7 +75,23 @@ class TestImportDetails(TestCaseWithFactory):
             rcs_type=RevisionControlSystems.GIT,
             target_rcs_type=TargetRevisionControlSystems.GIT)
         self.assertImportDetailsDisplayed(
-            code_import, 'git-import-details',
+            code_import.target, 'git-import-details',
+            'This repository is an import of the Git repository')
+
+    def test_git_to_git_import_product(self):
+        # The index page for a product should state that a repository
+        # is imported.
+        self.useFixture(GitHostingFixture())
+        code_import = self.factory.makeCodeImport(
+            rcs_type=RevisionControlSystems.GIT,
+            target_rcs_type=TargetRevisionControlSystems.GIT)
+        product = code_import.target.target
+        with person_logged_in(product.owner):
+            product.vcs = VCSType.GIT
+            getUtility(IGitRepositorySet).setDefaultRepository(
+                target=product, repository=code_import.target)
+        self.assertImportDetailsDisplayed(
+            product, 'git-import-details',
             'This repository is an import of the Git repository')
 
     def test_other_users_are_forbidden_to_change_codeimport(self):
diff --git a/lib/lp/code/templates/gitlisting.pt b/lib/lp/code/templates/gitlisting.pt
index ed6c0eb..73109d8 100644
--- a/lib/lp/code/templates/gitlisting.pt
+++ b/lib/lp/code/templates/gitlisting.pt
@@ -84,6 +84,17 @@ git push --set-upstream origin master
         </p>
       </div>
 
+
+      <div id="repository-import-details"
+          class="yui-g"
+          tal:condition="repository/repository_type/enumvalue:IMPORTED">
+        <div class="portlet">
+          <h2>Import details</h2>
+          <tal:repository-import-details
+              replace="structure repository/@@++repository-import-details" />
+        </div>
+      </div>
+
       <div class="yui-g">
         <div id="default-repository-branches" class="portlet"
             tal:define="branches view/default_git_repository_branches">