diff options
Diffstat (limited to 'gitlab/v4/objects/jobs.py')
-rw-r--r-- | gitlab/v4/objects/jobs.py | 83 |
1 files changed, 6 insertions, 77 deletions
diff --git a/gitlab/v4/objects/jobs.py b/gitlab/v4/objects/jobs.py index cfe1e62..52fff50 100644 --- a/gitlab/v4/objects/jobs.py +++ b/gitlab/v4/objects/jobs.py @@ -8,6 +8,8 @@ from gitlab import utils from gitlab.base import RESTManager, RESTObject from gitlab.mixins import RefreshMixin, RetrieveMixin +from .artifacts import ProjectJobArtifactManager # noqa: F401 + __all__ = [ "ProjectJob", "ProjectJobManager", @@ -15,6 +17,8 @@ __all__ = [ class ProjectJob(RefreshMixin, RESTObject): + artifacts: ProjectJobArtifactManager + @cli.register_custom_action("ProjectJob") @exc.on_http_error(exc.GitlabJobCancelError) def cancel(self, **kwargs: Any) -> Dict[str, Any]: @@ -113,87 +117,12 @@ class ProjectJob(RefreshMixin, RESTObject): @cli.register_custom_action("ProjectJob") @exc.on_http_error(exc.GitlabGetError) - def artifacts( - self, - streamed: bool = False, - action: Optional[Callable[..., Any]] = None, - chunk_size: int = 1024, - *, - iterator: bool = False, - **kwargs: Any, - ) -> Optional[Union[bytes, Iterator[Any]]]: - """Get the job artifacts. - - Args: - 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 - **kwargs: Extra options to send to the server (e.g. sudo) - - Raises: - GitlabAuthenticationError: If authentication is not correct - GitlabGetError: If the artifacts could not be retrieved - - Returns: - The artifacts if `streamed` is False, None otherwise. - """ - path = f"{self.manager.path}/{self.encoded_id}/artifacts" - result = self.manager.gitlab.http_get( - path, streamed=streamed, raw=True, **kwargs - ) - if TYPE_CHECKING: - assert isinstance(result, requests.Response) - return utils.response_content( - result, streamed, action, chunk_size, iterator=iterator - ) - - @cli.register_custom_action("ProjectJob") - @exc.on_http_error(exc.GitlabGetError) def artifact( self, - path: str, - streamed: bool = False, - action: Optional[Callable[..., Any]] = None, - chunk_size: int = 1024, - *, - iterator: bool = False, + *args: Any, **kwargs: Any, ) -> Optional[Union[bytes, Iterator[Any]]]: - """Get a single artifact file from within the job's artifacts archive. - - Args: - path: Path of the artifact - 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 - **kwargs: Extra options to send to the server (e.g. sudo) - - Raises: - GitlabAuthenticationError: If authentication is not correct - GitlabGetError: If the artifacts could not be retrieved - - Returns: - The artifacts if `streamed` is False, None otherwise. - """ - path = f"{self.manager.path}/{self.encoded_id}/artifacts/{path}" - result = self.manager.gitlab.http_get( - path, streamed=streamed, raw=True, **kwargs - ) - if TYPE_CHECKING: - assert isinstance(result, requests.Response) - return utils.response_content( - result, streamed, action, chunk_size, iterator=iterator - ) + return self.artifacts.raw(*args, **kwargs) @cli.register_custom_action("ProjectJob") @exc.on_http_error(exc.GitlabGetError) |