Commit 21546423 authored by Timo Furrer's avatar Timo Furrer Committed by Patrick Rice
Browse files

Extend project lint result struct with includes

parent 8523c901
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -48,6 +48,22 @@ type ProjectLintResult struct {
	Errors     []string  `json:"errors"`
	Warnings   []string  `json:"warnings"`
	MergedYaml string    `json:"merged_yaml"`
	Includes   []Include `json:"includes"`
}

// Include contains the details about an include block in the .gitlab-ci.yml file.
// It is used in ProjectLintResult.
//
// Reference can be found at the lint API endpoint in the openapi yaml:
// https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/openapi/openapi_v2.yaml
type Include struct {
	Type           string                 `json:"type"`
	Location       string                 `json:"location"`
	Blob           string                 `json:"blob"`
	Raw            string                 `json:"raw"`
	Extra          map[string]interface{} `json:"extra"`
	ContextProject string                 `json:"context_project"`
	ContextSHA     string                 `json:"context_sha"`
}

// LintOptions represents the available Lint() options.
+58 −2
Original line number Diff line number Diff line
@@ -172,13 +172,41 @@ func TestValidateProjectNamespace(t *testing.T) {
				"valid": true,
				"errors": [],
				"warnings": [],
				"merged_yaml": 	"---\n:build:\n  :script:\n  - echo build"
				"merged_yaml": 	"---\n:build:\n  :script:\n  - echo build",
				"includes": [
					{
						"type": "file",
      					"location": "template/pipeline.yml",
      					"blob": "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
      					"raw": "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
      					"extra": {
        					"project": "namespace/project",
        					"ref": "1.2.3"
      					},
      					"context_project": "namespace/current-project",
      					"context_sha": "abcd1234"
    				}
				]
			}`,
			want: &ProjectLintResult{
				Valid:      true,
				Warnings:   []string{},
				Errors:     []string{},
				MergedYaml: "---\n:build:\n  :script:\n  - echo build",
				Includes: []Include{
					{
						Type:     "file",
						Location: "template/pipeline.yml",
						Blob:     "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
						Raw:      "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
						Extra: map[string]interface{}{
							"project": "namespace/project",
							"ref":     "1.2.3",
						},
						ContextProject: "namespace/current-project",
						ContextSHA:     "abcd1234",
					},
				},
			},
		},
		{
@@ -242,13 +270,41 @@ func TestValidateProjectLint(t *testing.T) {
				"valid": true,
				"errors": [],
				"warnings": [],
				"merged_yaml": 	"---\n:build:\n  :script:\n  - echo build"
				"merged_yaml": 	"---\n:build:\n  :script:\n  - echo build",
				"includes": [
					{
						"type": "file",
      					"location": "template/pipeline.yml",
      					"blob": "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
      					"raw": "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
      					"extra": {
        					"project": "namespace/project",
        					"ref": "1.2.3"
      					},
      					"context_project": "namespace/current-project",
      					"context_sha": "abcd1234"
    				}
				]
			}`,
			want: &ProjectLintResult{
				Valid:      true,
				Warnings:   []string{},
				Errors:     []string{},
				MergedYaml: "---\n:build:\n  :script:\n  - echo build",
				Includes: []Include{
					{
						Type:     "file",
						Location: "template/pipeline.yml",
						Blob:     "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
						Raw:      "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
						Extra: map[string]interface{}{
							"project": "namespace/project",
							"ref":     "1.2.3",
						},
						ContextProject: "namespace/current-project",
						ContextSHA:     "abcd1234",
					},
				},
			},
		},
	}