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

Commite8884f2

Browse files
chore: add type-hints to gitlab/v4/objects/jobs.py
1 parent93e39a2 commite8884f2

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

‎gitlab/v4/objects/jobs.py

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
fromtypingimportAny,Callable,cast,Dict,Optional,TYPE_CHECKING,Union
2+
3+
importrequests
4+
15
fromgitlabimportcli
26
fromgitlabimportexceptionsasexc
37
fromgitlabimportutils
@@ -13,7 +17,7 @@
1317
classProjectJob(RefreshMixin,RESTObject):
1418
@cli.register_custom_action("ProjectJob")
1519
@exc.on_http_error(exc.GitlabJobCancelError)
16-
defcancel(self,**kwargs):
20+
defcancel(self,**kwargs:Any)->Dict[str,Any]:
1721
"""Cancel the job.
1822
1923
Args:
@@ -24,11 +28,14 @@ def cancel(self, **kwargs):
2428
GitlabJobCancelError: If the job could not be canceled
2529
"""
2630
path=f"{self.manager.path}/{self.get_id()}/cancel"
27-
returnself.manager.gitlab.http_post(path)
31+
result=self.manager.gitlab.http_post(path)
32+
ifTYPE_CHECKING:
33+
assertisinstance(result,dict)
34+
returnresult
2835

2936
@cli.register_custom_action("ProjectJob")
3037
@exc.on_http_error(exc.GitlabJobRetryError)
31-
defretry(self,**kwargs):
38+
defretry(self,**kwargs:Any)->Dict[str,Any]:
3239
"""Retry the job.
3340
3441
Args:
@@ -39,11 +46,14 @@ def retry(self, **kwargs):
3946
GitlabJobRetryError: If the job could not be retried
4047
"""
4148
path=f"{self.manager.path}/{self.get_id()}/retry"
42-
returnself.manager.gitlab.http_post(path)
49+
result=self.manager.gitlab.http_post(path)
50+
ifTYPE_CHECKING:
51+
assertisinstance(result,dict)
52+
returnresult
4353

4454
@cli.register_custom_action("ProjectJob")
4555
@exc.on_http_error(exc.GitlabJobPlayError)
46-
defplay(self,**kwargs):
56+
defplay(self,**kwargs:Any)->None:
4757
"""Trigger a job explicitly.
4858
4959
Args:
@@ -58,7 +68,7 @@ def play(self, **kwargs):
5868

5969
@cli.register_custom_action("ProjectJob")
6070
@exc.on_http_error(exc.GitlabJobEraseError)
61-
deferase(self,**kwargs):
71+
deferase(self,**kwargs:Any)->None:
6272
"""Erase the job (remove job artifacts and trace).
6373
6474
Args:
@@ -73,7 +83,7 @@ def erase(self, **kwargs):
7383

7484
@cli.register_custom_action("ProjectJob")
7585
@exc.on_http_error(exc.GitlabCreateError)
76-
defkeep_artifacts(self,**kwargs):
86+
defkeep_artifacts(self,**kwargs:Any)->None:
7787
"""Prevent artifacts from being deleted when expiration is set.
7888
7989
Args:
@@ -88,7 +98,7 @@ def keep_artifacts(self, **kwargs):
8898

8999
@cli.register_custom_action("ProjectJob")
90100
@exc.on_http_error(exc.GitlabCreateError)
91-
defdelete_artifacts(self,**kwargs):
101+
defdelete_artifacts(self,**kwargs:Any)->None:
92102
"""Delete artifacts of a job.
93103
94104
Args:
@@ -103,7 +113,13 @@ def delete_artifacts(self, **kwargs):
103113

104114
@cli.register_custom_action("ProjectJob")
105115
@exc.on_http_error(exc.GitlabGetError)
106-
defartifacts(self,streamed=False,action=None,chunk_size=1024,**kwargs):
116+
defartifacts(
117+
self,
118+
streamed:bool=False,
119+
action:Optional[Callable[...,Any]]=None,
120+
chunk_size:int=1024,
121+
**kwargs:Any,
122+
)->Optional[bytes]:
107123
"""Get the job artifacts.
108124
109125
Args:
@@ -120,17 +136,26 @@ def artifacts(self, streamed=False, action=None, chunk_size=1024, **kwargs):
120136
GitlabGetError: If the artifacts could not be retrieved
121137
122138
Returns:
123-
str: The artifacts if `streamed` is False, None otherwise.
139+
bytes: The artifacts if `streamed` is False, None otherwise.
124140
"""
125141
path=f"{self.manager.path}/{self.get_id()}/artifacts"
126142
result=self.manager.gitlab.http_get(
127143
path,streamed=streamed,raw=True,**kwargs
128144
)
145+
ifTYPE_CHECKING:
146+
assertisinstance(result,requests.Response)
129147
returnutils.response_content(result,streamed,action,chunk_size)
130148

131149
@cli.register_custom_action("ProjectJob")
132150
@exc.on_http_error(exc.GitlabGetError)
133-
defartifact(self,path,streamed=False,action=None,chunk_size=1024,**kwargs):
151+
defartifact(
152+
self,
153+
path:str,
154+
streamed:bool=False,
155+
action:Optional[Callable[...,Any]]=None,
156+
chunk_size:int=1024,
157+
**kwargs:Any,
158+
)->Optional[bytes]:
134159
"""Get a single artifact file from within the job's artifacts archive.
135160
136161
Args:
@@ -148,17 +173,25 @@ def artifact(self, path, streamed=False, action=None, chunk_size=1024, **kwargs)
148173
GitlabGetError: If the artifacts could not be retrieved
149174
150175
Returns:
151-
str: The artifacts if `streamed` is False, None otherwise.
176+
bytes: The artifacts if `streamed` is False, None otherwise.
152177
"""
153178
path=f"{self.manager.path}/{self.get_id()}/artifacts/{path}"
154179
result=self.manager.gitlab.http_get(
155180
path,streamed=streamed,raw=True,**kwargs
156181
)
182+
ifTYPE_CHECKING:
183+
assertisinstance(result,requests.Response)
157184
returnutils.response_content(result,streamed,action,chunk_size)
158185

159186
@cli.register_custom_action("ProjectJob")
160187
@exc.on_http_error(exc.GitlabGetError)
161-
deftrace(self,streamed=False,action=None,chunk_size=1024,**kwargs):
188+
deftrace(
189+
self,
190+
streamed:bool=False,
191+
action:Optional[Callable[...,Any]]=None,
192+
chunk_size:int=1024,
193+
**kwargs:Any,
194+
)->Dict[str,Any]:
162195
"""Get the job trace.
163196
164197
Args:
@@ -181,10 +214,18 @@ def trace(self, streamed=False, action=None, chunk_size=1024, **kwargs):
181214
result=self.manager.gitlab.http_get(
182215
path,streamed=streamed,raw=True,**kwargs
183216
)
184-
returnutils.response_content(result,streamed,action,chunk_size)
217+
ifTYPE_CHECKING:
218+
assertisinstance(result,requests.Response)
219+
return_value=utils.response_content(result,streamed,action,chunk_size)
220+
ifTYPE_CHECKING:
221+
assertisinstance(return_value,dict)
222+
returnreturn_value
185223

186224

187225
classProjectJobManager(RetrieveMixin,RESTManager):
188226
_path="/projects/{project_id}/jobs"
189227
_obj_cls=ProjectJob
190228
_from_parent_attrs= {"project_id":"id"}
229+
230+
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->ProjectJob:
231+
returncast(ProjectJob,super().get(id=id,lazy=lazy,**kwargs))

‎pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module = [
1313
"docs.*",
1414
"docs.ext.*",
1515
"gitlab.v4.objects.files",
16-
"gitlab.v4.objects.jobs",
1716
"gitlab.v4.objects.labels",
1817
"gitlab.v4.objects.milestones",
1918
"gitlab.v4.objects.pipelines",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp