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

Commit

Permalink
Extend project lint result struct with includes
Browse files Browse the repository at this point in the history
The Gitlab API exposes a list of (recursive) includes when linting
a projects ci configuration. The ProjectLintResult struct representing
the API response does not reflect this list, so a user of the SDK
cannot use this information from the API.
  • Loading branch information
TheCodear committed Dec 3, 2024
1 parent 35c2003 commit 9170949
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
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

0 comments on commit 9170949

Please sign in to comment.