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:
116116def artifacts (
117117self ,
118118streamed :bool = False ,
119+ iterator :bool = False ,
119120action :Optional [Callable [...,Any ]]= None ,
120121chunk_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 )
145148if TYPE_CHECKING :
146149assert 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 )
151154def artifact (
152155self ,
153156path :str ,
154157streamed :bool = False ,
158+ iterator :bool = False ,
155159action :Optional [Callable [...,Any ]]= None ,
156160chunk_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 )
182188if TYPE_CHECKING :
183189assert 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 )
188194def trace (
189195self ,
190196streamed :bool = False ,
197+ iterator :bool = False ,
191198action :Optional [Callable [...,Any ]]= None ,
192199chunk_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 )
217226if TYPE_CHECKING :
218227assert 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+ )
220231if TYPE_CHECKING :
221232assert isinstance (return_value ,dict )
222233return return_value