Skip to content

Commit 7c71d5d

Browse files
nejchJohnVillalovos
authored andcommitted
fix: add get_all param (and --get-all) to allow passing all to API
1 parent 0549afa commit 7c71d5d

19 files changed

+158
-100
lines changed

docs/api-usage-advanced.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ supplying the ``obey_rate_limit`` argument.
9797
import requests
9898
9999
gl = gitlab.gitlab(url, token, api_version=4)
100-
gl.projects.list(all=True, obey_rate_limit=False)
100+
gl.projects.list(get_all=True, obey_rate_limit=False)
101101
102102
If you do not disable the rate-limiting feature, you can supply a custom value
103103
for ``max_retries``; by default, this is set to 10. To retry without bound when
@@ -110,7 +110,7 @@ throttled, you can set this parameter to -1. This parameter is ignored if
110110
import requests
111111
112112
gl = gitlab.gitlab(url, token, api_version=4)
113-
gl.projects.list(all=True, max_retries=12)
113+
gl.projects.list(get_all=True, max_retries=12)
114114
115115
.. warning::
116116

@@ -133,7 +133,7 @@ is raised for these errors.
133133
import requests
134134
135135
gl = gitlab.gitlab(url, token, api_version=4)
136-
gl.projects.list(all=True, retry_transient_errors=True)
136+
gl.projects.list(get_all=True, retry_transient_errors=True)
137137
138138
The default ``retry_transient_errors`` can also be set on the ``Gitlab`` object
139139
and overridden by individual API calls.
@@ -143,8 +143,8 @@ and overridden by individual API calls.
143143
import gitlab
144144
import requests
145145
gl = gitlab.gitlab(url, token, api_version=4, retry_transient_errors=True)
146-
gl.projects.list(all=True) # retries due to default value
147-
gl.projects.list(all=True, retry_transient_errors=False) # does not retry
146+
gl.projects.list(get_all=True) # retries due to default value
147+
gl.projects.list(get_all=True, retry_transient_errors=False) # does not retry
148148
149149
Timeout
150150
-------

docs/api-usage.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Examples:
110110
111111
.. warning::
112112
Calling ``list()`` without any arguments will by default not return the complete list
113-
of items. Use either the ``all=True`` or ``iterator=True`` parameters to get all the
113+
of items. Use either the ``get_all=True`` or ``iterator=True`` parameters to get all the
114114
items when using listing methods. See the :ref:`pagination` section for more
115115
information.
116116

@@ -144,7 +144,7 @@ Some objects also provide managers to access related GitLab resources:
144144
145145
# list the issues for a project
146146
project = gl.projects.get(1)
147-
issues = project.issues.list(all=True)
147+
issues = project.issues.list(get_all=True)
148148
149149
python-gitlab allows to send any data to the GitLab server when making queries.
150150
In case of invalid or missing arguments python-gitlab will raise an exception
@@ -314,13 +314,14 @@ listing methods support the ``page`` and ``per_page`` parameters:
314314

315315
The first page is page 1, not page 0.
316316

317-
By default GitLab does not return the complete list of items. Use the ``all``
317+
By default GitLab does not return the complete list of items. Use the ``get_all``
318318
parameter to get all the items when using listing methods:
319319

320320
.. code-block:: python
321321
322-
all_groups = gl.groups.list(all=True)
323-
all_owned_projects = gl.projects.list(owned=True, all=True)
322+
all_groups = gl.groups.list(get_all=True)
323+
324+
all_owned_projects = gl.projects.list(owned=True, get_all=True)
324325
325326
You can define the ``per_page`` value globally to avoid passing it to every
326327
``list()`` method call:

docs/cli-examples.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ List all the projects:
7676

7777
.. code-block:: console
7878
79-
$ gitlab project list --all
79+
$ gitlab project list --get-all
8080
8181
List all projects of a group:
8282

8383
.. code-block:: console
8484
85-
$ gitlab group-project list --all --group-id 1
85+
$ gitlab group-project list --get-all --group-id 1
8686
8787
List all projects of a group and its subgroups:
8888

8989
.. code-block:: console
9090
91-
$ gitlab group-project list --all --include-subgroups true --group-id 1
91+
$ gitlab group-project list --get-all --include-subgroups true --group-id 1
9292
9393
Limit to 5 items per request, display the 1st page only
9494

docs/faq.rst

+3
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ I get an ``AttributeError`` when accessing attributes after ``save()`` or ``refr
4848
You are most likely trying to access an attribute that was not returned
4949
by the server on the second request. Please look at the documentation in
5050
:ref:`object_attributes` to see how to avoid this.
51+
52+
I passed ``all=True`` (or ``--all`` via the CLI) to the API and I still cannot see all items returned.
53+
Use ``get_all=True`` (or ``--get-all`` via the CLI). See :ref:`pagination` for more details.

docs/gl_objects/commits.rst

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ results::
2727
commits = project.commits.list(ref_name='my_branch')
2828
commits = project.commits.list(since='2016-01-01T00:00:00Z')
2929

30-
.. note::
30+
List all commits for a project (see :ref:`pagination`) on all branches:
3131

32-
The available ``all`` listing argument conflicts with the python-gitlab
33-
argument. Use ``query_parameters`` to avoid the conflict::
34-
35-
commits = project.commits.list(all=True,
36-
query_parameters={'ref_name': 'my_branch'})
32+
commits = project.commits.list(get_all=True, all=True)
3733

3834
Create a commit::
3935

docs/gl_objects/groups.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ List only direct group members::
271271
List the group members recursively (including inherited members through
272272
ancestor groups)::
273273

274-
members = group.members_all.list(all=True)
274+
members = group.members_all.list(get_all=True)
275275

276276
Get only direct group member::
277277

docs/gl_objects/projects.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Results can also be sorted using the following parameters:
4040
::
4141

4242
# List all projects (default 20)
43-
projects = gl.projects.list(all=True)
43+
projects = gl.projects.list(get_all=True)
4444
# Archived projects
4545
projects = gl.projects.list(archived=1)
4646
# Limit to projects with a defined visibility
@@ -559,7 +559,7 @@ List only direct project members::
559559
List the project members recursively (including inherited members through
560560
ancestor groups)::
561561

562-
members = project.members_all.list(all=True)
562+
members = project.members_all.list(get_all=True)
563563

564564
Search project members matching a query string::
565565

docs/gl_objects/users.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,5 @@ Get the users activities::
454454

455455
activities = gl.user_activities.list(
456456
query_parameters={'from': '2018-07-01'},
457-
all=True, iterator=True)
457+
get_all=True,
458+
)

gitlab/client.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def http_list(
857857
Returns:
858858
A list of the objects returned by the server. If `iterator` is
859859
True and no pagination-related arguments (`page`, `per_page`,
860-
`all`) are defined then a GitlabList object (generator) is returned
860+
`get_all`) are defined then a GitlabList object (generator) is returned
861861
instead. This object will make API calls when needed to fetch the
862862
next items from the server.
863863
@@ -884,7 +884,13 @@ def http_list(
884884
category=DeprecationWarning,
885885
)
886886

887-
get_all = kwargs.pop("all", None)
887+
# Provide a `get_all`` param to avoid clashes with `all` API attributes.
888+
get_all = kwargs.pop("get_all", None)
889+
890+
if get_all is None:
891+
# For now, keep `all` without deprecation.
892+
get_all = kwargs.pop("all", None)
893+
888894
url = self._build_url(path)
889895

890896
page = kwargs.get("page")
@@ -902,7 +908,7 @@ def http_list(
902908

903909
def should_emit_warning() -> bool:
904910
# No warning is emitted if any of the following conditions apply:
905-
# * `all=False` was set in the `list()` call.
911+
# * `get_all=False` was set in the `list()` call.
906912
# * `page` was set in the `list()` call.
907913
# * GitLab did not return the `x-per-page` header.
908914
# * Number of items received is less than per-page value.
@@ -927,12 +933,12 @@ def should_emit_warning() -> bool:
927933
total_items = "many" if gl_list.total is None else gl_list.total
928934
utils.warn(
929935
message=(
930-
f"Calling a `list()` method without specifying `all=True` or "
936+
f"Calling a `list()` method without specifying `get_all=True` or "
931937
f"`iterator=True` will return a maximum of {gl_list.per_page} items. "
932938
f"Your query returned {len(items)} of {total_items} items. See "
933939
f"{_PAGINATION_URL} for more details. If this was done intentionally, "
934940
f"then this warning can be supressed by adding the argument "
935-
f"`all=False` to the `list()` call."
941+
f"`get_all=False` to the `list()` call."
936942
),
937943
category=UserWarning,
938944
)

gitlab/v4/cli.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,18 @@ def _populate_sub_parser_by_class(
240240

241241
sub_parser_action.add_argument("--page", required=False, type=int)
242242
sub_parser_action.add_argument("--per-page", required=False, type=int)
243-
sub_parser_action.add_argument("--all", required=False, action="store_true")
243+
sub_parser_action.add_argument(
244+
"--get-all",
245+
required=False,
246+
action="store_true",
247+
help="Return all items from the server, without pagination.",
248+
)
249+
sub_parser_action.add_argument(
250+
"--all",
251+
required=False,
252+
action="store_true",
253+
help="Deprecated. Use --get-all instead.",
254+
)
244255

245256
if action_name == "delete":
246257
if cls._id_attr is not None:

tests/functional/api/test_gitlab.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_broadcast_messages(gl):
1818
msg.save()
1919
msg_id = msg.id
2020

21-
msg = gl.broadcastmessages.list(all=True)[0]
21+
msg = gl.broadcastmessages.list(get_all=True)[0]
2222
assert msg.color == "#444444"
2323

2424
msg = gl.broadcastmessages.get(msg_id)
@@ -86,13 +86,13 @@ def test_template_dockerfile(gl):
8686

8787

8888
def test_template_gitignore(gl):
89-
assert gl.gitignores.list(all=True)
89+
assert gl.gitignores.list(get_all=True)
9090
gitignore = gl.gitignores.get("Node")
9191
assert gitignore.content is not None
9292

9393

9494
def test_template_gitlabciyml(gl):
95-
assert gl.gitlabciymls.list(all=True)
95+
assert gl.gitlabciymls.list(get_all=True)
9696
gitlabciyml = gl.gitlabciymls.get("Nodejs")
9797
assert gitlabciyml.content is not None
9898

@@ -114,10 +114,10 @@ def test_hooks(gl):
114114

115115

116116
def test_namespaces(gl):
117-
namespace = gl.namespaces.list(all=True)
117+
namespace = gl.namespaces.list(get_all=True)
118118
assert namespace
119119

120-
namespace = gl.namespaces.list(search="root", all=True)[0]
120+
namespace = gl.namespaces.list(search="root", get_all=True)[0]
121121
assert namespace.kind == "user"
122122

123123

@@ -217,8 +217,8 @@ def test_list_all_false_nowarning(gl, recwarn):
217217

218218

219219
def test_list_all_true_nowarning(gl, recwarn):
220-
"""Using `all=True` will disable the warning"""
221-
items = gl.gitlabciymls.list(all=True)
220+
"""Using `get_all=True` will disable the warning"""
221+
items = gl.gitlabciymls.list(get_all=True)
222222
assert not recwarn
223223
assert len(items) > 20
224224

tests/functional/api/test_repository.py

+20
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ def test_create_commit(project):
105105
assert isinstance(commit.merge_requests(), list)
106106

107107

108+
def test_list_all_commits(project):
109+
data = {
110+
"branch": "new-branch",
111+
"start_branch": "main",
112+
"commit_message": "New commit on new branch",
113+
"actions": [
114+
{"action": "create", "file_path": "new-file", "content": "new content"}
115+
],
116+
}
117+
commit = project.commits.create(data)
118+
119+
commits = project.commits.list(all=True)
120+
assert commit not in commits
121+
122+
# Listing commits on other branches requires `all` parameter passed to the API
123+
all_commits = project.commits.list(get_all=True, all=True)
124+
assert commit in all_commits
125+
assert len(all_commits) > len(commits)
126+
127+
108128
def test_create_commit_status(project):
109129
commit = project.commits.list()[0]
110130
status = commit.statuses.create({"state": "success", "sha": commit.id})

tests/functional/api/test_snippets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def test_snippets(gl):
5-
snippets = gl.snippets.list(all=True)
5+
snippets = gl.snippets.list(get_all=True)
66
assert not snippets
77

88
snippet = gl.snippets.create(
@@ -20,7 +20,7 @@ def test_snippets(gl):
2020
assert snippet.user_agent_detail()["user_agent"]
2121

2222
snippet.delete()
23-
assert snippet not in gl.snippets.list(all=True)
23+
assert snippet not in gl.snippets.list(get_all=True)
2424

2525

2626
def test_project_snippets(project):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
def test_project_create_file(gitlab_cli, project):
2+
file_path = "README"
3+
branch = "main"
4+
content = "CONTENT"
5+
commit_message = "Initial commit"
6+
7+
cmd = [
8+
"project-file",
9+
"create",
10+
"--project-id",
11+
project.id,
12+
"--file-path",
13+
file_path,
14+
"--branch",
15+
branch,
16+
"--content",
17+
content,
18+
"--commit-message",
19+
commit_message,
20+
]
21+
ret = gitlab_cli(cmd)
22+
23+
assert ret.success
24+
25+
26+
def test_list_all_commits(gitlab_cli, project):
27+
data = {
28+
"branch": "new-branch",
29+
"start_branch": "main",
30+
"commit_message": "New commit on new branch",
31+
"actions": [
32+
{"action": "create", "file_path": "new-file", "content": "new content"}
33+
],
34+
}
35+
commit = project.commits.create(data)
36+
37+
cmd = ["project-commit", "list", "--project-id", project.id, "--get-all"]
38+
ret = gitlab_cli(cmd)
39+
assert commit.id not in ret.stdout
40+
41+
# Listing commits on other branches requires `all` parameter passed to the API
42+
cmd = ["project-commit", "list", "--project-id", project.id, "--get-all", "--all"]
43+
ret_all = gitlab_cli(cmd)
44+
assert commit.id in ret_all.stdout
45+
assert len(ret_all.stdout) > len(ret.stdout)
46+
47+
48+
def test_revert_commit(gitlab_cli, project):
49+
commit = project.commits.list()[0]
50+
51+
cmd = [
52+
"project-commit",
53+
"revert",
54+
"--project-id",
55+
project.id,
56+
"--id",
57+
commit.id,
58+
"--branch",
59+
"main",
60+
]
61+
ret = gitlab_cli(cmd)
62+
63+
assert ret.success
64+
65+
66+
def test_get_commit_signature_not_found(gitlab_cli, project):
67+
commit = project.commits.list()[0]
68+
69+
cmd = ["project-commit", "signature", "--project-id", project.id, "--id", commit.id]
70+
ret = gitlab_cli(cmd)
71+
72+
assert not ret.success
73+
assert "404 Signature Not Found" in ret.stderr

0 commit comments

Comments
 (0)