66from typing import Any , cast
77
88from gitlab .base import RESTManager , RESTObject
9+ from gitlab .cli import register_custom_action
10+ from gitlab .exceptions import GitlabCiLintError
911from gitlab .mixins import CreateMixin , GetWithoutIdMixin
1012from gitlab .types import RequiredOptional
1113
@@ -28,9 +30,24 @@ class CiLintManager(CreateMixin, RESTManager):
2830 required = ("content" ,), optional = ("include_merged_yaml" , "include_jobs" )
2931 )
3032
33+ @register_custom_action (
34+ "CiLintManager" ,
35+ ("content" ,),
36+ optional = ("include_merged_yaml" , "include_jobs" ),
37+ )
38+ def validate (self , * args : Any , ** kwargs : Any ) -> None :
39+ """Raise an error if the CI Lint results are not valid.
40+
41+ This is a custom python-gitlab method to wrap lint endpoints."""
42+ result = self .create (* args , ** kwargs )
43+
44+ if result .status != "valid" :
45+ message = ",\n " .join (result .errors )
46+ raise GitlabCiLintError (message )
47+
3148
3249class ProjectCiLint (RESTObject ):
33- pass
50+ _id_attr = None
3451
3552
3653class ProjectCiLintManager (GetWithoutIdMixin , CreateMixin , RESTManager ):
@@ -43,3 +60,18 @@ class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager):
4360
4461 def get (self , ** kwargs : Any ) -> ProjectCiLint :
4562 return cast (ProjectCiLint , super ().get (** kwargs ))
63+
64+ @register_custom_action (
65+ "ProjectCiLintManager" ,
66+ ("content" ,),
67+ optional = ("dry_run" , "include_jobs" , "ref" ),
68+ )
69+ def validate (self , * args : Any , ** kwargs : Any ) -> None :
70+ """Raise an error if the Project CI Lint results are not valid.
71+
72+ This is a custom python-gitlab method to wrap lint endpoints."""
73+ result = self .create (* args , ** kwargs )
74+
75+ if not result .valid :
76+ message = ",\n " .join (result .errors )
77+ raise GitlabCiLintError (message )
0 commit comments