Merge lp:~thumper/launchpad/get-branch-by-date into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~thumper/launchpad/get-branch-by-date
Merge into: lp:launchpad
Diff against target: 110 lines (+26/-9)
3 files modified
lib/lp/code/interfaces/hasbranches.py (+9/-3)
lib/lp/code/model/hasbranches.py (+4/-1)
lib/lp/code/stories/webservice/xx-branch.txt (+13/-5)
To merge this branch: bzr merge lp:~thumper/launchpad/get-branch-by-date
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+18816@code.launchpad.net

Commit message

Allow the getBranches API method to specify modified_since to limit the returned branches.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Adds another option to the getBranches method of the IHasBranches interface.

This allows the user to specify the modified_since option to limit the branches returned to those whose date_last_modified is after the specified datetime.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/interfaces/hasbranches.py'
--- lib/lp/code/interfaces/hasbranches.py 2009-06-30 16:56:07 +0000
+++ lib/lp/code/interfaces/hasbranches.py 2010-02-08 01:44:13 +0000
@@ -11,7 +11,7 @@
1111
1212
13from zope.interface import Interface13from zope.interface import Interface
14from zope.schema import Choice, List14from zope.schema import Choice, Datetime, List
1515
16from canonical.launchpad import _16from canonical.launchpad import _
17from lp.code.enums import BranchLifecycleStatus, BranchMergeProposalStatus17from lp.code.enums import BranchLifecycleStatus, BranchMergeProposalStatus
@@ -34,15 +34,21 @@
34 @operation_parameters(34 @operation_parameters(
35 status=List(35 status=List(
36 title=_("A list of branch lifecycle statuses to filter by."),36 title=_("A list of branch lifecycle statuses to filter by."),
37 value_type=Choice(vocabulary=BranchLifecycleStatus)))37 value_type=Choice(vocabulary=BranchLifecycleStatus)),
38 modified_since=Datetime(
39 title=_('Limit the branches to those modified since this date.'),
40 required=False))
38 @call_with(visible_by_user=REQUEST_USER)41 @call_with(visible_by_user=REQUEST_USER)
39 @operation_returns_collection_of(Interface) # Really IBranch.42 @operation_returns_collection_of(Interface) # Really IBranch.
40 @export_read_operation()43 @export_read_operation()
41 def getBranches(status=None, visible_by_user=None):44 def getBranches(status=None, visible_by_user=None,
45 modified_since=None):
42 """Returns all branches with the given lifecycle status.46 """Returns all branches with the given lifecycle status.
4347
44 :param status: A list of statuses to filter with.48 :param status: A list of statuses to filter with.
45 :param visible_by_user: Normally the user who is asking.49 :param visible_by_user: Normally the user who is asking.
50 :param modified_since: If set, filters the branches being returned
51 to those that have been modified since the specified date/time.
46 :returns: A list of `IBranch`.52 :returns: A list of `IBranch`.
47 """53 """
4854
4955
=== modified file 'lib/lp/code/model/hasbranches.py'
--- lib/lp/code/model/hasbranches.py 2009-06-30 16:56:07 +0000
+++ lib/lp/code/model/hasbranches.py 2010-02-08 01:44:13 +0000
@@ -18,13 +18,16 @@
18class HasBranchesMixin:18class HasBranchesMixin:
19 """A mixin implementation for `IHasBranches`."""19 """A mixin implementation for `IHasBranches`."""
2020
21 def getBranches(self, status=None, visible_by_user=None):21 def getBranches(self, status=None, visible_by_user=None,
22 modified_since=None):
22 """See `IHasBranches`."""23 """See `IHasBranches`."""
23 if status is None:24 if status is None:
24 status = DEFAULT_BRANCH_STATUS_IN_LISTING25 status = DEFAULT_BRANCH_STATUS_IN_LISTING
2526
26 collection = IBranchCollection(self).visibleByUser(visible_by_user)27 collection = IBranchCollection(self).visibleByUser(visible_by_user)
27 collection = collection.withLifecycleStatus(*status)28 collection = collection.withLifecycleStatus(*status)
29 if modified_since is not None:
30 collection = collection.modifiedSince(modified_since)
28 return collection.getBranches()31 return collection.getBranches()
2932
3033
3134
=== modified file 'lib/lp/code/stories/webservice/xx-branch.txt'
--- lib/lp/code/stories/webservice/xx-branch.txt 2010-01-14 01:28:55 +0000
+++ lib/lp/code/stories/webservice/xx-branch.txt 2010-02-08 01:44:13 +0000
@@ -79,7 +79,8 @@
79 >>> fooix = factory.makeProduct(name='fooix')79 >>> fooix = factory.makeProduct(name='fooix')
80 >>> branch = factory.makeProductBranch(80 >>> branch = factory.makeProductBranch(
81 ... branch_type=BranchType.HOSTED, owner=eric, product=fooix,81 ... branch_type=BranchType.HOSTED, owner=eric, product=fooix,
82 ... name='trunk', title='The Fooix Trunk')82 ... name='trunk', title='The Fooix Trunk',
83 ... date_created=datetime(2009, 1, 1, tzinfo=pytz.UTC))
83 >>> feature_branch = factory.makeAnyBranch(84 >>> feature_branch = factory.makeAnyBranch(
84 ... owner=eric, product=fooix, name='feature-branch',85 ... owner=eric, product=fooix, name='feature-branch',
85 ... lifecycle_status=BranchLifecycleStatus.EXPERIMENTAL)86 ... lifecycle_status=BranchLifecycleStatus.EXPERIMENTAL)
@@ -108,8 +109,8 @@
108 branch_type: u'Hosted'109 branch_type: u'Hosted'
109 bzr_identity: u'lp://dev/~eric/fooix/trunk'110 bzr_identity: u'lp://dev/~eric/fooix/trunk'
110 control_format: None111 control_format: None
111 date_created: ...112 date_created: u'2009-01-01T00:00:00+00:00'
112 date_last_modified: ...113 date_last_modified: u'2009-01-01T00:00:00+00:00'
113 dependent_branches_collection_link: u'.../~eric/fooix/trunk/dependent_branches'114 dependent_branches_collection_link: u'.../~eric/fooix/trunk/dependent_branches'
114 description: None115 description: None
115 display_name: u'lp://dev/~eric/fooix/trunk'116 display_name: u'lp://dev/~eric/fooix/trunk'
@@ -181,10 +182,10 @@
181182
182 >>> def print_branch(branch):183 >>> def print_branch(branch):
183 ... print branch['unique_name'] + ' - ' + branch['lifecycle_status']184 ... print branch['unique_name'] + ' - ' + branch['lifecycle_status']
184 >>> def print_branches(webservice, url, status=None):185 >>> def print_branches(webservice, url, status=None, modified_since=None):
185 ... branches = webservice.named_get(186 ... branches = webservice.named_get(
186 ... url, 'getBranches',187 ... url, 'getBranches',
187 ... status=status).jsonBody()188 ... status=status, modified_since=modified_since).jsonBody()
188 ... for branch in branches['entries']:189 ... for branch in branches['entries']:
189 ... print_branch(branch)190 ... print_branch(branch)
190191
@@ -192,6 +193,13 @@
192 ~eric/fooix/trunk - Development193 ~eric/fooix/trunk - Development
193 ~eric/fooix/feature-branch - Experimental194 ~eric/fooix/feature-branch - Experimental
194195
196The branches can be limited to those that have been modified since a specified
197time.
198
199 >>> print_branches(webservice, '/fooix',
200 ... modified_since=u'2010-01-01T00:00:00+00:00')
201 ~eric/fooix/feature-branch - Experimental
202
195A list of lifecycle statuses can be provided for filtering.203A list of lifecycle statuses can be provided for filtering.
196204
197 >>> print_branches(webservice, '/fooix', ('Experimental'))205 >>> print_branches(webservice, '/fooix', ('Experimental'))