1- from typing import Any , Callable , cast , Dict , Optional , TYPE_CHECKING , Union
1+ from typing import Any , Callable , cast , Dict , Iterator , Optional , TYPE_CHECKING , Union
22
33import requests
44
@@ -116,16 +116,19 @@ def delete_artifacts(self, **kwargs: Any) -> None:
116116 def artifacts (
117117 self ,
118118 streamed : bool = False ,
119+ iterator : bool = False ,
119120 action : Optional [Callable [..., Any ]] = None ,
120121 chunk_size : int = 1024 ,
121122 ** kwargs : Any ,
122- ) -> Optional [bytes ]:
123+ ) -> Optional [Union [ bytes , Iterator [ Any ]] ]:
123124 """Get the job artifacts.
124125
125126 Args:
126127 streamed: If True the data will be processed by chunks of
127128 `chunk_size` and each chunk is passed to `action` for
128129 treatment
130+ iterator: If True directly return the underlying response
131+ iterator
129132 action: Callable responsible of dealing with chunk of
130133 data
131134 chunk_size: Size of each chunk
@@ -144,25 +147,28 @@ def artifacts(
144147 )
145148 if TYPE_CHECKING :
146149 assert isinstance (result , requests .Response )
147- return utils .response_content (result , streamed , action , chunk_size )
150+ return utils .response_content (result , streamed , iterator , action , chunk_size )
148151
149152 @cli .register_custom_action ("ProjectJob" )
150153 @exc .on_http_error (exc .GitlabGetError )
151154 def artifact (
152155 self ,
153156 path : str ,
154157 streamed : bool = False ,
158+ iterator : bool = False ,
155159 action : Optional [Callable [..., Any ]] = None ,
156160 chunk_size : int = 1024 ,
157161 ** kwargs : Any ,
158- ) -> Optional [bytes ]:
162+ ) -> Optional [Union [ bytes , Iterator [ Any ]] ]:
159163 """Get a single artifact file from within the job's artifacts archive.
160164
161165 Args:
162166 path: Path of the artifact
163167 streamed: If True the data will be processed by chunks of
164168 `chunk_size` and each chunk is passed to `action` for
165169 treatment
170+ iterator: If True directly return the underlying response
171+ iterator
166172 action: Callable responsible of dealing with chunk of
167173 data
168174 chunk_size: Size of each chunk
@@ -181,13 +187,14 @@ def artifact(
181187 )
182188 if TYPE_CHECKING :
183189 assert isinstance (result , requests .Response )
184- return utils .response_content (result , streamed , action , chunk_size )
190+ return utils .response_content (result , streamed , iterator , action , chunk_size )
185191
186192 @cli .register_custom_action ("ProjectJob" )
187193 @exc .on_http_error (exc .GitlabGetError )
188194 def trace (
189195 self ,
190196 streamed : bool = False ,
197+ iterator : bool = False ,
191198 action : Optional [Callable [..., Any ]] = None ,
192199 chunk_size : int = 1024 ,
193200 ** kwargs : Any ,
@@ -198,6 +205,8 @@ def trace(
198205 streamed: If True the data will be processed by chunks of
199206 `chunk_size` and each chunk is passed to `action` for
200207 treatment
208+ iterator: If True directly return the underlying response
209+ iterator
201210 action: Callable responsible of dealing with chunk of
202211 data
203212 chunk_size: Size of each chunk
@@ -216,7 +225,9 @@ def trace(
216225 )
217226 if TYPE_CHECKING :
218227 assert isinstance (result , requests .Response )
219- return_value = utils .response_content (result , streamed , action , chunk_size )
228+ return_value = utils .response_content (
229+ result , streamed , iterator , action , chunk_size
230+ )
220231 if TYPE_CHECKING :
221232 assert isinstance (return_value , dict )
222233 return return_value
0 commit comments