From 76b6e1fc0f42ad00f21d284b4ca2c45d6020fd19 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Wed, 1 May 2019 07:45:19 +0200 Subject: [PATCH] feat: implement artifacts deletion Closes #744 --- docs/gl_objects/builds.rst | 4 ++++ gitlab/v4/objects.py | 15 +++++++++++++++ tools/python_test_v4.py | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/gl_objects/builds.rst b/docs/gl_objects/builds.rst index d74d9d6d6..eab4735c3 100644 --- a/docs/gl_objects/builds.rst +++ b/docs/gl_objects/builds.rst @@ -319,6 +319,10 @@ Mark a job artifact as kept when expiration is set:: build_or_job.keep_artifacts() +Delete the artifacts of a job:: + + build_or_job.delete_artifacts() + Get a job trace:: build_or_job.trace() diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 8fc715090..d15bc5da2 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1584,6 +1584,21 @@ def keep_artifacts(self, **kwargs): path = "%s/%s/artifacts/keep" % (self.manager.path, self.get_id()) self.manager.gitlab.http_post(path) + @cli.register_custom_action("ProjectJob") + @exc.on_http_error(exc.GitlabCreateError) + def delete_artifacts(self, **kwargs): + """Delete artifacts of a job. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabDeleteError: If the request could not be performed + """ + path = "%s/%s/artifacts" % (self.manager.path, self.get_id()) + self.manager.gitlab.http_delete(path) + @cli.register_custom_action("ProjectJob") @exc.on_http_error(exc.GitlabGetError) def artifacts(self, streamed=False, action=None, chunk_size=1024, **kwargs): diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index b8dae28c6..07f3589bb 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -421,8 +421,9 @@ # commit status commit = admin_project.commits.list()[0] +size = len(commit.statuses.list()) status = commit.statuses.create({"state": "success", "sha": commit.id}) -assert len(commit.statuses.list()) == 1 +assert len(commit.statuses.list()) == size + 1 assert commit.refs() assert commit.merge_requests() is not None