Skip to content

Commit c01c034

Browse files
nejchJohnVillalovos
authored andcommitted
feat(artifacts): add support for project artifacts delete API
1 parent 14b88a1 commit c01c034

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

gitlab/v4/objects/artifacts.py

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ def __call__(
4545
**kwargs,
4646
)
4747

48+
@exc.on_http_error(exc.GitlabDeleteError)
49+
def delete(self, **kwargs: Any) -> None:
50+
"""Delete the project's artifacts on the server.
51+
52+
Args:
53+
**kwargs: Extra options to send to the server (e.g. sudo)
54+
55+
Raises:
56+
GitlabAuthenticationError: If authentication is not correct
57+
GitlabDeleteError: If the server cannot perform the request
58+
"""
59+
path = self._compute_path("/projects/{project_id}/artifacts")
60+
61+
if TYPE_CHECKING:
62+
assert path is not None
63+
self.gitlab.http_delete(path, **kwargs)
64+
4865
@cli.register_custom_action(
4966
"ProjectArtifactManager", ("ref_name", "job"), ("job_token",)
5067
)

tests/unit/objects/test_job_artifacts.py

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ def resp_artifacts_by_ref_name(binary_content):
2424
yield rsps
2525

2626

27+
@pytest.fixture
28+
def resp_project_artifacts_delete(no_content):
29+
with responses.RequestsMock() as rsps:
30+
rsps.add(
31+
method=responses.DELETE,
32+
url="http://localhost/api/v4/projects/1/artifacts",
33+
json=no_content,
34+
content_type="application/json",
35+
status=204,
36+
)
37+
yield rsps
38+
39+
40+
def test_project_artifacts_delete(gl, resp_project_artifacts_delete):
41+
project = gl.projects.get(1, lazy=True)
42+
project.artifacts.delete()
43+
44+
2745
def test_project_artifacts_download_by_ref_name(
2846
gl, binary_content, resp_artifacts_by_ref_name
2947
):

0 commit comments

Comments
 (0)