| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 91c17b7 commit b213dd3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -819,6 +819,49 @@ Get total fetches in last 30 days of a project:: | |||
| 819 | 819 | ||
| 820 | 820 | total_fetches = project.additionalstatistics.get().fetches['total'] | |
| 821 | 821 | ||
| 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 | ||
| 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 | + | ||
| 845 | + Validate a CI YAML configuration with a namespace:: | ||
| 846 | + | ||
| 847 | + gitlab_ci_yml = """.api_test: | ||
| 848 | + rules: | ||
| 849 | + - if: $CI_PIPELINE_SOURCE=="merge_request_event" | ||
| 850 | + changes: | ||
| 851 | + - src/api/* | ||
| 852 | + deploy: | ||
| 853 | + extends: | ||
| 854 | + - .api_test | ||
| 855 | + rules: | ||
| 856 | + - when: manual | ||
| 857 | + allow_failure: true | ||
| 858 | + script: | ||
| 859 | + - echo "hello world" | ||
| 860 | + """ | ||
| 861 | + lint_result = project.ci_lint.create({"content": gitlab_ci_yml}) | ||
| 862 | + assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid | ||
| 863 | + print(lint_result.merged_yaml) # Print the merged YAML file | ||
| 864 | + | ||
| 822 | 865 | Project storage | |
| 823 | 866 | ============================= | |
| 824 | 867 | ||
| Original file line number | Diff line number | Diff 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 | ||
| 5 | + """ | ||
| 1 | 6 | from typing import ( | |
| 2 | 7 | Any, | |
| 3 | 8 | Callable, | |
@@ -97,6 +102,8 @@ | |||
| 97 | 102 | "ProjectRemoteMirrorManager", | |
| 98 | 103 | "ProjectStorage", | |
| 99 | 104 | "ProjectStorageManager", | |
| 105 | + "ProjectCiLint", | ||
| 106 | + "ProjectCiLintManager", | ||
| 100 | 107 | ] | |
| 101 | 108 | ||
| 102 | 109 | ||
@@ -158,6 +165,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO | |||
| 158 | 165 | badges: ProjectBadgeManager | |
| 159 | 166 | boards: ProjectBoardManager | |
| 160 | 167 | branches: ProjectBranchManager | |
| 168 | + ci_lint: "ProjectCiLintManager" | ||
| 161 | 169 | clusters: ProjectClusterManager | |
| 162 | 170 | commits: ProjectCommitManager | |
| 163 | 171 | customattributes: ProjectCustomAttributeManager | |
@@ -1055,3 +1063,18 @@ class ProjectStorageManager(GetWithoutIdMixin, RESTManager): | |||
| 1055 | 1063 | ||
| 1056 | 1064 | def get(self, **kwargs: Any) -> ProjectStorage: | |
| 1057 | 1065 | return cast(ProjectStorage, super().get(**kwargs)) | |
| 1066 | + | ||
| 1067 | + | ||
| 1068 | + class ProjectCiLint(RESTObject): | ||
| 1069 | + pass | ||
| 1070 | + | ||
| 1071 | + | ||
| 1072 | + class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager): | ||
| 1073 | + """GitLab API: https://docs.gitlab.com/ee/api/lint.html""" | ||
| 1074 | + | ||
| 1075 | + _path = "/projects/{project_id}/ci/lint" | ||
| 1076 | + _obj_cls = ProjectCiLint | ||
| 1077 | + _from_parent_attrs = {"project_id": "id"} | ||
| 1078 | + | ||
| 1079 | + def get(self, **kwargs: Any) -> ProjectCiLint: | ||
| 1080 | + return cast(ProjectCiLint, super().get(**kwargs)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,6 +82,12 @@ | |||
| 82 | 82 | "status": "created", | |
| 83 | 83 | "source": "trigger", | |
| 84 | 84 | } | |
| 85 | + ci_lint_get_content = { | ||
| 86 | + "valid": True, | ||
| 87 | + "merged_yaml": "---\n:test_job:\n :script: echo 1\n", | ||
| 88 | + "errors": [], | ||
| 89 | + "warnings": [], | ||
| 90 | + } | ||
| 85 | 91 | ||
| 86 | 92 | ||
| 87 | 93 | @pytest.fixture | |
@@ -541,6 +547,32 @@ def resp_artifact(): | |||
| 541 | 547 | yield rsps | |
| 542 | 548 | ||
| 543 | 549 | ||
| 550 | + @pytest.fixture | ||
| 551 | + def resp_get_ci_lint(): | ||
| 552 | + with responses.RequestsMock() as rsps: | ||
| 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 | + yield rsps | ||
| 561 | + | ||
| 562 | + | ||
| 563 | + @pytest.fixture | ||
| 564 | + def resp_create_ci_lint(): | ||
| 565 | + with responses.RequestsMock() as rsps: | ||
| 566 | + rsps.add( | ||
| 567 | + method=responses.POST, | ||
| 568 | + url="http://localhost/api/v4/projects/1/ci/lint", | ||
| 569 | + json=ci_lint_get_content, | ||
| 570 | + content_type="application/json", | ||
| 571 | + status=200, | ||
| 572 | + ) | ||
| 573 | + yield rsps | ||
| 574 | + | ||
| 575 | + | ||
| 544 | 576 | def test_get_project(gl, resp_get_project): | |
| 545 | 577 | data = gl.projects.get(1) | |
| 546 | 578 | assert isinstance(data, Project) | |
@@ -756,3 +788,17 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project): | |||
| 756 | 788 | def test_project_snapshot(project, resp_snapshot_project): | |
| 757 | 789 | tar_file = project.snapshot() | |
| 758 | 790 | assert isinstance(tar_file, bytes) | |
| 791 | + | ||
| 792 | + | ||
| 793 | + def test_project_ci_lint_get(project, resp_get_ci_lint): | ||
| 794 | + lint_result = project.ci_lint.get() | ||
| 795 | + assert lint_result.valid is True | ||
| 796 | + | ||
| 797 | + | ||
| 798 | + def test_project_ci_lint_create(project, resp_create_ci_lint): | ||
| 799 | + gitlab_ci_yml = """--- | ||
| 800 | + :test_job: | ||
| 801 | + :script: echo 1 | ||
| 802 | + """ | ||
| 803 | + lint_result = project.ci_lint.create({"content": gitlab_ci_yml}) | ||
| 804 | + assert lint_result.valid is True | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments