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

Commit635f5a7

Browse files
oliver.blasiusJohnVillalovos
oliver.blasius
authored andcommitted
feat(api): add support for latest pipeline
1 parent88de2f0 commit635f5a7

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

‎docs/gl_objects/pipelines_and_jobs.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Delete a pipeline::
4949

5050
pipeline.delete()
5151

52+
Get latest pipeline::
53+
54+
projet.pipelines.latest(ref="main")
55+
56+
5257
Triggers
5358
========
5459

‎gitlab/v4/objects/pipelines.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ def create(
139139
ProjectPipeline,CreateMixin.create(self,data,path=path,**kwargs)
140140
)
141141

142+
deflatest(self,ref:Optional[str]=None,lazy:bool=False)->ProjectPipeline:
143+
"""Get the latest pipeline for the most recent commit
144+
on a specific ref in a project
145+
146+
Args:
147+
ref: The branch or tag to check for the latest pipeline.
148+
Defaults to the default branch when not specified.
149+
Returns:
150+
A Pipeline instance
151+
"""
152+
data= {}
153+
ifref:
154+
data= {"ref":ref}
155+
ifTYPE_CHECKING:
156+
assertself._obj_clsisnotNone
157+
assertself.pathisnotNone
158+
server_data=self.gitlab.http_get(self.path+"/latest",query_data=data)
159+
ifTYPE_CHECKING:
160+
assertnotisinstance(server_data,requests.Response)
161+
returnself._obj_cls(self,server_data,lazy=lazy)
162+
142163

143164
classProjectPipelineJob(RESTObject):
144165
pass

‎tests/unit/objects/test_pipelines.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,62 @@
3939
"web_url":"https://example.com/foo/bar/pipelines/46",
4040
}
4141

42+
pipeline_latest= {
43+
"id":47,
44+
"project_id":1,
45+
"status":"pending",
46+
"ref":"main",
47+
"sha":"a91957a858320c0e17f3a0eca7cfacbff50ea29a",
48+
"before_sha":"a91957a858320c0e17f3a0eca7cfacbff50ea29a",
49+
"tag":False,
50+
"yaml_errors":None,
51+
"user": {
52+
"name":"Administrator",
53+
"username":"root",
54+
"id":1,
55+
"state":"active",
56+
"avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
57+
"web_url":"http://localhost:3000/root",
58+
},
59+
"created_at":"2016-08-11T11:28:34.085Z",
60+
"updated_at":"2016-08-11T11:32:35.169Z",
61+
"started_at":None,
62+
"finished_at":"2016-08-11T11:32:35.145Z",
63+
"committed_at":None,
64+
"duration":None,
65+
"queued_duration":0.010,
66+
"coverage":None,
67+
"web_url":"https://example.com/foo/bar/pipelines/46",
68+
}
69+
70+
pipeline_latest_other_ref= {
71+
"id":48,
72+
"project_id":1,
73+
"status":"pending",
74+
"ref":"feature-ref",
75+
"sha":"a91957a858320c0e17f3a0eca7cfacbff50ea29a",
76+
"before_sha":"a91957a858320c0e17f3a0eca7cfacbff50ea29a",
77+
"tag":False,
78+
"yaml_errors":None,
79+
"user": {
80+
"name":"Administrator",
81+
"username":"root",
82+
"id":1,
83+
"state":"active",
84+
"avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
85+
"web_url":"http://localhost:3000/root",
86+
},
87+
"created_at":"2016-08-11T11:28:34.085Z",
88+
"updated_at":"2016-08-11T11:32:35.169Z",
89+
"started_at":None,
90+
"finished_at":"2016-08-11T11:32:35.145Z",
91+
"committed_at":None,
92+
"duration":None,
93+
"queued_duration":0.010,
94+
"coverage":None,
95+
"web_url":"https://example.com/foo/bar/pipelines/46",
96+
}
97+
4298

4399
test_report_content= {
44100
"total_time":5,
@@ -162,10 +218,37 @@ def resp_get_pipeline_test_report_summary():
162218
yieldrsps
163219

164220

221+
@pytest.fixture
222+
defresp_get_latest():
223+
withresponses.RequestsMock()asrsps:
224+
rsps.add(
225+
method=responses.GET,
226+
url="http://localhost/api/v4/projects/1/pipelines/latest",
227+
json=pipeline_latest,
228+
content_type="application/json",
229+
status=200,
230+
)
231+
yieldrsps
232+
233+
234+
@pytest.fixture
235+
defresp_get_latest_other_ref():
236+
withresponses.RequestsMock()asrsps:
237+
rsps.add(
238+
method=responses.GET,
239+
url="http://localhost/api/v4/projects/1/pipelines/latest",
240+
json=pipeline_latest_other_ref,
241+
content_type="application/json",
242+
status=200,
243+
)
244+
yieldrsps
245+
246+
165247
deftest_get_project_pipeline(project,resp_get_pipeline):
166248
pipeline=project.pipelines.get(1)
167249
assertisinstance(pipeline,ProjectPipeline)
168250
assertpipeline.ref=="main"
251+
assertpipeline.id==46
169252

170253

171254
deftest_cancel_project_pipeline(project,resp_cancel_pipeline):
@@ -198,3 +281,17 @@ def test_get_project_pipeline_test_report_summary(
198281
assertisinstance(test_report_summary,ProjectPipelineTestReportSummary)
199282
asserttest_report_summary.total["count"]==3363
200283
asserttest_report_summary.test_suites[0]["name"]=="test"
284+
285+
286+
deftest_latest_pipeline(project,resp_get_latest):
287+
pipeline=project.pipelines.latest()
288+
assertisinstance(pipeline,ProjectPipeline)
289+
assertpipeline.ref=="main"
290+
assertpipeline.id==47
291+
292+
293+
deftest_latest_pipeline_other_ref(project,resp_get_latest_other_ref):
294+
pipeline=project.pipelines.latest(ref="feature-ref")
295+
assertisinstance(pipeline,ProjectPipeline)
296+
assertpipeline.ref=="feature-ref"
297+
assertpipeline.id==48

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp