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
1=== modified file 'lib/lp/code/interfaces/hasbranches.py'
2--- lib/lp/code/interfaces/hasbranches.py 2009-06-30 16:56:07 +0000
3+++ lib/lp/code/interfaces/hasbranches.py 2010-02-08 01:44:13 +0000
4@@ -11,7 +11,7 @@
5
6
7 from zope.interface import Interface
8-from zope.schema import Choice, List
9+from zope.schema import Choice, Datetime, List
10
11 from canonical.launchpad import _
12 from lp.code.enums import BranchLifecycleStatus, BranchMergeProposalStatus
13@@ -34,15 +34,21 @@
14 @operation_parameters(
15 status=List(
16 title=_("A list of branch lifecycle statuses to filter by."),
17- value_type=Choice(vocabulary=BranchLifecycleStatus)))
18+ value_type=Choice(vocabulary=BranchLifecycleStatus)),
19+ modified_since=Datetime(
20+ title=_('Limit the branches to those modified since this date.'),
21+ required=False))
22 @call_with(visible_by_user=REQUEST_USER)
23 @operation_returns_collection_of(Interface) # Really IBranch.
24 @export_read_operation()
25- def getBranches(status=None, visible_by_user=None):
26+ def getBranches(status=None, visible_by_user=None,
27+ modified_since=None):
28 """Returns all branches with the given lifecycle status.
29
30 :param status: A list of statuses to filter with.
31 :param visible_by_user: Normally the user who is asking.
32+ :param modified_since: If set, filters the branches being returned
33+ to those that have been modified since the specified date/time.
34 :returns: A list of `IBranch`.
35 """
36
37
38=== modified file 'lib/lp/code/model/hasbranches.py'
39--- lib/lp/code/model/hasbranches.py 2009-06-30 16:56:07 +0000
40+++ lib/lp/code/model/hasbranches.py 2010-02-08 01:44:13 +0000
41@@ -18,13 +18,16 @@
42 class HasBranchesMixin:
43 """A mixin implementation for `IHasBranches`."""
44
45- def getBranches(self, status=None, visible_by_user=None):
46+ def getBranches(self, status=None, visible_by_user=None,
47+ modified_since=None):
48 """See `IHasBranches`."""
49 if status is None:
50 status = DEFAULT_BRANCH_STATUS_IN_LISTING
51
52 collection = IBranchCollection(self).visibleByUser(visible_by_user)
53 collection = collection.withLifecycleStatus(*status)
54+ if modified_since is not None:
55+ collection = collection.modifiedSince(modified_since)
56 return collection.getBranches()
57
58
59
60=== modified file 'lib/lp/code/stories/webservice/xx-branch.txt'
61--- lib/lp/code/stories/webservice/xx-branch.txt 2010-01-14 01:28:55 +0000
62+++ lib/lp/code/stories/webservice/xx-branch.txt 2010-02-08 01:44:13 +0000
63@@ -79,7 +79,8 @@
64 >>> fooix = factory.makeProduct(name='fooix')
65 >>> branch = factory.makeProductBranch(
66 ... branch_type=BranchType.HOSTED, owner=eric, product=fooix,
67- ... name='trunk', title='The Fooix Trunk')
68+ ... name='trunk', title='The Fooix Trunk',
69+ ... date_created=datetime(2009, 1, 1, tzinfo=pytz.UTC))
70 >>> feature_branch = factory.makeAnyBranch(
71 ... owner=eric, product=fooix, name='feature-branch',
72 ... lifecycle_status=BranchLifecycleStatus.EXPERIMENTAL)
73@@ -108,8 +109,8 @@
74 branch_type: u'Hosted'
75 bzr_identity: u'lp://dev/~eric/fooix/trunk'
76 control_format: None
77- date_created: ...
78- date_last_modified: ...
79+ date_created: u'2009-01-01T00:00:00+00:00'
80+ date_last_modified: u'2009-01-01T00:00:00+00:00'
81 dependent_branches_collection_link: u'.../~eric/fooix/trunk/dependent_branches'
82 description: None
83 display_name: u'lp://dev/~eric/fooix/trunk'
84@@ -181,10 +182,10 @@
85
86 >>> def print_branch(branch):
87 ... print branch['unique_name'] + ' - ' + branch['lifecycle_status']
88- >>> def print_branches(webservice, url, status=None):
89+ >>> def print_branches(webservice, url, status=None, modified_since=None):
90 ... branches = webservice.named_get(
91 ... url, 'getBranches',
92- ... status=status).jsonBody()
93+ ... status=status, modified_since=modified_since).jsonBody()
94 ... for branch in branches['entries']:
95 ... print_branch(branch)
96
97@@ -192,6 +193,13 @@
98 ~eric/fooix/trunk - Development
99 ~eric/fooix/feature-branch - Experimental
100
101+The branches can be limited to those that have been modified since a specified
102+time.
103+
104+ >>> print_branches(webservice, '/fooix',
105+ ... modified_since=u'2010-01-01T00:00:00+00:00')
106+ ~eric/fooix/feature-branch - Experimental
107+
108 A list of lifecycle statuses can be provided for filtering.
109
110 >>> print_branches(webservice, '/fooix', ('Experimental'))