Merge lp:~twom/launchpad/pending-but-not-merged into lp:launchpad

Proposed by Tom Wardill on 2018-08-31
Status: Merged
Merged at revision: 18768
Proposed branch: lp:~twom/launchpad/pending-but-not-merged
Merge into: lp:launchpad
Diff against target: 94 lines (+38/-4)
4 files modified
lib/lp/code/browser/gitrepository.py (+3/-2)
lib/lp/code/browser/tests/test_gitrepository.py (+21/-0)
lib/lp/code/model/gitrepository.py (+8/-2)
lib/lp/code/model/tests/test_gitrepository.py (+6/-0)
To merge this branch: bzr merge lp:~twom/launchpad/pending-but-not-merged
Reviewer Review Type Date Requested Status
Colin Watson 2018-08-31 Approve on 2018-08-31
Review via email: mp+354108@code.launchpad.net

Commit message

Don't show merged or otherwise inactive landing targets on the gitrepository page

To post a comment you must log in.
Colin Watson (cjwatson) :
18769. By Tom Wardill on 2018-08-31

We don't use landing_targets, so let's rename to that

18770. By Tom Wardill on 2018-08-31

Rename parameter for only_active

18771. By Tom Wardill on 2018-08-31

Re-add the missing docstring

Colin Watson (cjwatson) :
18772. By Tom Wardill on 2018-08-31

Add test for GitRepository.getMergeProposals

Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/gitrepository.py'
2--- lib/lp/code/browser/gitrepository.py 2018-08-30 14:54:37 +0000
3+++ lib/lp/code/browser/gitrepository.py 2018-08-31 14:26:04 +0000
4@@ -393,8 +393,9 @@
5
6 @cachedproperty
7 def landing_targets(self):
8- """Return a filtered list of landing targets."""
9- targets = self.context.getPrecachedLandingTargets(self.user)
10+ """Return a filtered list of active landing targets."""
11+ targets = self.context.getPrecachedLandingTargets(
12+ self.user, only_active=True)
13 return latest_proposals_for_each_branch(targets)
14
15
16
17=== modified file 'lib/lp/code/browser/tests/test_gitrepository.py'
18--- lib/lp/code/browser/tests/test_gitrepository.py 2018-08-31 06:29:29 +0000
19+++ lib/lp/code/browser/tests/test_gitrepository.py 2018-08-31 14:26:04 +0000
20@@ -296,6 +296,27 @@
21 self.assertIsNotNone(
22 find_tag_by_id(browser.contents, 'landing-targets'))
23
24+ def test_view_with_inactive_landing_targets(self):
25+ product = self.factory.makeProduct(name="foo", vcs=VCSType.GIT)
26+ target_repository = self.factory.makeGitRepository(target=product)
27+ source_repository = self.factory.makeGitRepository(target=product)
28+ target_git_refs = self.factory.makeGitRefs(
29+ target_repository,
30+ paths=["refs/heads/master", "refs/heads/1.0", "refs/tags/1.1"])
31+ source_git_refs = self.factory.makeGitRefs(
32+ source_repository,
33+ paths=["refs/heads/master"])
34+ self.factory.makeBranchMergeProposalForGit(
35+ target_ref=target_git_refs[0],
36+ source_ref=source_git_refs[0],
37+ set_state=BranchMergeProposalStatus.MERGED)
38+ with FeatureFixture({"code.git.show_repository_mps": "on"}):
39+ with person_logged_in(target_repository.owner):
40+ browser = self.getViewBrowser(
41+ source_repository, user=source_repository.owner)
42+ self.assertIsNone(
43+ find_tag_by_id(browser.contents, 'landing-targets'))
44+
45
46 class TestGitRepositoryViewPrivateArtifacts(BrowserTestCase):
47 """Tests that Git repositories with private team artifacts can be viewed.
48
49=== modified file 'lib/lp/code/model/gitrepository.py'
50--- lib/lp/code/model/gitrepository.py 2018-08-29 17:11:57 +0000
51+++ lib/lp/code/model/gitrepository.py 2018-08-31 14:26:04 +0000
52@@ -71,6 +71,7 @@
53 )
54 from lp.app.interfaces.services import IService
55 from lp.code.enums import (
56+ BranchMergeProposalStatus,
57 GitObjectType,
58 GitRepositoryType,
59 )
60@@ -887,10 +888,15 @@
61 BranchMergeProposal,
62 BranchMergeProposal.source_git_repository == self)
63
64- def getPrecachedLandingTargets(self, user):
65+ def getPrecachedLandingTargets(self, user, only_active=False):
66 """See `IGitRepository`."""
67+ results = self.landing_targets
68+ if only_active:
69+ results = self.landing_targets.find(
70+ Not(BranchMergeProposal.queue_status.is_in(
71+ BRANCH_MERGE_PROPOSAL_FINAL_STATES)))
72 loader = partial(BranchMergeProposal.preloadDataForBMPs, user=user)
73- return DecoratedResultSet(self.landing_targets, pre_iter_hook=loader)
74+ return DecoratedResultSet(results, pre_iter_hook=loader)
75
76 @property
77 def _api_landing_targets(self):
78
79=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
80--- lib/lp/code/model/tests/test_gitrepository.py 2018-07-24 11:57:33 +0000
81+++ lib/lp/code/model/tests/test_gitrepository.py 2018-08-31 14:26:04 +0000
82@@ -215,6 +215,12 @@
83 clear_property_cache(repository)
84 self.assertIsNone(repository.code_import)
85
86+ def test_getMergeProposals(self):
87+ repository = self.factory.makeGitRepository()
88+ [ref] = self.factory.makeGitRefs(repository=repository)
89+ bmp = self.factory.makeBranchMergeProposalForGit(target_ref=ref)
90+ self.assertEqual([bmp], list(repository.getMergeProposals()))
91+
92
93 class TestGitIdentityMixin(TestCaseWithFactory):
94 """Test the defaults and identities provided by GitIdentityMixin."""