-
Notifications
You must be signed in to change notification settings - Fork 676
Expand file tree
/
Copy pathci_lint.py
More file actions
79 lines (61 loc) · 2.2 KB
/
ci_lint.py
File metadata and controls
79 lines (61 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
GitLab API:
https://docs.gitlab.com/ee/api/lint.html
"""
from typing import Any
from gitlab.base import RESTObject
from gitlab.cli import register_custom_action
from gitlab.exceptions import GitlabCiLintError
from gitlab.mixins import CreateMixin, GetWithoutIdMixin
from gitlab.types import RequiredOptional
__all__ = ["CiLint", "CiLintManager", "ProjectCiLint", "ProjectCiLintManager"]
class CiLint(RESTObject):
_id_attr = None
class CiLintManager(CreateMixin[CiLint]):
_path = "/ci/lint"
_obj_cls = CiLint
_create_attrs = RequiredOptional(
required=("content",), optional=("include_merged_yaml", "include_jobs")
)
@register_custom_action(
cls_names="CiLintManager",
required=("content",),
optional=("include_merged_yaml", "include_jobs"),
)
def validate(self, *args: Any, **kwargs: Any) -> None:
"""Raise an error if the CI Lint results are not valid.
This is a custom python-gitlab method to wrap lint endpoints."""
result = self.create(*args, **kwargs)
if result.status != "valid":
message = ",\n".join(result.errors)
raise GitlabCiLintError(message)
class ProjectCiLint(RESTObject):
_id_attr = None
class ProjectCiLintManager(
GetWithoutIdMixin[ProjectCiLint], CreateMixin[ProjectCiLint]
):
_path = "/projects/{project_id}/ci/lint"
_obj_cls = ProjectCiLint
_from_parent_attrs = {"project_id": "id"}
_optional_get_attrs = (
"content_ref",
"dry_run",
"dry_run_ref",
"include_jobs",
"ref",
)
_create_attrs = RequiredOptional(
required=("content",), optional=("dry_run", "include_jobs", "ref")
)
@register_custom_action(
cls_names="ProjectCiLintManager",
required=("content",),
optional=("dry_run", "include_jobs", "ref"),
)
def validate(self, *args: Any, **kwargs: Any) -> None:
"""Raise an error if the Project CI Lint results are not valid.
This is a custom python-gitlab method to wrap lint endpoints."""
result = self.create(*args, **kwargs)
if not result.valid:
message = ",\n".join(result.errors)
raise GitlabCiLintError(message)