summaryrefslogtreecommitdiff
path: root/gitlab/v4/objects/artifacts.py
diff options
context:
space:
mode:
authorTom Catshoek <tomcatshoek@zeelandnet.nl>2022-06-26 08:29:13 +0200
committerGitHub <noreply@github.com>2022-06-26 08:29:13 +0200
commitb6447211754e126f64e12fc735ad74fe557b7fb4 (patch)
tree2c86425ce6b25b4d40bf0c12aa0d1f7def77838c /gitlab/v4/objects/artifacts.py
parent0f2a602d3a9d6579f5fdfdf945a236ae44e93a12 (diff)
downloadgitlab-b6447211754e126f64e12fc735ad74fe557b7fb4.tar.gz
feat(downloads): allow streaming downloads access to response iterator (#1956)
* feat(downloads): allow streaming downloads access to response iterator Allow access to the underlying response iterator when downloading in streaming mode by specifying `iterator=True`. Update type annotations to support this change. * docs(api-docs): add iterator example to artifact download Document the usage of the `iterator=True` option when downloading artifacts * test(packages): add tests for streaming downloads
Diffstat (limited to 'gitlab/v4/objects/artifacts.py')
-rw-r--r--gitlab/v4/objects/artifacts.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/gitlab/v4/objects/artifacts.py b/gitlab/v4/objects/artifacts.py
index 541e5e2..f5f106d 100644
--- a/gitlab/v4/objects/artifacts.py
+++ b/gitlab/v4/objects/artifacts.py
@@ -2,7 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/job_artifacts.html
"""
-from typing import Any, Callable, Optional, TYPE_CHECKING
+from typing import Any, Callable, Iterator, Optional, TYPE_CHECKING, Union
import requests
@@ -40,10 +40,14 @@ class ProjectArtifactManager(RESTManager):
),
category=DeprecationWarning,
)
- return self.download(
+ data = self.download(
*args,
**kwargs,
)
+ if TYPE_CHECKING:
+ assert data is not None
+ assert isinstance(data, bytes)
+ return data
@exc.on_http_error(exc.GitlabDeleteError)
def delete(self, **kwargs: Any) -> None:
@@ -71,10 +75,11 @@ class ProjectArtifactManager(RESTManager):
ref_name: str,
job: str,
streamed: bool = False,
+ iterator: bool = False,
action: Optional[Callable] = None,
chunk_size: int = 1024,
**kwargs: Any,
- ) -> Optional[bytes]:
+ ) -> Optional[Union[bytes, Iterator[Any]]]:
"""Get the job artifacts archive from a specific tag or branch.
Args:
@@ -85,6 +90,8 @@ class ProjectArtifactManager(RESTManager):
streamed: If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment
+ iterator: If True directly return the underlying response
+ iterator
action: Callable responsible of dealing with chunk of
data
chunk_size: Size of each chunk
@@ -103,7 +110,7 @@ class ProjectArtifactManager(RESTManager):
)
if TYPE_CHECKING:
assert isinstance(result, requests.Response)
- return utils.response_content(result, streamed, action, chunk_size)
+ return utils.response_content(result, streamed, iterator, action, chunk_size)
@cli.register_custom_action(
"ProjectArtifactManager", ("ref_name", "artifact_path", "job")
@@ -115,10 +122,11 @@ class ProjectArtifactManager(RESTManager):
artifact_path: str,
job: str,
streamed: bool = False,
+ iterator: bool = False,
action: Optional[Callable] = None,
chunk_size: int = 1024,
**kwargs: Any,
- ) -> Optional[bytes]:
+ ) -> Optional[Union[bytes, Iterator[Any]]]:
"""Download a single artifact file from a specific tag or branch from
within the job's artifacts archive.
@@ -130,6 +138,8 @@ class ProjectArtifactManager(RESTManager):
streamed: If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment
+ iterator: If True directly return the underlying response
+ iterator
action: Callable responsible of dealing with chunk of
data
chunk_size: Size of each chunk
@@ -148,4 +158,4 @@ class ProjectArtifactManager(RESTManager):
)
if TYPE_CHECKING:
assert isinstance(result, requests.Response)
- return utils.response_content(result, streamed, action, chunk_size)
+ return utils.response_content(result, streamed, iterator, action, chunk_size)