Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7a07fc

Browse files
committed
feat(api): add endpoint for latest ref artifacts
1 parent4039c8c commitb7a07fc

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/job_artifacts.html
3+
"""
4+
5+
importpytest
6+
importresponses
7+
8+
fromgitlab.v4.objectsimportProject
9+
10+
11+
ref_name="master"
12+
job="build"
13+
14+
15+
@pytest.fixture
16+
defresp_artifacts_by_ref_name(binary_content):
17+
url=f"http://localhost/api/v4/projects/1/jobs/artifacts/{ref_name}/download?job={job}"
18+
19+
withresponses.RequestsMock()asrsps:
20+
rsps.add(
21+
method=responses.GET,
22+
url=url,
23+
body=binary_content,
24+
content_type="application/octet-stream",
25+
status=200,
26+
)
27+
yieldrsps
28+
29+
30+
deftest_download_artifacts_by_ref_name(gl,binary_content,resp_artifacts_by_ref_name):
31+
project=gl.projects.get(1,lazy=True)
32+
artifacts=project.artifacts(ref_name=ref_name,job=job)
33+
assertartifacts==binary_content

‎gitlab/v4/objects.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,6 +5087,40 @@ def transfer_project(self, to_namespace, **kwargs):
50875087
path,post_data={"namespace":to_namespace},**kwargs
50885088
)
50895089

5090+
@cli.register_custom_action("Project", ("ref_name","job"), ("job_token",))
5091+
@exc.on_http_error(exc.GitlabGetError)
5092+
defartifacts(
5093+
self,ref_name,job,streamed=False,action=None,chunk_size=1024,**kwargs
5094+
):
5095+
"""Get the job artifacts archive from a specific tag or branch.
5096+
5097+
Args:
5098+
ref_name (str): Branch or tag name in repository. HEAD or SHA references
5099+
are not supported.
5100+
artifact_path (str): Path to a file inside the artifacts archive.
5101+
job (str): The name of the job.
5102+
job_token (str): Job token for multi-project pipeline triggers.
5103+
streamed (bool): If True the data will be processed by chunks of
5104+
`chunk_size` and each chunk is passed to `action` for
5105+
treatment
5106+
action (callable): Callable responsible of dealing with chunk of
5107+
data
5108+
chunk_size (int): Size of each chunk
5109+
**kwargs: Extra options to send to the server (e.g. sudo)
5110+
5111+
Raises:
5112+
GitlabAuthenticationError: If authentication is not correct
5113+
GitlabGetError: If the artifacts could not be retrieved
5114+
5115+
Returns:
5116+
str: The artifacts if `streamed` is False, None otherwise.
5117+
"""
5118+
path="/projects/%s/jobs/artifacts/%s/download"% (self.get_id(),ref_name)
5119+
result=self.manager.gitlab.http_get(
5120+
path,job=job,streamed=streamed,raw=True,**kwargs
5121+
)
5122+
returnutils.response_content(result,streamed,action,chunk_size)
5123+
50905124
@cli.register_custom_action("Project", ("ref_name","artifact_path","job"))
50915125
@exc.on_http_error(exc.GitlabGetError)
50925126
defartifact(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp