Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Extend project lint result struct with includes #2070

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,26 @@ type LintResult struct {
// GitLab API docs:
// https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
type ProjectLintResult struct {
Valid bool `json:"valid"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
MergedYaml string `json:"merged_yaml"`
Valid bool `json:"valid"`
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.
Expand Down
60 changes: 58 additions & 2 deletions validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
{
Expand Down Expand Up @@ -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",
},
},
},
},
}
Expand Down
Loading