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

Commit00d7b20

Browse files
chore: add type-hints to gitlab/v4/objects/repositories.py
1 parentcb3ad6c commit00d7b20

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

‎gitlab/v4/objects/repositories.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,36 @@
33
44
Currently this module only contains repository-related methods for projects.
55
"""
6+
fromtypingimportAny,Callable,Dict,List,Optional,TYPE_CHECKING,Union
67

8+
importrequests
9+
10+
importgitlab
711
fromgitlabimportcli
812
fromgitlabimportexceptionsasexc
913
fromgitlabimportutils
1014

15+
ifTYPE_CHECKING:
16+
# When running mypy we use these as the base classes
17+
_RestObjectBase=gitlab.base.RESTObject
18+
else:
19+
_RestObjectBase=object
20+
1121

12-
classRepositoryMixin:
22+
classRepositoryMixin(_RestObjectBase):
1323
@cli.register_custom_action("Project", ("submodule","branch","commit_sha"))
1424
@exc.on_http_error(exc.GitlabUpdateError)
15-
defupdate_submodule(self,submodule,branch,commit_sha,**kwargs):
25+
defupdate_submodule(
26+
self,submodule:str,branch:str,commit_sha:str,**kwargs:Any
27+
)->Union[Dict[str,Any],requests.Response]:
1628
"""Update a project submodule
1729
1830
Args:
1931
submodule (str): Full path to the submodule
2032
branch (str): Name of the branch to commit into
2133
commit_sha (str): Full commit SHA to update the submodule to
22-
commit_message (str): Commit message. If no message is provided, a default one will be set (optional)
34+
commit_message (str): Commit message. If no message is provided, a
35+
default one will be set (optional)
2336
2437
Raises:
2538
GitlabAuthenticationError: If authentication is not correct
@@ -35,7 +48,9 @@ def update_submodule(self, submodule, branch, commit_sha, **kwargs):
3548

3649
@cli.register_custom_action("Project",tuple(), ("path","ref","recursive"))
3750
@exc.on_http_error(exc.GitlabGetError)
38-
defrepository_tree(self,path="",ref="",recursive=False,**kwargs):
51+
defrepository_tree(
52+
self,path:str="",ref:str="",recursive:bool=False,**kwargs:Any
53+
)->Union[gitlab.client.GitlabList,List[Dict[str,Any]]]:
3954
"""Return a list of files in the repository.
4055
4156
Args:
@@ -57,7 +72,7 @@ def repository_tree(self, path="", ref="", recursive=False, **kwargs):
5772
list: The representation of the tree
5873
"""
5974
gl_path=f"/projects/{self.get_id()}/repository/tree"
60-
query_data= {"recursive":recursive}
75+
query_data:Dict[str,Any]= {"recursive":recursive}
6176
ifpath:
6277
query_data["path"]=path
6378
ifref:
@@ -66,7 +81,9 @@ def repository_tree(self, path="", ref="", recursive=False, **kwargs):
6681

6782
@cli.register_custom_action("Project", ("sha",))
6883
@exc.on_http_error(exc.GitlabGetError)
69-
defrepository_blob(self,sha,**kwargs):
84+
defrepository_blob(
85+
self,sha:str,**kwargs:Any
86+
)->Union[Dict[str,Any],requests.Response]:
7087
"""Return a file by blob SHA.
7188
7289
Args:
@@ -87,8 +104,13 @@ def repository_blob(self, sha, **kwargs):
87104
@cli.register_custom_action("Project", ("sha",))
88105
@exc.on_http_error(exc.GitlabGetError)
89106
defrepository_raw_blob(
90-
self,sha,streamed=False,action=None,chunk_size=1024,**kwargs
91-
):
107+
self,
108+
sha:str,
109+
streamed:bool=False,
110+
action:Optional[Callable[...,Any]]=None,
111+
chunk_size:int=1024,
112+
**kwargs:Any,
113+
)->Optional[bytes]:
92114
"""Return the raw file contents for a blob.
93115
94116
Args:
@@ -112,11 +134,15 @@ def repository_raw_blob(
112134
result=self.manager.gitlab.http_get(
113135
path,streamed=streamed,raw=True,**kwargs
114136
)
137+
ifTYPE_CHECKING:
138+
assertisinstance(result,requests.Response)
115139
returnutils.response_content(result,streamed,action,chunk_size)
116140

117141
@cli.register_custom_action("Project", ("from_","to"))
118142
@exc.on_http_error(exc.GitlabGetError)
119-
defrepository_compare(self,from_,to,**kwargs):
143+
defrepository_compare(
144+
self,from_:str,to:str,**kwargs:Any
145+
)->Union[Dict[str,Any],requests.Response]:
120146
"""Return a diff between two branches/commits.
121147
122148
Args:
@@ -137,7 +163,9 @@ def repository_compare(self, from_, to, **kwargs):
137163

138164
@cli.register_custom_action("Project")
139165
@exc.on_http_error(exc.GitlabGetError)
140-
defrepository_contributors(self,**kwargs):
166+
defrepository_contributors(
167+
self,**kwargs:Any
168+
)->Union[gitlab.client.GitlabList,List[Dict[str,Any]]]:
141169
"""Return a list of contributors for the project.
142170
143171
Args:
@@ -161,8 +189,13 @@ def repository_contributors(self, **kwargs):
161189
@cli.register_custom_action("Project",tuple(), ("sha",))
162190
@exc.on_http_error(exc.GitlabListError)
163191
defrepository_archive(
164-
self,sha=None,streamed=False,action=None,chunk_size=1024,**kwargs
165-
):
192+
self,
193+
sha:str=None,
194+
streamed:bool=False,
195+
action:Optional[Callable[...,Any]]=None,
196+
chunk_size:int=1024,
197+
**kwargs:Any,
198+
)->Optional[bytes]:
166199
"""Return a tarball of the repository.
167200
168201
Args:
@@ -189,11 +222,13 @@ def repository_archive(
189222
result=self.manager.gitlab.http_get(
190223
path,query_data=query_data,raw=True,streamed=streamed,**kwargs
191224
)
225+
ifTYPE_CHECKING:
226+
assertisinstance(result,requests.Response)
192227
returnutils.response_content(result,streamed,action,chunk_size)
193228

194229
@cli.register_custom_action("Project")
195230
@exc.on_http_error(exc.GitlabDeleteError)
196-
defdelete_merged_branches(self,**kwargs):
231+
defdelete_merged_branches(self,**kwargs:Any)->None:
197232
"""Delete merged branches.
198233
199234
Args:

‎pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module = [
1414
"docs.ext.*",
1515
"gitlab.v4.objects.files",
1616
"gitlab.v4.objects.labels",
17-
"gitlab.v4.objects.repositories",
1817
"gitlab.v4.objects.services",
1918
"gitlab.v4.objects.sidekiq",
2019
"tests.functional.*",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp