Skip to content

Commit 3e8562d

Browse files
feat(objects): add Project CI Lint support
Add support for validating a project's CI configuration [1] TODO: Add tests [1] https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
1 parent 09b3b22 commit 3e8562d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

docs/gl_objects/projects.rst

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

785785
total_fetches = project.additionalstatistics.get().fetches['total']
786786

787+
Project CI Lint
788+
=============================
789+
790+
Reference
791+
---------
792+
793+
* v4 API:
794+
795+
+ :class:`gitlab.v4.objects.ProjectCiLint`
796+
+ :class:`gitlab.v4.objects.ProjectCiLintManager`
797+
+ :attr:`gitlab.v4.objects.Project.ci_lint`
798+
799+
* GitLab API: https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
800+
801+
Examples
802+
---------
803+
804+
Validate a project's CI configuration::
805+
806+
lint_result = project.ci_lint.get()
807+
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
808+
print(lint_result.merged_yaml) # Print the merged YAML file
809+
787810
Project storage
788811
=============================
789812

gitlab/v4/objects/projects.py

Lines changed: 32 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
from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING, Union
27

38
import requests
@@ -83,6 +88,8 @@
8388
"ProjectRemoteMirrorManager",
8489
"ProjectStorage",
8590
"ProjectStorageManager",
91+
"ProjectCiLint",
92+
"ProjectCiLintManager",
8693
]
8794

8895

@@ -144,6 +151,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
144151
badges: ProjectBadgeManager
145152
boards: ProjectBoardManager
146153
branches: ProjectBranchManager
154+
ci_lint: "ProjectCiLintManager"
147155
clusters: ProjectClusterManager
148156
commits: ProjectCommitManager
149157
customattributes: ProjectCustomAttributeManager
@@ -1032,3 +1040,27 @@ def get(
10321040
self, id: Optional[Union[int, str]] = None, **kwargs: Any
10331041
) -> Optional[ProjectStorage]:
10341042
return cast(Optional[ProjectStorage], super().get(id=id, **kwargs))
1043+
1044+
1045+
class ProjectCiLint(RESTObject):
1046+
pass
1047+
1048+
1049+
class ProjectCiLintManager(GetWithoutIdMixin, RESTManager):
1050+
_path = "/projects/{project_id}/ci/lint"
1051+
_obj_cls = ProjectCiLint
1052+
_from_parent_attrs = {"project_id": "id"}
1053+
# https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
1054+
1055+
def get(
1056+
self, id: Optional[Union[int, str]] = None, **kwargs: Any
1057+
) -> Optional[ProjectCiLint]:
1058+
if id is not None:
1059+
raise AttributeError("Unsupported attribute: id")
1060+
1061+
if TYPE_CHECKING:
1062+
assert self.path is not None
1063+
server_data = self.gitlab.http_get(self.path, **kwargs)
1064+
if TYPE_CHECKING:
1065+
assert isinstance(server_data, dict)
1066+
return self._obj_cls(self, server_data)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy