launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #19321
[Merge] lp:~wgrant/launchpad/gitcrumbs into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/gitcrumbs into lp:launchpad.
Commit message:
Give Git repositories and refs more sensible breadcrumbs.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1466271 in Launchpad itself: "Git repositories don't have breadcrumbs"
https://bugs.launchpad.net/launchpad/+bug/1466271
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/gitcrumbs/+merge/270660
Give Git repositories and refs more sensible breadcrumbs:
Git >> lp:~wgrant/launchpad >> master
I considered allowing navigation to PersonProduct via something like:
Git >> William Grant >> launchpad >> master
... but that makes things longer for default repositories.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/gitcrumbs into lp:launchpad.
=== modified file 'lib/lp/code/browser/configure.zcml'
--- lib/lp/code/browser/configure.zcml 2015-06-25 04:42:48 +0000
+++ lib/lp/code/browser/configure.zcml 2015-09-10 11:49:18 +0000
@@ -904,6 +904,11 @@
<browser:menus
classes="GitRefContextMenu"
module="lp.code.browser.gitref"/>
+ <adapter
+ provides="lp.services.webapp.interfaces.IBreadcrumb"
+ for="lp.code.interfaces.gitref.IGitRef"
+ factory="lp.services.webapp.breadcrumb.NameBreadcrumb"
+ permission="zope.Public"/>
<browser:defaultView
for="lp.code.interfaces.gitsubscription.IGitSubscription"
=== modified file 'lib/lp/code/browser/gitrepository.py'
--- lib/lp/code/browser/gitrepository.py 2015-08-04 10:28:21 +0000
+++ lib/lp/code/browser/gitrepository.py 2015-09-10 11:49:18 +0000
@@ -7,6 +7,7 @@
__all__ = [
'GitRefBatchNavigator',
+ 'GitRepositoriesBreadcrumb',
'GitRepositoryBreadcrumb',
'GitRepositoryContextMenu',
'GitRepositoryDeletionView',
@@ -86,7 +87,7 @@
precache_permission_for_objects,
)
from lp.services.webapp.batching import TableBatchNavigator
-from lp.services.webapp.breadcrumb import NameBreadcrumb
+from lp.services.webapp.breadcrumb import Breadcrumb
from lp.services.webapp.escaping import structured
from lp.services.webapp.interfaces import ICanonicalUrlData
from lp.services.webhooks.browser import WebhookTargetNavigationMixin
@@ -107,11 +108,28 @@
return self.repository.unique_name
-class GitRepositoryBreadcrumb(NameBreadcrumb):
-
- @property
- def inside(self):
- return self.context.target
+class GitRepositoriesBreadcrumb(Breadcrumb):
+
+ text = "Git"
+
+ @property
+ def url(self):
+ return canonical_url(self.context, view_name="+git")
+
+ @property
+ def inside(self):
+ return self.context
+
+
+class GitRepositoryBreadcrumb(Breadcrumb):
+
+ @property
+ def text(self):
+ return self.context.git_identity
+
+ @property
+ def inside(self):
+ return GitRepositoriesBreadcrumb(self.context.target)
class GitRepositoryNavigation(WebhookTargetNavigationMixin, Navigation):
=== added file 'lib/lp/code/browser/tests/test_gitref.py'
--- lib/lp/code/browser/tests/test_gitref.py 1970-01-01 00:00:00 +0000
+++ lib/lp/code/browser/tests/test_gitref.py 2015-09-10 11:49:18 +0000
@@ -0,0 +1,58 @@
+# Copyright 2015 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Unit tests for GitRefView."""
+
+__metaclass__ = type
+
+import re
+
+import soupmatchers
+from zope.component import getUtility
+
+from lp.code.interfaces.gitrepository import IGitRepositorySet
+from lp.testing import TestCaseWithFactory
+from lp.testing.layers import DatabaseFunctionalLayer
+from lp.testing.views import create_view
+
+
+class GitRefView(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_rendering(self):
+ repository = self.factory.makeGitRepository(
+ owner=self.factory.makePerson(name="person"),
+ target=self.factory.makeProduct(name="target"),
+ name=u"git")
+ getUtility(IGitRepositorySet).setDefaultRepositoryForOwner(
+ repository.owner, repository.target, repository, repository.owner)
+ [ref] = self.factory.makeGitRefs(
+ repository=repository, paths=[u"refs/heads/master"])
+ view = create_view(ref, "+index")
+ # To test the breadcrumbs we need a correct traversal stack.
+ view.request.traversed_objects = [repository, ref, view]
+ view.initialize()
+ breadcrumbs_tag = soupmatchers.Tag(
+ 'breadcrumbs', 'ol', attrs={'class': 'breadcrumbs'})
+ self.assertThat(
+ view(),
+ soupmatchers.HTMLContains(
+ soupmatchers.Within(
+ breadcrumbs_tag,
+ soupmatchers.Tag(
+ 'git collection breadcrumb', 'a',
+ text='Git',
+ attrs={'href': re.compile(r'/\+git$')})),
+ soupmatchers.Within(
+ breadcrumbs_tag,
+ soupmatchers.Tag(
+ 'repository breadcrumb', 'a',
+ text='lp:~person/target',
+ attrs={'href': re.compile(
+ r'/~person/target/\+git/git')})),
+ soupmatchers.Within(
+ breadcrumbs_tag,
+ soupmatchers.Tag(
+ 'git ref breadcrumb', 'li',
+ text=re.compile(r'\smaster\s')))))
Follow ups