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

Appearance settings

Commit 7270523

Browse filesBrowse files
chore: require keyword arguments for register_custom_action
This makes it more obvious when reading the code what each argument is for.
1 parent 623dac9 commit 7270523
Copy full SHA for 7270523
Expand file treeCollapse file tree

29 files changed

+177
-141
lines changed
Open diff view settings
Collapse file

‎gitlab/cli.py‎

Copy file name to clipboardExpand all lines: gitlab/cli.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def format_help(self) -> str:
7272

7373

7474
def register_custom_action(
75+
*,
7576
cls_names: Union[str, Tuple[str, ...]],
76-
mandatory: Tuple[str, ...] = (),
77+
required: Tuple[str, ...] = (),
7778
optional: Tuple[str, ...] = (),
7879
custom_action: Optional[str] = None,
7980
) -> Callable[[__F], __F]:
@@ -98,7 +99,7 @@ def wrapped_f(*args: Any, **kwargs: Any) -> Any:
9899
custom_actions[final_name] = {}
99100

100101
action = custom_action or f.__name__.replace("_", "-")
101-
custom_actions[final_name][action] = (mandatory, optional, in_obj)
102+
custom_actions[final_name][action] = (required, optional, in_obj)
102103

103104
return cast(__F, wrapped_f)
104105

Collapse file

‎gitlab/mixins.py‎

Copy file name to clipboardExpand all lines: gitlab/mixins.py
+22-14Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class UserAgentDetailMixin(_RestObjectBase):
550550
_updated_attrs: Dict[str, Any]
551551
manager: base.RESTManager
552552

553-
@cli.register_custom_action(("Snippet", "ProjectSnippet", "ProjectIssue"))
553+
@cli.register_custom_action(cls_names=("Snippet", "ProjectSnippet", "ProjectIssue"))
554554
@exc.on_http_error(exc.GitlabGetError)
555555
def user_agent_detail(self, **kwargs: Any) -> Dict[str, Any]:
556556
"""Get the user agent detail.
@@ -578,7 +578,8 @@ class AccessRequestMixin(_RestObjectBase):
578578
manager: base.RESTManager
579579

580580
@cli.register_custom_action(
581-
("ProjectAccessRequest", "GroupAccessRequest"), (), ("access_level",)
581+
cls_names=("ProjectAccessRequest", "GroupAccessRequest"),
582+
optional=("access_level",),
582583
)
583584
@exc.on_http_error(exc.GitlabUpdateError)
584585
def approve(
@@ -611,7 +612,7 @@ class DownloadMixin(_RestObjectBase):
611612
_updated_attrs: Dict[str, Any]
612613
manager: base.RESTManager
613614

614-
@cli.register_custom_action(("GroupExport", "ProjectExport"))
615+
@cli.register_custom_action(cls_names=("GroupExport", "ProjectExport"))
615616
@exc.on_http_error(exc.GitlabGetError)
616617
def download(
617618
self,
@@ -721,7 +722,7 @@ class SubscribableMixin(_RestObjectBase):
721722
manager: base.RESTManager
722723

723724
@cli.register_custom_action(
724-
("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel")
725+
cls_names=("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel")
725726
)
726727
@exc.on_http_error(exc.GitlabSubscribeError)
727728
def subscribe(self, **kwargs: Any) -> None:
@@ -741,7 +742,7 @@ def subscribe(self, **kwargs: Any) -> None:
741742
self._update_attrs(server_data)
742743

743744
@cli.register_custom_action(
744-
("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel")
745+
cls_names=("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel")
745746
)
746747
@exc.on_http_error(exc.GitlabUnsubscribeError)
747748
def unsubscribe(self, **kwargs: Any) -> None:
@@ -769,7 +770,7 @@ class TodoMixin(_RestObjectBase):
769770
_updated_attrs: Dict[str, Any]
770771
manager: base.RESTManager
771772

772-
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"))
773+
@cli.register_custom_action(cls_names=("ProjectIssue", "ProjectMergeRequest"))
773774
@exc.on_http_error(exc.GitlabTodoError)
774775
def todo(self, **kwargs: Any) -> None:
775776
"""Create a todo associated to the object.
@@ -793,7 +794,7 @@ class TimeTrackingMixin(_RestObjectBase):
793794
_updated_attrs: Dict[str, Any]
794795
manager: base.RESTManager
795796

796-
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"))
797+
@cli.register_custom_action(cls_names=("ProjectIssue", "ProjectMergeRequest"))
797798
@exc.on_http_error(exc.GitlabTimeTrackingError)
798799
def time_stats(self, **kwargs: Any) -> Dict[str, Any]:
799800
"""Get time stats for the object.
@@ -819,7 +820,9 @@ def time_stats(self, **kwargs: Any) -> Dict[str, Any]:
819820
assert not isinstance(result, requests.Response)
820821
return result
821822

822-
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"), ("duration",))
823+
@cli.register_custom_action(
824+
cls_names=("ProjectIssue", "ProjectMergeRequest"), required=("duration",)
825+
)
823826
@exc.on_http_error(exc.GitlabTimeTrackingError)
824827
def time_estimate(self, duration: str, **kwargs: Any) -> Dict[str, Any]:
825828
"""Set an estimated time of work for the object.
@@ -839,7 +842,7 @@ def time_estimate(self, duration: str, **kwargs: Any) -> Dict[str, Any]:
839842
assert not isinstance(result, requests.Response)
840843
return result
841844

842-
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"))
845+
@cli.register_custom_action(cls_names=("ProjectIssue", "ProjectMergeRequest"))
843846
@exc.on_http_error(exc.GitlabTimeTrackingError)
844847
def reset_time_estimate(self, **kwargs: Any) -> Dict[str, Any]:
845848
"""Resets estimated time for the object to 0 seconds.
@@ -857,7 +860,9 @@ def reset_time_estimate(self, **kwargs: Any) -> Dict[str, Any]:
857860
assert not isinstance(result, requests.Response)
858861
return result
859862

860-
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"), ("duration",))
863+
@cli.register_custom_action(
864+
cls_names=("ProjectIssue", "ProjectMergeRequest"), required=("duration",)
865+
)
861866
@exc.on_http_error(exc.GitlabTimeTrackingError)
862867
def add_spent_time(self, duration: str, **kwargs: Any) -> Dict[str, Any]:
863868
"""Add time spent working on the object.
@@ -877,7 +882,7 @@ def add_spent_time(self, duration: str, **kwargs: Any) -> Dict[str, Any]:
877882
assert not isinstance(result, requests.Response)
878883
return result
879884

880-
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"))
885+
@cli.register_custom_action(cls_names=("ProjectIssue", "ProjectMergeRequest"))
881886
@exc.on_http_error(exc.GitlabTimeTrackingError)
882887
def reset_spent_time(self, **kwargs: Any) -> Dict[str, Any]:
883888
"""Resets the time spent working on the object.
@@ -904,7 +909,7 @@ class ParticipantsMixin(_RestObjectBase):
904909
_updated_attrs: Dict[str, Any]
905910
manager: base.RESTManager
906911

907-
@cli.register_custom_action(("ProjectMergeRequest", "ProjectIssue"))
912+
@cli.register_custom_action(cls_names=("ProjectMergeRequest", "ProjectIssue"))
908913
@exc.on_http_error(exc.GitlabListError)
909914
def participants(self, **kwargs: Any) -> Dict[str, Any]:
910915
"""List the participants.
@@ -932,7 +937,8 @@ def participants(self, **kwargs: Any) -> Dict[str, Any]:
932937

933938
class BadgeRenderMixin(_RestManagerBase):
934939
@cli.register_custom_action(
935-
("GroupBadgeManager", "ProjectBadgeManager"), ("link_url", "image_url")
940+
cls_names=("GroupBadgeManager", "ProjectBadgeManager"),
941+
required=("link_url", "image_url"),
936942
)
937943
@exc.on_http_error(exc.GitlabRenderError)
938944
def render(self, link_url: str, image_url: str, **kwargs: Any) -> Dict[str, Any]:
@@ -1025,7 +1031,9 @@ def _get_upload_path(self) -> str:
10251031
data = self.attributes
10261032
return self._upload_path.format(**data)
10271033

1028-
@cli.register_custom_action(("Project", "ProjectWiki"), ("filename", "filepath"))
1034+
@cli.register_custom_action(
1035+
cls_names=("Project", "ProjectWiki"), required=("filename", "filepath")
1036+
)
10291037
@exc.on_http_error(exc.GitlabUploadError)
10301038
def upload(
10311039
self,
Collapse file

‎gitlab/v4/objects/artifacts.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/artifacts.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def delete(self, **kwargs: Any) -> None:
4444
self.gitlab.http_delete(path, **kwargs)
4545

4646
@cli.register_custom_action(
47-
"ProjectArtifactManager", ("ref_name", "job"), ("job_token",)
47+
cls_names="ProjectArtifactManager",
48+
required=("ref_name", "job"),
49+
optional=("job_token",),
4850
)
4951
@exc.on_http_error(exc.GitlabGetError)
5052
def download(
@@ -93,7 +95,8 @@ def download(
9395
)
9496

9597
@cli.register_custom_action(
96-
"ProjectArtifactManager", ("ref_name", "artifact_path", "job")
98+
cls_names="ProjectArtifactManager",
99+
required=("ref_name", "artifact_path", "job"),
97100
)
98101
@exc.on_http_error(exc.GitlabGetError)
99102
def raw(
Collapse file

‎gitlab/v4/objects/ci_lint.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/ci_lint.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class CiLintManager(CreateMixin, RESTManager):
3131
)
3232

3333
@register_custom_action(
34-
"CiLintManager",
35-
("content",),
34+
cls_names="CiLintManager",
35+
required=("content",),
3636
optional=("include_merged_yaml", "include_jobs"),
3737
)
3838
def validate(self, *args: Any, **kwargs: Any) -> None:
@@ -63,8 +63,8 @@ def get(self, **kwargs: Any) -> ProjectCiLint:
6363
return cast(ProjectCiLint, super().get(**kwargs))
6464

6565
@register_custom_action(
66-
"ProjectCiLintManager",
67-
("content",),
66+
cls_names="ProjectCiLintManager",
67+
required=("content",),
6868
optional=("dry_run", "include_jobs", "ref"),
6969
)
7070
def validate(self, *args: Any, **kwargs: Any) -> None:
Collapse file

‎gitlab/v4/objects/commits.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/commits.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ProjectCommit(RESTObject):
2828
discussions: ProjectCommitDiscussionManager
2929
statuses: "ProjectCommitStatusManager"
3030

31-
@cli.register_custom_action("ProjectCommit")
31+
@cli.register_custom_action(cls_names="ProjectCommit")
3232
@exc.on_http_error(exc.GitlabGetError)
3333
def diff(self, **kwargs: Any) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
3434
"""Generate the commit diff.
@@ -46,7 +46,7 @@ def diff(self, **kwargs: Any) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
4646
path = f"{self.manager.path}/{self.encoded_id}/diff"
4747
return self.manager.gitlab.http_list(path, **kwargs)
4848

49-
@cli.register_custom_action("ProjectCommit", ("branch",))
49+
@cli.register_custom_action(cls_names="ProjectCommit", required=("branch",))
5050
@exc.on_http_error(exc.GitlabCherryPickError)
5151
def cherry_pick(self, branch: str, **kwargs: Any) -> None:
5252
"""Cherry-pick a commit into a branch.
@@ -63,7 +63,7 @@ def cherry_pick(self, branch: str, **kwargs: Any) -> None:
6363
post_data = {"branch": branch}
6464
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
6565

66-
@cli.register_custom_action("ProjectCommit", optional=("type",))
66+
@cli.register_custom_action(cls_names="ProjectCommit", optional=("type",))
6767
@exc.on_http_error(exc.GitlabGetError)
6868
def refs(
6969
self, type: str = "all", **kwargs: Any
@@ -85,7 +85,7 @@ def refs(
8585
query_data = {"type": type}
8686
return self.manager.gitlab.http_list(path, query_data=query_data, **kwargs)
8787

88-
@cli.register_custom_action("ProjectCommit")
88+
@cli.register_custom_action(cls_names="ProjectCommit")
8989
@exc.on_http_error(exc.GitlabGetError)
9090
def merge_requests(
9191
self, **kwargs: Any
@@ -105,7 +105,7 @@ def merge_requests(
105105
path = f"{self.manager.path}/{self.encoded_id}/merge_requests"
106106
return self.manager.gitlab.http_list(path, **kwargs)
107107

108-
@cli.register_custom_action("ProjectCommit", ("branch",))
108+
@cli.register_custom_action(cls_names="ProjectCommit", required=("branch",))
109109
@exc.on_http_error(exc.GitlabRevertError)
110110
def revert(
111111
self, branch: str, **kwargs: Any
@@ -127,7 +127,7 @@ def revert(
127127
post_data = {"branch": branch}
128128
return self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
129129

130-
@cli.register_custom_action("ProjectCommit")
130+
@cli.register_custom_action(cls_names="ProjectCommit")
131131
@exc.on_http_error(exc.GitlabGetError)
132132
def signature(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
133133
"""Get the signature of the commit.
Collapse file

‎gitlab/v4/objects/container_registry.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/container_registry.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class ProjectRegistryTagManager(DeleteMixin, RetrieveMixin, RESTManager):
4242
_path = "/projects/{project_id}/registry/repositories/{repository_id}/tags"
4343

4444
@cli.register_custom_action(
45-
"ProjectRegistryTagManager",
46-
("name_regex_delete",),
45+
cls_names="ProjectRegistryTagManager",
46+
required=("name_regex_delete",),
4747
optional=("keep_n", "name_regex_keep", "older_than"),
4848
)
4949
@exc.on_http_error(exc.GitlabDeleteError)
Collapse file

‎gitlab/v4/objects/deploy_keys.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/deploy_keys.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ProjectKeyManager(CRUDMixin, RESTManager):
3636
_create_attrs = RequiredOptional(required=("title", "key"), optional=("can_push",))
3737
_update_attrs = RequiredOptional(optional=("title", "can_push"))
3838

39-
@cli.register_custom_action("ProjectKeyManager", ("key_id",))
39+
@cli.register_custom_action(cls_names="ProjectKeyManager", required=("key_id",))
4040
@exc.on_http_error(exc.GitlabProjectDeployKeyError)
4141
def enable(
4242
self, key_id: int, **kwargs: Any
Collapse file

‎gitlab/v4/objects/deployments.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/deployments.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class ProjectDeployment(SaveMixin, RESTObject):
2323
mergerequests: ProjectDeploymentMergeRequestManager
2424

2525
@cli.register_custom_action(
26-
"ProjectDeployment",
27-
mandatory=("status",),
26+
cls_names="ProjectDeployment",
27+
required=("status",),
2828
optional=("comment", "represented_as"),
2929
)
3030
@exc.on_http_error(exc.GitlabDeploymentApprovalError)
Collapse file

‎gitlab/v4/objects/environments.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/environments.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
class ProjectEnvironment(SaveMixin, ObjectDeleteMixin, RESTObject):
27-
@cli.register_custom_action("ProjectEnvironment")
27+
@cli.register_custom_action(cls_names="ProjectEnvironment")
2828
@exc.on_http_error(exc.GitlabStopError)
2929
def stop(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
3030
"""Stop the environment.
Collapse file

‎gitlab/v4/objects/files.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/files.py
+14-7Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
109109
optional=("encoding", "author_email", "author_name"),
110110
)
111111

112-
@cli.register_custom_action("ProjectFileManager", ("file_path", "ref"))
112+
@cli.register_custom_action(
113+
cls_names="ProjectFileManager", required=("file_path", "ref")
114+
)
113115
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
114116
# type error
115117
def get( # type: ignore
@@ -132,9 +134,9 @@ def get( # type: ignore
132134
return cast(ProjectFile, GetMixin.get(self, file_path, ref=ref, **kwargs))
133135

134136
@cli.register_custom_action(
135-
"ProjectFileManager",
136-
("file_path", "branch", "content", "commit_message"),
137-
("encoding", "author_email", "author_name"),
137+
cls_names="ProjectFileManager",
138+
required=("file_path", "branch", "content", "commit_message"),
139+
optional=("encoding", "author_email", "author_name"),
138140
)
139141
@exc.on_http_error(exc.GitlabCreateError)
140142
def create(
@@ -199,7 +201,8 @@ def update( # type: ignore
199201
return result
200202

201203
@cli.register_custom_action(
202-
"ProjectFileManager", ("file_path", "branch", "commit_message")
204+
cls_names="ProjectFileManager",
205+
required=("file_path", "branch", "commit_message"),
203206
)
204207
@exc.on_http_error(exc.GitlabDeleteError)
205208
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
@@ -224,7 +227,9 @@ def delete( # type: ignore
224227
data = {"branch": branch, "commit_message": commit_message}
225228
self.gitlab.http_delete(path, query_data=data, **kwargs)
226229

227-
@cli.register_custom_action("ProjectFileManager", ("file_path", "ref"))
230+
@cli.register_custom_action(
231+
cls_names="ProjectFileManager", required=("file_path", "ref")
232+
)
228233
@exc.on_http_error(exc.GitlabGetError)
229234
def raw(
230235
self,
@@ -271,7 +276,9 @@ def raw(
271276
result, streamed, action, chunk_size, iterator=iterator
272277
)
273278

274-
@cli.register_custom_action("ProjectFileManager", ("file_path", "ref"))
279+
@cli.register_custom_action(
280+
cls_names="ProjectFileManager", required=("file_path", "ref")
281+
)
275282
@exc.on_http_error(exc.GitlabListError)
276283
def blame(self, file_path: str, ref: str, **kwargs: Any) -> List[Dict[str, Any]]:
277284
"""Return the content of a file for a commit.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.