Skip to content

Commit 80e52e2

Browse files
threexcstephenfin
authored andcommitted
patch, series: Add support for '--since' and '--before'
Signed-off-by: Trevor Gamblin <[email protected]> Signed-off-by: Stephen Finucane <[email protected]> [stephenfin: Fixed some failing tests, removed some dupe code]
1 parent 5e24a79 commit 80e52e2

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

git_pw/patch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ def update_cmd(patch_ids, commit_ref, state, delegate, archived, fmt):
329329
is_flag=True,
330330
help='Include patches that are archived.',
331331
)
332+
@utils.date_options()
332333
@utils.pagination_options(sort_fields=_sort_fields, default_sort='-date')
333334
@utils.format_options(headers=_list_headers)
334335
@click.argument('name', required=False)
@@ -339,6 +340,8 @@ def list_cmd(
339340
delegates,
340341
hashes,
341342
archived,
343+
since,
344+
before,
342345
limit,
343346
page,
344347
sort,
@@ -403,6 +406,12 @@ def list_cmd(
403406
]
404407
)
405408

409+
if since:
410+
params.append(('since', since.isoformat()))
411+
412+
if before:
413+
params.append(('before', before.isoformat()))
414+
406415
patches = api.index('patches', params)
407416

408417
# Format and print output

git_pw/series.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ def _format_submission(submission):
161161
'email, name or ID.'
162162
),
163163
)
164+
@utils.date_options()
164165
@utils.pagination_options(sort_fields=_sort_fields, default_sort='-date')
165166
@utils.format_options(headers=_list_headers)
166167
@click.argument('name', required=False)
167168
@api.validate_multiple_filter_support
168-
def list_cmd(submitters, limit, page, sort, fmt, headers, name):
169+
def list_cmd(submitters, limit, page, sort, fmt, headers, name, since, before):
169170
"""List series.
170171
171172
List series on the Patchwork instance.
@@ -201,6 +202,12 @@ def list_cmd(submitters, limit, page, sort, fmt, headers, name):
201202
]
202203
)
203204

205+
if since:
206+
params.append(('since', since.isoformat()))
207+
208+
if before:
209+
params.append(('before', before.isoformat()))
210+
204211
series = api.index('series', params)
205212

206213
# Format and print output

git_pw/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,28 @@ def _pagination_options(f):
207207
return _pagination_options
208208

209209

210+
def date_options() -> ty.Callable:
211+
"""Shared date bounding options."""
212+
213+
def _date_options(f):
214+
f = click.option(
215+
'--since',
216+
metavar='SINCE',
217+
type=click.DateTime(),
218+
help='Show only items since a given date in ISO 8601 format',
219+
)(f)
220+
f = click.option(
221+
'--before',
222+
metavar='BEFORE',
223+
type=click.DateTime(),
224+
help='Show only items before a given date in ISO 8601 format',
225+
)(f)
226+
227+
return f
228+
229+
return _date_options
230+
231+
210232
def format_options(
211233
original_function: ty.Optional[ty.Callable] = None,
212234
headers: ty.Optional[ty.Tuple[str, ...]] = None,

tests/test_patch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ def test_list_with_filters(self, mock_echo, mock_index, mock_version):
391391
'--sort',
392392
'-name',
393393
'test',
394+
'--since',
395+
'2022-01-01',
396+
'--before',
397+
'2022-12-31',
394398
],
395399
)
396400

@@ -412,6 +416,8 @@ def test_list_with_filters(self, mock_echo, mock_index, mock_version):
412416
('page', 1),
413417
('per_page', 1),
414418
('order', '-name'),
419+
('since', '2022-01-01T00:00:00'),
420+
('before', '2022-12-31T00:00:00'),
415421
],
416422
),
417423
]

tests/test_series.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ def test_list_with_filters(self, mock_echo, mock_index, mock_version):
226226
'--sort',
227227
'-name',
228228
'test',
229+
'--since',
230+
'2022-01-01',
231+
'--before',
232+
'2022-12-31',
229233
],
230234
)
231235

@@ -241,6 +245,8 @@ def test_list_with_filters(self, mock_echo, mock_index, mock_version):
241245
('page', 1),
242246
('per_page', 1),
243247
('order', '-name'),
248+
('since', '2022-01-01T00:00:00'),
249+
('before', '2022-12-31T00:00:00'),
244250
],
245251
),
246252
]

0 commit comments

Comments
 (0)