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

Commitc5d0404

Browse files
Guilherme GalloJohnVillalovos
Guilherme Gallo
authored andcommitted
fix: Considerscope an ArrayAttribute in PipelineJobManager
List query params like 'scope' were not being handled correctly forpipeline/jobs endpoint.This change ensures multiple values are appended with '[]', resulting inthe correct URL structure.Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>---Background:If one queries for pipeline jobs with `scope=["failed", "success"]`One gets:GET /api/v4/projects/176/pipelines/1113028/jobs?scope=success&scope=failedBut it is supposed to get:GET /api/v4/projects/176/pipelines/1113028/jobs?scope[]=success&scope[]=failedThe current version only considers the last element of the list argument.Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>
1 parentc23e6bd commitc5d0404

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

‎gitlab/v4/objects/pipelines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
SaveMixin,
1818
UpdateMixin,
1919
)
20-
fromgitlab.typesimportRequiredOptional
20+
fromgitlab.typesimportArrayAttribute,RequiredOptional
2121

2222
__all__= [
2323
"ProjectMergeRequestPipeline",
@@ -149,6 +149,7 @@ class ProjectPipelineJobManager(ListMixin, RESTManager):
149149
_obj_cls=ProjectPipelineJob
150150
_from_parent_attrs= {"project_id":"project_id","pipeline_id":"id"}
151151
_list_filters= ("scope","include_retried")
152+
_types= {"scope":ArrayAttribute}
152153

153154

154155
classProjectPipelineBridge(RESTObject):

‎tests/unit/objects/test_jobs.py

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
GitLab API: https://docs.gitlab.com/ee/api/jobs.html
33
"""
44

5+
fromfunctoolsimportpartial
6+
57
importpytest
68
importresponses
79

810
fromgitlab.v4.objectsimportProjectJob
911

10-
job_content= {
12+
failed_job_content= {
1113
"commit": {
1214
"author_email":"admin@example.com",
1315
"author_name":"Administrator",
@@ -37,14 +39,20 @@
3739
"user": {"id":1},
3840
}
3941

42+
success_job_content= {
43+
**failed_job_content,
44+
"status":"success",
45+
"id":failed_job_content["id"]+1,
46+
}
47+
4048

4149
@pytest.fixture
4250
defresp_get_job():
4351
withresponses.RequestsMock()asrsps:
4452
rsps.add(
4553
method=responses.GET,
4654
url="http://localhost/api/v4/projects/1/jobs/1",
47-
json=job_content,
55+
json=failed_job_content,
4856
content_type="application/json",
4957
status=200,
5058
)
@@ -57,7 +65,7 @@ def resp_cancel_job():
5765
rsps.add(
5866
method=responses.POST,
5967
url="http://localhost/api/v4/projects/1/jobs/1/cancel",
60-
json=job_content,
68+
json=failed_job_content,
6169
content_type="application/json",
6270
status=201,
6371
)
@@ -70,13 +78,53 @@ def resp_retry_job():
7078
rsps.add(
7179
method=responses.POST,
7280
url="http://localhost/api/v4/projects/1/jobs/1/retry",
73-
json=job_content,
81+
json=failed_job_content,
7482
content_type="application/json",
7583
status=201,
7684
)
7785
yieldrsps
7886

7987

88+
@pytest.fixture
89+
defresp_list_job():
90+
urls= [
91+
"http://localhost/api/v4/projects/1/jobs",
92+
"http://localhost/api/v4/projects/1/pipelines/1/jobs",
93+
]
94+
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
95+
register_endpoint=partial(
96+
rsps.add,
97+
method=responses.GET,
98+
content_type="application/json",
99+
status=200,
100+
)
101+
forurlinurls:
102+
register_endpoint(
103+
url=url,
104+
json=[failed_job_content],
105+
match=[responses.matchers.query_param_matcher({"scope[]":"failed"})],
106+
)
107+
register_endpoint(
108+
url=url,
109+
json=[success_job_content],
110+
match=[responses.matchers.query_param_matcher({"scope[]":"success"})],
111+
)
112+
register_endpoint(
113+
url=url,
114+
json=[success_job_content,failed_job_content],
115+
match=[
116+
responses.matchers.query_string_matcher(
117+
"scope[]=success&scope[]failed"
118+
)
119+
],
120+
)
121+
register_endpoint(
122+
url=url,
123+
json=[success_job_content,failed_job_content],
124+
)
125+
yieldrsps
126+
127+
80128
deftest_get_project_job(project,resp_get_job):
81129
job=project.jobs.get(1)
82130
assertisinstance(job,ProjectJob)
@@ -95,3 +143,28 @@ def test_retry_project_job(project, resp_retry_job):
95143

96144
output=job.retry()
97145
assertoutput["ref"]=="main"
146+
147+
148+
deftest_list_project_job(project,resp_list_job):
149+
failed_jobs=project.jobs.list(scope="failed")
150+
success_jobs=project.jobs.list(scope="success")
151+
failed_and_success_jobs=project.jobs.list(scope=["failed","success"])
152+
pipeline_lazy=project.pipelines.get(1,lazy=True)
153+
pjobs_failed=pipeline_lazy.jobs.list(scope="failed")
154+
pjobs_success=pipeline_lazy.jobs.list(scope="success")
155+
pjobs_failed_and_success=pipeline_lazy.jobs.list(scope=["failed","success"])
156+
157+
prepared_urls= [c.request.urlforcinresp_list_job.calls]
158+
159+
# Both pipelines and pipelines/jobs should behave the same way
160+
# When `scope` is scalar, one can use scope=value or scope[]=value
161+
assertset(failed_and_success_jobs)==set(failed_jobs+success_jobs)
162+
assertset(pjobs_failed_and_success)==set(pjobs_failed+pjobs_success)
163+
assertprepared_urls== [
164+
"http://localhost/api/v4/projects/1/jobs?scope%5B%5D=failed",
165+
"http://localhost/api/v4/projects/1/jobs?scope%5B%5D=success",
166+
"http://localhost/api/v4/projects/1/jobs?scope%5B%5D=failed&scope%5B%5D=success",
167+
"http://localhost/api/v4/projects/1/pipelines/1/jobs?scope%5B%5D=failed",
168+
"http://localhost/api/v4/projects/1/pipelines/1/jobs?scope%5B%5D=success",
169+
"http://localhost/api/v4/projects/1/pipelines/1/jobs?scope%5B%5D=failed&scope%5B%5D=success",
170+
]

‎tests/unit/objects/test_resource_groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
fromgitlab.v4.objectsimportProjectResourceGroup,ProjectResourceGroupUpcomingJob
1010

11-
from .test_jobsimportjob_content
11+
from .test_jobsimportfailed_job_content
1212

1313
resource_group_content= {
1414
"id":3,
@@ -51,7 +51,7 @@ def resp_list_upcoming_jobs():
5151
rsps.add(
5252
method=responses.GET,
5353
url="http://localhost/api/v4/projects/1/resource_groups/production/upcoming_jobs",
54-
json=[job_content],
54+
json=[failed_job_content],
5555
content_type="application/json",
5656
status=200,
5757
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp