Skip to content

Commit a7741fe

Browse files
committed
Allow bulk updating
This is really a hack but it is something I've found myself missing recently. Hopefully this will be unnecessary once we have series states. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent b92435e commit a7741fe

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

git_pw/patch.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def show_cmd(patch_id):
109109

110110

111111
@click.command(name='update')
112-
@click.argument('patch_id', type=click.INT)
112+
@click.argument('patch_ids', type=click.INT, nargs=-1, required=True)
113113
@click.option('--commit-ref', metavar='COMMIT_REF',
114114
help='Set the patch commit reference hash')
115115
@click.option('--state', metavar='STATE',
@@ -120,40 +120,41 @@ def show_cmd(patch_id):
120120
'either a username or a user\'s email address.')
121121
@click.option('--archived', metavar='ARCHIVED', type=click.BOOL,
122122
help='Set the patch archived state.')
123-
def update_cmd(patch_id, commit_ref, state, delegate, archived):
124-
"""Update a patch.
123+
def update_cmd(patch_ids, commit_ref, state, delegate, archived):
124+
"""Update one or more patches.
125125
126-
Updates a Patch on the Patchwork instance. Some operations may
126+
Updates one or more Patches on the Patchwork instance. Some operations may
127127
require admin or maintainer permissions.
128128
"""
129-
LOG.info('Updating patch: id=%d, commit_ref=%s, state=%s, archived=%s',
130-
patch_id, commit_ref, state, archived)
129+
for patch_id in patch_ids:
130+
LOG.info('Updating patch: id=%d, commit_ref=%s, state=%s, archived=%s',
131+
patch_id, commit_ref, state, archived)
131132

132-
if delegate:
133-
users = api.index('users', [('q', delegate)])
134-
if len(users) == 0:
135-
LOG.error('No matching delegates found: %s', delegate)
136-
sys.exit(1)
137-
elif len(users) > 1:
138-
LOG.error('More than one delegate found: %s', delegate)
139-
sys.exit(1)
133+
if delegate:
134+
users = api.index('users', [('q', delegate)])
135+
if len(users) == 0:
136+
LOG.error('No matching delegates found: %s', delegate)
137+
sys.exit(1)
138+
elif len(users) > 1:
139+
LOG.error('More than one delegate found: %s', delegate)
140+
sys.exit(1)
140141

141-
delegate = users[0]['id']
142+
delegate = users[0]['id']
142143

143-
data = {}
144-
for key, value in [('commit_ref', commit_ref), ('state', state),
145-
('archived', archived), ('delegate', delegate)]:
146-
if value is None:
147-
continue
144+
data = {}
145+
for key, value in [('commit_ref', commit_ref), ('state', state),
146+
('archived', archived), ('delegate', delegate)]:
147+
if value is None:
148+
continue
148149

149-
data[key] = str(value)
150+
data[key] = str(value)
150151

151-
data = [('commit_ref', commit_ref), ('state', state),
152-
('archived', archived), ('delegate', delegate)]
152+
data = [('commit_ref', commit_ref), ('state', state),
153+
('archived', archived), ('delegate', delegate)]
153154

154-
patch = api.update('patches', patch_id, data)
155+
patch = api.update('patches', patch_id, data)
155156

156-
_show_patch(patch)
157+
_show_patch(patch)
157158

158159

159160
# NOTE(stephenfin): The list of default states is populated from Patchwork's
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
You can now list multiple patches for ``git pw patch update``. This allows
5+
you to do bulk updates, e.g. for a series of patches (because series states
6+
are not yet supported). For example::
7+
8+
$ git pw patch update --state accepted 123 124 125 126

0 commit comments

Comments
 (0)