Merge lp:~cjwatson/launchpad/snap-show-source into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17702
Proposed branch: lp:~cjwatson/launchpad/snap-show-source
Merge into: lp:launchpad
Diff against target: 110 lines (+51/-16)
3 files modified
lib/lp/snappy/browser/snap.py (+10/-0)
lib/lp/snappy/browser/tests/test_snap.py (+37/-16)
lib/lp/snappy/templates/snap-index.pt (+4/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-show-source
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+269404@code.launchpad.net

Commit message

Show the source (Bazaar or Git branch) on Snap:+index.

Description of the change

Show the source (Bazaar or Git branch) on Snap:+index.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/snappy/browser/snap.py'
2--- lib/lp/snappy/browser/snap.py 2015-08-09 22:49:05 +0000
3+++ lib/lp/snappy/browser/snap.py 2015-08-27 16:11:59 +0000
4@@ -53,6 +53,16 @@
5 def builds(self):
6 return builds_for_snap(self.context)
7
8+ @property
9+ def source(self):
10+ if self.context.branch is not None:
11+ return self.context.branch
12+ elif self.context.git_repository is not None:
13+ return self.context.git_repository.getRefByPath(
14+ self.context.git_path)
15+ else:
16+ return None
17+
18
19 def builds_for_snap(snap):
20 """A list of interesting builds.
21
22=== modified file 'lib/lp/snappy/browser/tests/test_snap.py'
23--- lib/lp/snappy/browser/tests/test_snap.py 2015-08-07 10:12:38 +0000
24+++ lib/lp/snappy/browser/tests/test_snap.py 2015-08-27 16:11:59 +0000
25@@ -74,17 +74,12 @@
26 self.factory.makeBuilder(virtualized=True)
27
28 def makeSnap(self, branch=None, git_ref=None):
29- kwargs = {}
30 if branch is None and git_ref is None:
31 branch = self.factory.makeAnyBranch()
32- if branch is not None:
33- kwargs["branch"] = branch
34- else:
35- kwargs["git_repository"] = git_ref.repository
36- kwargs["git_path"] = git_ref.path
37 return self.factory.makeSnap(
38 registrant=self.person, owner=self.person,
39- distroseries=self.distroseries, name=u"snap-name", **kwargs)
40+ distroseries=self.distroseries, name=u"snap-name", branch=branch,
41+ git_ref=git_ref)
42
43 def makeBuild(self, snap=None, archive=None, date_created=None, **kwargs):
44 if snap is None:
45@@ -98,15 +93,41 @@
46 distroarchseries=self.distroarchseries, date_created=date_created,
47 **kwargs)
48
49- def test_index(self):
50- build = self.makeBuild(
51- status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=30))
52- self.assertTextMatchesExpressionIgnoreWhitespace("""\
53- Snap packages snap-name
54- .*
55- Snap package information
56- Owner: Test Person
57- Distribution series: Ubuntu Shiny
58+ def test_index_bzr(self):
59+ branch = self.factory.makePersonalBranch(
60+ owner=self.person, name="snap-branch")
61+ snap = self.makeSnap(branch=branch)
62+ build = self.makeBuild(
63+ snap=snap, status=BuildStatus.FULLYBUILT,
64+ duration=timedelta(minutes=30))
65+ self.assertTextMatchesExpressionIgnoreWhitespace("""\
66+ Snap packages snap-name
67+ .*
68+ Snap package information
69+ Owner: Test Person
70+ Distribution series: Ubuntu Shiny
71+ Source: lp://dev/~test-person/\\+junk/snap-branch
72+ Latest builds
73+ Status When complete Architecture Archive
74+ Successfully built 30 minutes ago i386
75+ Primary Archive for Ubuntu Linux
76+ """, self.getMainText(build.snap))
77+
78+ def test_index_git(self):
79+ [ref] = self.factory.makeGitRefs(
80+ owner=self.person, target=self.person, name=u"snap-repository",
81+ paths=[u"refs/heads/master"])
82+ snap = self.makeSnap(git_ref=ref)
83+ build = self.makeBuild(
84+ snap=snap, status=BuildStatus.FULLYBUILT,
85+ duration=timedelta(minutes=30))
86+ self.assertTextMatchesExpressionIgnoreWhitespace("""\
87+ Snap packages snap-name
88+ .*
89+ Snap package information
90+ Owner: Test Person
91+ Distribution series: Ubuntu Shiny
92+ Source: ~test-person/\\+git/snap-repository:master
93 Latest builds
94 Status When complete Architecture Archive
95 Successfully built 30 minutes ago i386
96
97=== modified file 'lib/lp/snappy/templates/snap-index.pt'
98--- lib/lp/snappy/templates/snap-index.pt 2015-08-07 10:12:38 +0000
99+++ lib/lp/snappy/templates/snap-index.pt 2015-08-27 16:11:59 +0000
100@@ -39,6 +39,10 @@
101 tal:content="distro_series/fullseriesname"/>
102 </dd>
103 </dl>
104+ <dl id="source" tal:define="source view/source" tal:condition="source">
105+ <dt>Source:</dt>
106+ <dd tal:content="structure source/fmt:link"/>
107+ </dl>
108 </div>
109
110 <h2>Latest builds</h2>