Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5a4379

Browse files
JohnVillalovosnejch
authored andcommitted
fix(cli): generate UserWarning iflist does not return all entries
Previously in the CLI, calls to `list()` would have `get_all=False` bydefault. Therefore hiding the fact that not all items are beingreturned if there were more than 20 items.Added `--no-get-all` option to `list` actions. Along with the alreadyexisting `--get-all`.Closes:#2900
1 parent7d04315 commite5a4379

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

‎gitlab/client.py‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ def http_list(
869869
query_data:Optional[Dict[str,Any]]=None,
870870
*,
871871
iterator:Optional[bool]=None,
872+
message_details:Optional[utils.WarnMessageData]=None,
872873
**kwargs:Any,
873874
)->Union["GitlabList",List[Dict[str,Any]]]:
874875
"""Make a GET request to the Gitlab server for list-oriented queries.
@@ -952,16 +953,29 @@ def should_emit_warning() -> bool:
952953
# Warn the user that they are only going to retrieve `per_page`
953954
# maximum items. This is a common cause of issues filed.
954955
total_items="many"ifgl_list.totalisNoneelsegl_list.total
955-
utils.warn(
956-
message=(
956+
ifmessage_detailsisnotNone:
957+
message=message_details.message.format_map(
958+
{
959+
"len_items":len(items),
960+
"per_page":gl_list.per_page,
961+
"total_items":total_items,
962+
}
963+
)
964+
show_caller=message_details.show_caller
965+
else:
966+
message= (
957967
f"Calling a `list()` method without specifying `get_all=True` or "
958968
f"`iterator=True` will return a maximum of{gl_list.per_page} items. "
959969
f"Your query returned{len(items)} of{total_items} items. See "
960970
f"{_PAGINATION_URL} for more details. If this was done intentionally, "
961971
f"then this warning can be supressed by adding the argument "
962972
f"`get_all=False` to the `list()` call."
963-
),
973+
)
974+
show_caller=True
975+
utils.warn(
976+
message=message,
964977
category=UserWarning,
978+
show_caller=show_caller,
965979
)
966980
returnitems
967981

‎gitlab/utils.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importdataclasses
12
importemail.message
23
importlogging
34
importpathlib
@@ -205,3 +206,9 @@ def warn(
205206
stacklevel=stacklevel,
206207
source=source,
207208
)
209+
210+
211+
@dataclasses.dataclass
212+
classWarnMessageData:
213+
message:str
214+
show_caller:bool

‎gitlab/v4/cli.py‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importargparse
2+
importjson
23
importoperator
34
importsys
45
fromtypingimportAny,Dict,List,Optional,Type,TYPE_CHECKING,Union
@@ -140,8 +141,16 @@ def do_list(
140141
)->Union[gitlab.base.RESTObjectList,List[gitlab.base.RESTObject]]:
141142
ifTYPE_CHECKING:
142143
assertisinstance(self.mgr,gitlab.mixins.ListMixin)
144+
message_details=gitlab.utils.WarnMessageData(
145+
message=(
146+
"Your query returned {len_items} of {total_items} items. To return all "
147+
"items use `--get-all`. To silence this warning use `--no-get-all`."
148+
),
149+
show_caller=False,
150+
)
151+
143152
try:
144-
result=self.mgr.list(**self.args)
153+
result=self.mgr.list(**self.args,message_details=message_details)
145154
exceptExceptionase:# pragma: no cover, cli.die is unit-tested
146155
cli.die("Impossible to list objects",e)
147156
returnresult
@@ -238,12 +247,25 @@ def _populate_sub_parser_by_class(
238247

239248
sub_parser_action.add_argument("--page",required=False,type=int)
240249
sub_parser_action.add_argument("--per-page",required=False,type=int)
241-
sub_parser_action.add_argument(
250+
get_all_group=sub_parser_action.add_mutually_exclusive_group()
251+
get_all_group.add_argument(
242252
"--get-all",
243253
required=False,
244-
action="store_true",
254+
action="store_const",
255+
const=True,
256+
default=None,
257+
dest="get_all",
245258
help="Return all items from the server, without pagination.",
246259
)
260+
get_all_group.add_argument(
261+
"--no-get-all",
262+
required=False,
263+
action="store_const",
264+
const=False,
265+
default=None,
266+
dest="get_all",
267+
help="Don't return all items from the server.",
268+
)
247269

248270
ifaction_name=="delete":
249271
ifcls._id_attrisnotNone:
@@ -416,8 +438,6 @@ def get_dict(
416438
classJSONPrinter:
417439
@staticmethod
418440
defdisplay(d:Union[str,Dict[str,Any]],**_kwargs:Any)->None:
419-
importjson# noqa
420-
421441
print(json.dumps(d))
422442

423443
@staticmethod
@@ -426,8 +446,6 @@ def display_list(
426446
fields:List[str],
427447
**_kwargs:Any,
428448
)->None:
429-
importjson# noqa
430-
431449
print(json.dumps([get_dict(obj,fields)forobjindata]))
432450

433451

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp