Skip to content

Commit 8ecba27

Browse files
committed
Add auto-complete of '--state' argument
Patchwork provides some defaults and it's likely most deployments are using these or some combination thereof. Start providing a default selection but allow people to override this if they need to. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 1528e7b commit 8ecba27

22 files changed

+75
-33
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ username/password combination:
102102
``pw.password``
103103
The password for your Patchwork account.
104104

105+
The following settings are **optional** and may need to be set depending on
106+
your Patchwork instance's configuration:
107+
108+
``pw.states``
109+
The states that can be applied to a patch using the ``git pw patch update``
110+
command. Should be provided in slug form (``changes-requested`` instead of
111+
``Changes Requested``). Only required if your Patchwork instance uses
112+
non-default states.
113+
105114
You can set these settings using the ``git config`` command. This should be
106115
done in the repo in which you intend to apply patches. For example, to
107116
configure the Patchwork project, run:

git_pw/config.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
from git_pw import utils
88

99
LOG = logging.getLogger(__name__)
10-
# TODO(stephenfin): We should eventually download and store these
11-
# automagically
12-
DEFAULT_STATES = [
13-
'new', 'under-review', 'accepted', 'rejected', 'rfc', 'not-applicable',
14-
'changes-requested', 'awaiting-upstream', 'superseded', 'deferred']
1510

1611

1712
class Config(object):
@@ -21,7 +16,10 @@ def __init__(self):
2116

2217
def __getattribute__(self, name):
2318
# attempt to use any attributes first
24-
value = object.__getattribute__(self, name)
19+
try:
20+
value = super(Config, self).__getattribute__(name)
21+
except AttributeError:
22+
value = None
2523
if value:
2624
LOG.debug("Retrieved '{}' setting from cache".format(name))
2725
return value

git_pw/patch.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
import click
1111

1212
from git_pw import api
13+
from git_pw import config
1314
from git_pw import utils
1415

16+
CONF = config.CONF
1517
LOG = logging.getLogger(__name__)
1618

17-
_list_headers = ('ID', 'Date', 'Name', 'Submitter', 'State', 'Archived',
18-
'Delegate')
19-
_sort_fields = ('id', '-id', 'name', '-name', 'date', '-date')
19+
_list_headers = (
20+
'ID', 'Date', 'Name', 'Submitter', 'State', 'Archived', 'Delegate')
21+
_sort_fields = (
22+
'id', '-id', 'name', '-name', 'date', '-date')
23+
_default_states = (
24+
'new', 'under-review', 'accepted', 'rejected', 'rfc', 'not-applicable',
25+
'changes-requested', 'awaiting-upstream', 'superseded', 'deferred')
2026

2127

2228
@click.command(name='apply', context_settings=dict(
@@ -135,13 +141,18 @@ def show_cmd(fmt, patch_id):
135141
_show_patch(patch, fmt)
136142

137143

144+
def _get_states():
145+
return CONF.states.split(',') if CONF.states else _default_states
146+
147+
138148
@click.command(name='update')
139149
@click.argument('patch_ids', type=click.INT, nargs=-1, required=True)
140150
@click.option('--commit-ref', metavar='COMMIT_REF',
141151
help='Set the patch commit reference hash')
142-
@click.option('--state', metavar='STATE',
143-
help='Set the patch state. Should be a slugified representation '
144-
'of a state. The available states are instance dependant.')
152+
@click.option('--state', metavar='STATE', type=click.Choice(_get_states()),
153+
help="Set the patch state. Should be a slugified representation "
154+
"of a state. The available states are instance dependant and "
155+
"can be configured using 'git config pw.states'.")
145156
@click.option('--delegate', metavar='DELEGATE',
146157
help='Set the patch delegate. Should be unique user identifier: '
147158
'either a username or a user\'s email address.')

man/git-pw-bundle-apply.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW BUNDLE APPLY" "1" "21-Sep-2019" "1.7.0" "git-pw bundle apply Manual"
1+
.TH "GIT-PW BUNDLE APPLY" "1" "08-Dec-2019" "1.8.0" "git-pw bundle apply Manual"
22
.SH NAME
33
git-pw\-bundle\-apply \- Apply bundle.
44
.SH SYNOPSIS

man/git-pw-bundle-download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW BUNDLE DOWNLOAD" "1" "21-Sep-2019" "1.7.0" "git-pw bundle download Manual"
1+
.TH "GIT-PW BUNDLE DOWNLOAD" "1" "08-Dec-2019" "1.8.0" "git-pw bundle download Manual"
22
.SH NAME
33
git-pw\-bundle\-download \- Download bundle in mbox format.
44
.SH SYNOPSIS

man/git-pw-bundle-list.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW BUNDLE LIST" "1" "21-Sep-2019" "1.7.0" "git-pw bundle list Manual"
1+
.TH "GIT-PW BUNDLE LIST" "1" "08-Dec-2019" "1.8.0" "git-pw bundle list Manual"
22
.SH NAME
33
git-pw\-bundle\-list \- List bundles.
44
.SH SYNOPSIS

man/git-pw-bundle-show.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW BUNDLE SHOW" "1" "21-Sep-2019" "1.7.0" "git-pw bundle show Manual"
1+
.TH "GIT-PW BUNDLE SHOW" "1" "08-Dec-2019" "1.8.0" "git-pw bundle show Manual"
22
.SH NAME
33
git-pw\-bundle\-show \- Show information about bundle.
44
.SH SYNOPSIS

man/git-pw-bundle.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW BUNDLE" "1" "21-Sep-2019" "1.7.0" "git-pw bundle Manual"
1+
.TH "GIT-PW BUNDLE" "1" "08-Dec-2019" "1.8.0" "git-pw bundle Manual"
22
.SH NAME
33
git-pw\-bundle \- Interact with bundles.
44
.SH SYNOPSIS

man/git-pw-patch-apply.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW PATCH APPLY" "1" "21-Sep-2019" "1.7.0" "git-pw patch apply Manual"
1+
.TH "GIT-PW PATCH APPLY" "1" "08-Dec-2019" "1.8.0" "git-pw patch apply Manual"
22
.SH NAME
33
git-pw\-patch\-apply \- Apply patch.
44
.SH SYNOPSIS

man/git-pw-patch-download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "GIT-PW PATCH DOWNLOAD" "1" "21-Sep-2019" "1.7.0" "git-pw patch download Manual"
1+
.TH "GIT-PW PATCH DOWNLOAD" "1" "08-Dec-2019" "1.8.0" "git-pw patch download Manual"
22
.SH NAME
33
git-pw\-patch\-download \- Download patch in diff or mbox format.
44
.SH SYNOPSIS

0 commit comments

Comments
 (0)