Skip to content

Commit aed0cc6

Browse files
committed
Require project configuration
99% of users are going to want to filter on a specific project. Make life easier for these folks by altering them to potential misconfigurations. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 7d78698 commit aed0cc6

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

git_pw/api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ def _get_server(): # type: () -> str
6060
sys.exit(1)
6161

6262

63+
def _get_project(): # type: () -> str
64+
if CONF.project and CONF.project.strip() == '*':
65+
return '' # just don't bother filtering on project
66+
elif CONF.project:
67+
return CONF.project.strip()
68+
else:
69+
LOG.error('Project information missing')
70+
LOG.error('You must provide project information via git-config or '
71+
'via --project')
72+
LOG.error('To list all projects, set project to "*"')
73+
sys.exit(1)
74+
75+
6376
def get(url, params=None): # type: (str, dict) -> requests.Response
6477
"""Make GET request and handle errors."""
6578
LOG.debug('GET %s', url)
@@ -131,6 +144,11 @@ def index(resource_type, params=None): # type: (str, dict) -> dict
131144
# NOTE(stephenfin): All resources must have a trailing '/'
132145
url = '/'.join([_get_server(), 'api', resource_type, ''])
133146

147+
# NOTE(stephenfin): Not all endpoints in the Patchwork API allow filtering
148+
# by project, but all the ones we care about here do.
149+
params = params or []
150+
params.append(('project', _get_project()))
151+
134152
return get(url, params).json()
135153

136154

git_pw/bundle.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
from tabulate import tabulate
1111

1212
from git_pw import api
13-
from git_pw import config
1413
from git_pw import utils
1514

16-
CONF = config.CONF
1715
LOG = logging.getLogger(__name__)
1816

1917

@@ -122,7 +120,6 @@ def list_cmd(owner, limit, page, sort, name):
122120

123121
params.extend([
124122
('q', name),
125-
('project', CONF.project),
126123
('page', page),
127124
('per_page', limit),
128125
('order', sort),

git_pw/patch.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
from tabulate import tabulate
1212

1313
from git_pw import api
14-
from git_pw import config
1514
from git_pw import utils
1615

17-
CONF = config.CONF
1816
LOG = logging.getLogger(__name__)
1917

2018

@@ -224,7 +222,6 @@ def list_cmd(state, submitter, delegate, archived, limit, page, sort, name):
224222

225223
params.extend([
226224
('q', name),
227-
('project', CONF.project),
228225
# TODO(stephenfin): Perhaps we could use string values. Refer to
229226
# https://github.com/carltongibson/django-filter/pull/378
230227
('archived', 3 if archived else 1),

git_pw/series.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
from tabulate import tabulate
1212

1313
from git_pw import api
14-
from git_pw import config
1514
from git_pw import utils
1615

17-
CONF = config.CONF
1816
LOG = logging.getLogger(__name__)
1917

2018

@@ -131,7 +129,6 @@ def list_cmd(submitter, limit, page, sort, name):
131129

132130
params.extend([
133131
('q', name),
134-
('project', CONF.project),
135132
('page', page),
136133
('per_page', limit),
137134
('order', sort),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
upgrade:
3+
- |
4+
Project configuration, e.g. via ``git config pw.project``, is now required.
5+
Previously, not configuring a project would result in items for for all
6+
projects being listed. This did not scale for larger instances such as
7+
`patchwork.ozlabs.org` and proved confusing for some users. If this
8+
functionality is required, you must explicitly request it using the ``*``
9+
character, e.g. ``git pw patch list --project='*'``.

0 commit comments

Comments
 (0)