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

Commit569de2a

Browse files
feat(objects): add Project CI Lint support
Add support for validating a project's CI configuration [1][1]https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
1 parent3df404c commit569de2a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

‎docs/gl_objects/projects.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,29 @@ Get total fetches in last 30 days of a project::
819819

820820
total_fetches = project.additionalstatistics.get().fetches['total']
821821

822+
Project CI Lint
823+
=============================
824+
825+
Reference
826+
---------
827+
828+
* v4 API:
829+
830+
+:class:`gitlab.v4.objects.ProjectCiLint`
831+
+:class:`gitlab.v4.objects.ProjectCiLintManager`
832+
+:attr:`gitlab.v4.objects.Project.ci_lint`
833+
834+
* GitLab API: https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
835+
836+
Examples
837+
---------
838+
839+
Validate a project's CI configuration::
840+
841+
lint_result = project.ci_lint.get()
842+
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
843+
print(lint_result.merged_yaml) # Print the merged YAML file
844+
822845
Project storage
823846
=============================
824847

‎gitlab/v4/objects/projects.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
GitLab API:
3+
https://docs.gitlab.com/ee/api/projects.html
4+
https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
5+
"""
16
fromtypingimport (
27
Any,
38
Callable,
@@ -97,6 +102,8 @@
97102
"ProjectRemoteMirrorManager",
98103
"ProjectStorage",
99104
"ProjectStorageManager",
105+
"ProjectCiLint",
106+
"ProjectCiLintManager",
100107
]
101108

102109

@@ -158,6 +165,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
158165
badges:ProjectBadgeManager
159166
boards:ProjectBoardManager
160167
branches:ProjectBranchManager
168+
ci_lint:"ProjectCiLintManager"
161169
clusters:ProjectClusterManager
162170
commits:ProjectCommitManager
163171
customattributes:ProjectCustomAttributeManager
@@ -1055,3 +1063,17 @@ class ProjectStorageManager(GetWithoutIdMixin, RESTManager):
10551063

10561064
defget(self,**kwargs:Any)->ProjectStorage:
10571065
returncast(ProjectStorage,super().get(**kwargs))
1066+
1067+
1068+
classProjectCiLint(RESTObject):
1069+
pass
1070+
1071+
1072+
classProjectCiLintManager(GetWithoutIdMixin,RESTManager):
1073+
_path="/projects/{project_id}/ci/lint"
1074+
_obj_cls=ProjectCiLint
1075+
_from_parent_attrs= {"project_id":"id"}
1076+
# https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
1077+
1078+
defget(self,**kwargs:Any)->ProjectCiLint:
1079+
returncast(ProjectCiLint,super().get(**kwargs))

‎tests/unit/objects/test_projects.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
"status":"created",
8383
"source":"trigger",
8484
}
85+
ci_lint_get_content= {
86+
"valid":True,
87+
"merged_yaml":"---\n:test_job:\n :script: echo 1\n",
88+
"errors": [],
89+
"warnings": [],
90+
}
8591

8692

8793
@pytest.fixture
@@ -541,6 +547,19 @@ def resp_artifact():
541547
yieldrsps
542548

543549

550+
@pytest.fixture
551+
defresp_ci_lint():
552+
withresponses.RequestsMock()asrsps:
553+
rsps.add(
554+
method=responses.GET,
555+
url="http://localhost/api/v4/projects/1/ci/lint",
556+
json=ci_lint_get_content,
557+
content_type="application/json",
558+
status=200,
559+
)
560+
yieldrsps
561+
562+
544563
deftest_get_project(gl,resp_get_project):
545564
data=gl.projects.get(1)
546565
assertisinstance(data,Project)
@@ -756,3 +775,8 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project):
756775
deftest_project_snapshot(project,resp_snapshot_project):
757776
tar_file=project.snapshot()
758777
assertisinstance(tar_file,bytes)
778+
779+
780+
deftest_project_ci_lint_get(project,resp_ci_lint):
781+
lint_result=project.ci_lint.get()
782+
assertlint_result.validisTrue

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp