Skip to content

Commit 6ec1881

Browse files
committed
Add '--hash' option for 'git-pw patch list'
Allow users to filter by hash. Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #55
1 parent 5a3341d commit 6ec1881

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

git_pw/patch.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,25 @@ def update_cmd(patch_ids, commit_ref, state, delegate, archived, fmt):
199199
help='Show only patches by these submitters. Should be an '
200200
'email, name or ID.')
201201
@click.option('--delegate', metavar='DELEGATE', multiple=True,
202-
help='Show only patches by these delegates. Should be an '
202+
help='Show only patches with these delegates. Should be an '
203203
'email or username.')
204+
@click.option('--hash', 'hashes', metavar='HASH', multiple=True,
205+
help='Show only patches with these hashes.')
204206
@click.option('--archived', default=False, is_flag=True,
205207
help='Include patches that are archived.')
206208
@utils.pagination_options(sort_fields=_sort_fields, default_sort='-date')
207209
@utils.format_options(headers=_list_headers)
208210
@click.argument('name', required=False)
209211
@api.validate_multiple_filter_support
210-
def list_cmd(state, submitter, delegate, archived, limit, page, sort, fmt,
211-
headers, name):
212+
def list_cmd(state, submitter, delegate, hashes, archived, limit, page, sort,
213+
fmt, headers, name):
212214
"""List patches.
213215
214216
List patches on the Patchwork instance.
215217
"""
216218
LOG.debug('List patches: states=%s, submitters=%s, delegates=%s, '
217-
'archived=%r', ','.join(state), ','.join(submitter),
218-
','.join(delegate), archived)
219+
'hashes=%s, archived=%r', ','.join(state), ','.join(submitter),
220+
','.join(delegate), ','.join(hashes), archived)
219221

220222
params = []
221223

@@ -236,6 +238,9 @@ def list_cmd(state, submitter, delegate, archived, limit, page, sort, fmt,
236238
else:
237239
params.extend(api.retrieve_filter_ids('users', 'delegate', delg))
238240

241+
for hash_ in hashes:
242+
params.append(('hash', hash_))
243+
239244
params.extend([
240245
('q', name),
241246
('archived', 'true' if archived else 'false'),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
It is now possible to filter patches by hash. For example::
5+
6+
git pw patch list --hash HASH

tests/test_patch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def test_list_with_filters(self, mock_echo, mock_index, mock_version):
345345
result = runner.invoke(patch.list_cmd, [
346346
'--state', 'new', '--submitter', 'john@example.com',
347347
'--submitter', '2', '--delegate', 'doe@example.com',
348-
'--delegate', '2', '--archived',
348+
'--delegate', '2', '--hash', 'foo', '--archived',
349349
'--limit', 1, '--page', 1, '--sort', '-name', 'test'])
350350

351351
assert result.exit_code == 0, result
@@ -354,7 +354,8 @@ def test_list_with_filters(self, mock_echo, mock_index, mock_version):
354354
mock.call('users', [('q', 'doe@example.com')]),
355355
mock.call('patches', [
356356
('state', 'new'), ('submitter', 1), ('submitter', '2'),
357-
('delegate', 1), ('delegate', '2'), ('q', 'test'),
357+
('delegate', 1), ('delegate', '2'), ('hash', 'foo'),
358+
('q', 'test'),
358359
('archived', 'true'), ('page', 1), ('per_page', 1),
359360
('order', '-name')])]
360361

0 commit comments

Comments
 (0)