Merge lp:~cjwatson/launchpad/git-mp-ref-proposals into lp:launchpad

Proposed by Colin Watson on 2015-04-24
Status: Merged
Merged at revision: 17456
Proposed branch: lp:~cjwatson/launchpad/git-mp-ref-proposals
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/git-mp-collection
Diff against target: 133 lines (+49/-2)
4 files modified
lib/lp/_schema_circular_imports.py (+2/-0)
lib/lp/code/interfaces/gitref.py (+21/-1)
lib/lp/code/model/gitref.py (+17/-0)
lib/lp/code/model/tests/test_gitref.py (+9/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-mp-ref-proposals
Reviewer Review Type Date Requested Status
William Grant code 2015-04-24 Approve on 2015-04-27
Review via email: mp+257374@code.launchpad.net

Commit Message

Add GitRef.getMergeProposals.

Description of the Change

Add GitRef.getMergeProposals.

To post a comment you must log in.
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/_schema_circular_imports.py'
2--- lib/lp/_schema_circular_imports.py 2015-04-22 16:11:40 +0000
3+++ lib/lp/_schema_circular_imports.py 2015-04-24 13:23:09 +0000
4@@ -568,6 +568,8 @@
5 patch_plain_parameter_type(
6 IGitRef, 'createMergeProposal', 'merge_prerequisite', IGitRef)
7 patch_entry_return_type(IGitRef, 'createMergeProposal', IBranchMergeProposal)
8+patch_collection_return_type(
9+ IGitRef, 'getMergeProposals', IBranchMergeProposal)
10
11 # IGitRepository
12 patch_collection_property(IGitRepository, 'branches', IGitRef)
13
14=== modified file 'lib/lp/code/interfaces/gitref.py'
15--- lib/lp/code/interfaces/gitref.py 2015-04-22 16:11:40 +0000
16+++ lib/lp/code/interfaces/gitref.py 2015-04-24 13:23:09 +0000
17@@ -14,9 +14,11 @@
18 call_with,
19 export_as_webservice_entry,
20 export_factory_operation,
21+ export_read_operation,
22 exported,
23 operation_for_version,
24 operation_parameters,
25+ operation_returns_collection_of,
26 REQUEST_USER,
27 )
28 from lazr.restful.fields import (
29@@ -37,7 +39,10 @@
30 )
31
32 from lp import _
33-from lp.code.enums import GitObjectType
34+from lp.code.enums import (
35+ BranchMergeProposalStatus,
36+ GitObjectType,
37+ )
38 from lp.registry.interfaces.person import IPerson
39 from lp.services.webapp.interfaces import ITableBatchNavigator
40
41@@ -256,6 +261,21 @@
42 References in personal repositories cannot specify merge proposals.
43 """
44
45+ @operation_parameters(
46+ status=List(
47+ title=_("A list of merge proposal statuses to filter by."),
48+ value_type=Choice(vocabulary=BranchMergeProposalStatus)),
49+ merged_revision_ids=List(TextLine(
50+ title=_('The target revision ID of the merge.'))))
51+ @call_with(visible_by_user=REQUEST_USER)
52+ # Really IBranchMergeProposal, patched in _schema_circular_imports.py.
53+ @operation_returns_collection_of(Interface)
54+ @export_read_operation()
55+ @operation_for_version("devel")
56+ def getMergeProposals(status=None, visible_by_user=None,
57+ merged_revision_ids=None, eager_load=False):
58+ """Return matching BranchMergeProposals."""
59+
60
61 class IGitRefBatchNavigator(ITableBatchNavigator):
62 pass
63
64=== modified file 'lib/lp/code/model/gitref.py'
65--- lib/lp/code/model/gitref.py 2015-04-22 16:11:40 +0000
66+++ lib/lp/code/model/gitref.py 2015-04-24 13:23:09 +0000
67@@ -18,6 +18,7 @@
68 Store,
69 Unicode,
70 )
71+from zope.component import getUtility
72 from zope.event import notify
73 from zope.interface import implements
74
75@@ -38,6 +39,7 @@
76 from lp.code.interfaces.branchmergeproposal import (
77 BRANCH_MERGE_PROPOSAL_FINAL_STATES,
78 )
79+from lp.code.interfaces.gitcollection import IAllGitRepositories
80 from lp.code.interfaces.gitref import IGitRef
81 from lp.code.model.branchmergeproposal import (
82 BranchMergeProposal,
83@@ -181,6 +183,21 @@
84 Not(BranchMergeProposal.queue_status.is_in(
85 BRANCH_MERGE_PROPOSAL_FINAL_STATES)))
86
87+ def getMergeProposals(self, status=None, visible_by_user=None,
88+ merged_revision_ids=None, eager_load=False):
89+ """See `IGitRef`."""
90+ if not status:
91+ status = (
92+ BranchMergeProposalStatus.CODE_APPROVED,
93+ BranchMergeProposalStatus.NEEDS_REVIEW,
94+ BranchMergeProposalStatus.WORK_IN_PROGRESS)
95+
96+ collection = getUtility(IAllGitRepositories).visibleByUser(
97+ visible_by_user)
98+ return collection.getMergeProposals(
99+ status, target_repository=self.repository, target_path=self.path,
100+ merged_revision_ids=merged_revision_ids, eager_load=eager_load)
101+
102
103 class GitRef(StormBase, GitRefMixin):
104 """See `IGitRef`."""
105
106=== modified file 'lib/lp/code/model/tests/test_gitref.py'
107--- lib/lp/code/model/tests/test_gitref.py 2015-04-21 13:40:50 +0000
108+++ lib/lp/code/model/tests/test_gitref.py 2015-04-24 13:23:09 +0000
109@@ -26,8 +26,11 @@
110
111 layer = DatabaseFunctionalLayer
112
113+ def setUp(self):
114+ super(TestGitRef, self).setUp()
115+ self.useFixture(FeatureFixture({GIT_FEATURE_FLAG: u"on"}))
116+
117 def test_display_name(self):
118- self.useFixture(FeatureFixture({GIT_FEATURE_FLAG: u"on"}))
119 [master, personal] = self.factory.makeGitRefs(
120 paths=[u"refs/heads/master", u"refs/heads/people/foo/bar"])
121 repo_path = master.repository.shortened_path
122@@ -35,6 +38,11 @@
123 [u"%s:master" % repo_path, "%s:people/foo/bar" % repo_path],
124 [ref.display_name for ref in (master, personal)])
125
126+ def test_getMergeProposals(self):
127+ [target_ref] = self.factory.makeGitRefs()
128+ bmp = self.factory.makeBranchMergeProposalForGit(target_ref=target_ref)
129+ self.assertEqual([bmp], list(target_ref.getMergeProposals()))
130+
131
132 class TestGitRefWebservice(TestCaseWithFactory):
133 """Tests for the webservice."""