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

Commitc86e471

Browse files
chore: renamewhat togitlab_resource
Naming a variable `what` makes it difficult to understand what it isused for.Rename it to `gitlab_resource` as that is what is being stored.The Gitlab documentation talks about them being resources:https://docs.gitlab.com/ee/api/api_resources.htmlThis will improve code readability.
1 parent6189437 commitc86e471

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

‎gitlab/cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ def die(msg: str, e: Optional[Exception] = None) -> None:
9191
sys.exit(1)
9292

9393

94-
defwhat_to_cls(what:str,namespace:ModuleType)->Type[RESTObject]:
94+
defgitlab_resource_to_cls(
95+
gitlab_resource:str,namespace:ModuleType
96+
)->Type[RESTObject]:
9597
classes=CaseInsensitiveDict(namespace.__dict__)
96-
lowercase_class=what.replace("-","")
98+
lowercase_class=gitlab_resource.replace("-","")
9799

98100
returnclasses[lowercase_class]
99101

100102

101-
defcls_to_what(cls:RESTObject)->str:
103+
defcls_to_gitlab_resource(cls:RESTObject)->str:
102104
dasherized_uppercase=camel_upperlower_regex.sub(r"\1-\2",cls.__name__)
103105
dasherized_lowercase=camel_lowerupper_regex.sub(r"\1-\2",dasherized_uppercase)
104106
returndasherized_lowercase.lower()
@@ -322,7 +324,7 @@ def main() -> None:
322324
fields= [x.strip()forxinargs.fields.split(",")]
323325
debug=args.debug
324326
action=args.whaction
325-
what=args.what
327+
gitlab_resource=args.gitlab_resource
326328

327329
args_dict=vars(args)
328330
# Remove CLI behavior-related args
@@ -331,7 +333,7 @@ def main() -> None:
331333
"config_file",
332334
"verbose",
333335
"debug",
334-
"what",
336+
"gitlab_resource",
335337
"whaction",
336338
"version",
337339
"output",
@@ -359,4 +361,4 @@ def main() -> None:
359361
ifdebug:
360362
gl.enable_debug()
361363

362-
gitlab.v4.cli.run(gl,what,action,args_dict,verbose,output,fields)
364+
gitlab.v4.cli.run(gl,gitlab_resource,action,args_dict,verbose,output,fields)

‎gitlab/v4/cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929

3030
classGitlabCLI:
3131
def__init__(
32-
self,gl:gitlab.Gitlab,what:str,action:str,args:Dict[str,str]
32+
self,gl:gitlab.Gitlab,gitlab_resource:str,action:str,args:Dict[str,str]
3333
)->None:
34-
self.cls:Type[gitlab.base.RESTObject]=cli.what_to_cls(
35-
what,namespace=gitlab.v4.objects
34+
self.cls:Type[gitlab.base.RESTObject]=cli.gitlab_resource_to_cls(
35+
gitlab_resource,namespace=gitlab.v4.objects
3636
)
3737
self.cls_name=self.cls.__name__
38-
self.what=what.replace("-","_")
38+
self.gitlab_resource=gitlab_resource.replace("-","_")
3939
self.action=action.lower()
4040
self.gl=gl
4141
self.args=args
@@ -81,7 +81,7 @@ def _process_from_parent_attrs(self) -> None:
8181

8282
defrun(self)->Any:
8383
# Check for a method that matches object + action
84-
method=f"do_{self.what}_{self.action}"
84+
method=f"do_{self.gitlab_resource}_{self.action}"
8585
ifhasattr(self,method):
8686
returngetattr(self,method)()
8787

@@ -333,7 +333,7 @@ def _populate_sub_parser_by_class(
333333

334334
defextend_parser(parser:argparse.ArgumentParser)->argparse.ArgumentParser:
335335
subparsers=parser.add_subparsers(
336-
title="object",dest="what",help="Object to manipulate."
336+
title="object",dest="gitlab_resource",help="Object to manipulate."
337337
)
338338
subparsers.required=True
339339

@@ -347,7 +347,7 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
347347
classes.add(cls._obj_cls)
348348

349349
forclsinsorted(classes,key=operator.attrgetter("__name__")):
350-
arg_name=cli.cls_to_what(cls)
350+
arg_name=cli.cls_to_gitlab_resource(cls)
351351
object_group=subparsers.add_parser(arg_name)
352352

353353
object_subparsers=object_group.add_subparsers(
@@ -497,14 +497,14 @@ def display_list(
497497

498498
defrun(
499499
gl:gitlab.Gitlab,
500-
what:str,
500+
gitlab_resource:str,
501501
action:str,
502502
args:Dict[str,Any],
503503
verbose:bool,
504504
output:str,
505505
fields:List[str],
506506
)->None:
507-
g_cli=GitlabCLI(gl=gl,what=what,action=action,args=args)
507+
g_cli=GitlabCLI(gl=gl,gitlab_resource=gitlab_resource,action=action,args=args)
508508
data=g_cli.run()
509509

510510
printer:Union[JSONPrinter,LegacyPrinter,YAMLPrinter]=PRINTERS[output]()

‎tests/unit/test_cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
@pytest.mark.parametrize(
32-
"what,expected_class",
32+
"gitlab_resource,expected_class",
3333
[
3434
("class","Class"),
3535
("test-class","TestClass"),
@@ -39,18 +39,18 @@
3939
("ldap-group","LDAPGroup"),
4040
],
4141
)
42-
deftest_what_to_cls(what,expected_class):
42+
deftest_gitlab_resource_to_cls(gitlab_resource,expected_class):
4343
def_namespace():
4444
pass
4545

4646
ExpectedClass=type(expected_class, (), {})
4747
_namespace.__dict__[expected_class]=ExpectedClass
4848

49-
assertcli.what_to_cls(what,_namespace)==ExpectedClass
49+
assertcli.gitlab_resource_to_cls(gitlab_resource,_namespace)==ExpectedClass
5050

5151

5252
@pytest.mark.parametrize(
53-
"class_name,expected_what",
53+
"class_name,expected_gitlab_resource",
5454
[
5555
("Class","class"),
5656
("TestClass","test-class"),
@@ -61,10 +61,10 @@ def _namespace():
6161
("LDAPGroup","ldap-group"),
6262
],
6363
)
64-
deftest_cls_to_what(class_name,expected_what):
64+
deftest_cls_to_gitlab_resource(class_name,expected_gitlab_resource):
6565
TestClass=type(class_name, (), {})
6666

67-
assertcli.cls_to_what(TestClass)==expected_what
67+
assertcli.cls_to_gitlab_resource(TestClass)==expected_gitlab_resource
6868

6969

7070
@pytest.mark.parametrize(
@@ -125,7 +125,7 @@ def test_base_parser():
125125
deftest_v4_parse_args():
126126
parser=cli._get_parser()
127127
args=parser.parse_args(["project","list"])
128-
assertargs.what=="project"
128+
assertargs.gitlab_resource=="project"
129129
assertargs.whaction=="list"
130130

131131

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp