Repository: getpatchwork/git-pw

Issue:
`patch list` is not so usable when tons of patches are available
Here is an issue with `git pw patch list`.
It can't show properly the limit of commits. `--limit=0` does not affect anything (I'm expecting no limit, or server defined limit), `--limit=1000` shows 1000 patches, however, I would rather need only few patches by given submitter (okay, this wouldn't work with API 1.0), or for given date (or period in time).
So, `git pw patch list --date=today` or alike is what being missed.

Comments:

Patch:
diff --git a/git_pw/patch.py b/git_pw/patch.py
index d436bbb..4ed80b0 100644
--- a/git_pw/patch.py
+++ b/git_pw/patch.py
@@ -329,6 +329,7 @@ def update_cmd(patch_ids, commit_ref, state, delegate, archived, fmt):
     is_flag=True,
     help='Include patches that are archived.',
 )
+@utils.date_options()
 @utils.pagination_options(sort_fields=_sort_fields, default_sort='-date')
 @utils.format_options(headers=_list_headers)
 @click.argument('name', required=False)
@@ -339,6 +340,8 @@ def list_cmd(
     delegates,
     hashes,
     archived,
+    since,
+    before,
     limit,
     page,
     sort,
@@ -403,6 +406,12 @@ def list_cmd(
         ]
     )
 
+    if since:
+        params.append(('since', since.isoformat()))
+
+    if before:
+        params.append(('before', before.isoformat()))
+
     patches = api.index('patches', params)
 
     # Format and print output
diff --git a/git_pw/series.py b/git_pw/series.py
index 59a1a25..1a46bc7 100644
--- a/git_pw/series.py
+++ b/git_pw/series.py
@@ -161,11 +161,12 @@ def show_cmd(fmt, series_id):
         'email, name or ID.'
     ),
 )
+@utils.date_options()
 @utils.pagination_options(sort_fields=_sort_fields, default_sort='-date')
 @utils.format_options(headers=_list_headers)
 @click.argument('name', required=False)
 @api.validate_multiple_filter_support
-def list_cmd(submitters, limit, page, sort, fmt, headers, name):
+def list_cmd(submitters, limit, page, sort, fmt, headers, name, since, before):
     """List series.
 
     List series on the Patchwork instance.
@@ -201,6 +202,12 @@ def list_cmd(submitters, limit, page, sort, fmt, headers, name):
         ]
     )
 
+    if since:
+        params.append(('since', since.isoformat()))
+
+    if before:
+        params.append(('before', before.isoformat()))
+
     series = api.index('series', params)
 
     # Format and print output
diff --git a/git_pw/utils.py b/git_pw/utils.py
index b714844..c94758b 100644
--- a/git_pw/utils.py
+++ b/git_pw/utils.py
@@ -207,6 +207,28 @@ def pagination_options(
     return _pagination_options
 
 
+def date_options() -> ty.Callable:
+    """Shared date bounding options."""
+
+    def _date_options(f):
+        f = click.option(
+            '--since',
+            metavar='SINCE',
+            type=click.DateTime(),
+            help='Show only items since a given date in ISO 8601 format',
+        )(f)
+        f = click.option(
+            '--before',
+            metavar='BEFORE',
+            type=click.DateTime(),
+            help='Show only items before a given date in ISO 8601 format',
+        )(f)
+
+        return f
+
+    return _date_options
+
+
 def format_options(
     original_function: ty.Optional[ty.Callable] = None,
     headers: ty.Optional[ty.Tuple[str, ...]] = None,
diff --git a/releasenotes/notes/add-before-since-options-c67799ef2ad89c0c.yaml b/releasenotes/notes/add-before-since-options-c67799ef2ad89c0c.yaml
new file mode 100644
index 0000000..dc22af5
--- /dev/null
+++ b/releasenotes/notes/add-before-since-options-c67799ef2ad89c0c.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    The ``series list`` and ``patch list`` commands now support ``--since`` and
+    ``--before`` filters to list items created since or before a given
+    date-time.


Test patch:
diff --git a/tests/test_patch.py b/tests/test_patch.py
index 74285e9..e0d98f5 100644
--- a/tests/test_patch.py
+++ b/tests/test_patch.py
@@ -391,6 +391,10 @@ class ListTestCase(unittest.TestCase):
                 '--sort',
                 '-name',
                 'test',
+                '--since',
+                '2022-01-01',
+                '--before',
+                '2022-12-31',
             ],
         )
 
@@ -412,6 +416,8 @@ class ListTestCase(unittest.TestCase):
                     ('page', 1),
                     ('per_page', 1),
                     ('order', '-name'),
+                    ('since', '2022-01-01T00:00:00'),
+                    ('before', '2022-12-31T00:00:00'),
                 ],
             ),
         ]
diff --git a/tests/test_series.py b/tests/test_series.py
index 7125519..4dd6a5e 100644
--- a/tests/test_series.py
+++ b/tests/test_series.py
@@ -226,6 +226,10 @@ class ListTestCase(unittest.TestCase):
                 '--sort',
                 '-name',
                 'test',
+                '--since',
+                '2022-01-01',
+                '--before',
+                '2022-12-31',
             ],
         )
 
@@ -241,6 +245,8 @@ class ListTestCase(unittest.TestCase):
                     ('page', 1),
                     ('per_page', 1),
                     ('order', '-name'),
+                    ('since', '2022-01-01T00:00:00'),
+                    ('before', '2022-12-31T00:00:00'),
                 ],
             ),
         ]