1
+ from typing import Any ,cast ,Dict ,Optional ,TYPE_CHECKING ,Union
2
+
3
+ import requests
4
+
1
5
from gitlab import cli
2
6
from gitlab import exceptions as exc
3
7
from gitlab .base import RequiredOptional ,RESTManager ,RESTObject
@@ -24,7 +28,7 @@ class ProjectCommit(RESTObject):
24
28
25
29
@cli .register_custom_action ("ProjectCommit" )
26
30
@exc .on_http_error (exc .GitlabGetError )
27
- def diff (self ,** kwargs ) :
31
+ def diff (self ,** kwargs : Any ) -> Union [ Dict [ str , Any ], requests . Response ] :
28
32
"""Generate the commit diff.
29
33
30
34
Args:
@@ -42,7 +46,7 @@ def diff(self, **kwargs):
42
46
43
47
@cli .register_custom_action ("ProjectCommit" , ("branch" ,))
44
48
@exc .on_http_error (exc .GitlabCherryPickError )
45
- def cherry_pick (self ,branch ,** kwargs ) :
49
+ def cherry_pick (self ,branch : str ,** kwargs : Any ) -> None :
46
50
"""Cherry-pick a commit into a branch.
47
51
48
52
Args:
@@ -59,7 +63,9 @@ def cherry_pick(self, branch, **kwargs):
59
63
60
64
@cli .register_custom_action ("ProjectCommit" ,optional = ("type" ,))
61
65
@exc .on_http_error (exc .GitlabGetError )
62
- def refs (self ,type = "all" ,** kwargs ):
66
+ def refs (
67
+ self ,type :str = "all" ,** kwargs :Any
68
+ )-> Union [Dict [str ,Any ],requests .Response ]:
63
69
"""List the references the commit is pushed to.
64
70
65
71
Args:
@@ -79,7 +85,7 @@ def refs(self, type="all", **kwargs):
79
85
80
86
@cli .register_custom_action ("ProjectCommit" )
81
87
@exc .on_http_error (exc .GitlabGetError )
82
- def merge_requests (self ,** kwargs ) :
88
+ def merge_requests (self ,** kwargs : Any ) -> Union [ Dict [ str , Any ], requests . Response ] :
83
89
"""List the merge requests related to the commit.
84
90
85
91
Args:
@@ -97,7 +103,9 @@ def merge_requests(self, **kwargs):
97
103
98
104
@cli .register_custom_action ("ProjectCommit" , ("branch" ,))
99
105
@exc .on_http_error (exc .GitlabRevertError )
100
- def revert (self ,branch ,** kwargs ):
106
+ def revert (
107
+ self ,branch :str ,** kwargs :Any
108
+ )-> Union [Dict [str ,Any ],requests .Response ]:
101
109
"""Revert a commit on a given branch.
102
110
103
111
Args:
@@ -117,7 +125,7 @@ def revert(self, branch, **kwargs):
117
125
118
126
@cli .register_custom_action ("ProjectCommit" )
119
127
@exc .on_http_error (exc .GitlabGetError )
120
- def signature (self ,** kwargs ) :
128
+ def signature (self ,** kwargs : Any ) -> Union [ Dict [ str , Any ], requests . Response ] :
121
129
"""Get the signature of the commit.
122
130
123
131
Args:
@@ -172,7 +180,9 @@ class ProjectCommitStatusManager(ListMixin, CreateMixin, RESTManager):
172
180
)
173
181
174
182
@exc .on_http_error (exc .GitlabCreateError )
175
- def create (self ,data ,** kwargs ):
183
+ def create (
184
+ self ,data :Optional [Dict [str ,Any ]]= None ,** kwargs :Any
185
+ )-> ProjectCommitStatus :
176
186
"""Create a new object.
177
187
178
188
Args:
@@ -193,8 +203,13 @@ def create(self, data, **kwargs):
193
203
# they are missing when using only the API
194
204
# See #511
195
205
base_path = "/projects/%(project_id)s/statuses/%(commit_id)s"
196
- if "project_id" in data and "commit_id" in data :
206
+ path :Optional [str ]
207
+ if data is not None and "project_id" in data and "commit_id" in data :
197
208
path = base_path % data
198
209
else :
199
210
path = self ._compute_path (base_path )
200
- return CreateMixin .create (self ,data ,path = path ,** kwargs )
211
+ if TYPE_CHECKING :
212
+ assert path is not None
213
+ return cast (
214
+ ProjectCommitStatus ,CreateMixin .create (self ,data ,path = path ,** kwargs )
215
+ )