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

Commit afed20c

Browse files
committed
Extend project lint result struct with includes
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.
1 parent 01aa9b5 commit afed20c

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

validate.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,26 @@ type LintResult struct {
4444
// GitLab API docs:
4545
// https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
4646
type ProjectLintResult struct {
47-
Valid bool `json:"valid"`
48-
Errors []string `json:"errors"`
49-
Warnings []string `json:"warnings"`
50-
MergedYaml string `json:"merged_yaml"`
47+
Valid bool `json:"valid"`
48+
Errors []string `json:"errors"`
49+
Warnings []string `json:"warnings"`
50+
MergedYaml string `json:"merged_yaml"`
51+
Includes []Include `json:"includes"`
52+
}
53+
54+
// Include contains the details about an include block in the .gitlab-ci.yml file.
55+
// It is used in ProjectLintResult.
56+
//
57+
// Reference can be found at the lint API endpoint in the openapi yaml:
58+
// https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/openapi/openapi_v2.yaml
59+
type Include struct {
60+
Type string `json:"type"`
61+
Location string `json:"location"`
62+
Blob string `json:"blob"`
63+
Raw string `json:"raw"`
64+
Extra map[string]interface{} `json:"extra"`
65+
ContextProject string `json:"context_project"`
66+
ContextSHA string `json:"context_sha"`
5167
}
5268

5369
// LintOptions represents the available Lint() options.

validate_test.go

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,41 @@ func TestValidateProjectNamespace(t *testing.T) {
172172
"valid": true,
173173
"errors": [],
174174
"warnings": [],
175-
"merged_yaml": "---\n:build:\n :script:\n - echo build"
175+
"merged_yaml": "---\n:build:\n :script:\n - echo build",
176+
"includes": [
177+
{
178+
"type": "file",
179+
"location": "template/pipeline.yml",
180+
"blob": "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
181+
"raw": "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
182+
"extra": {
183+
"project": "namespace/project",
184+
"ref": "1.2.3"
185+
},
186+
"context_project": "namespace/current-project",
187+
"context_sha": "abcd1234"
188+
}
189+
]
176190
}`,
177191
want: &ProjectLintResult{
178192
Valid: true,
179193
Warnings: []string{},
180194
Errors: []string{},
181195
MergedYaml: "---\n:build:\n :script:\n - echo build",
196+
Includes: []Include{
197+
{
198+
Type: "file",
199+
Location: "template/pipeline.yml",
200+
Blob: "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
201+
Raw: "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
202+
Extra: map[string]interface{}{
203+
"project": "namespace/project",
204+
"ref": "1.2.3",
205+
},
206+
ContextProject: "namespace/current-project",
207+
ContextSHA: "abcd1234",
208+
},
209+
},
182210
},
183211
},
184212
{
@@ -242,13 +270,41 @@ func TestValidateProjectLint(t *testing.T) {
242270
"valid": true,
243271
"errors": [],
244272
"warnings": [],
245-
"merged_yaml": "---\n:build:\n :script:\n - echo build"
273+
"merged_yaml": "---\n:build:\n :script:\n - echo build",
274+
"includes": [
275+
{
276+
"type": "file",
277+
"location": "template/pipeline.yml",
278+
"blob": "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
279+
"raw": "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
280+
"extra": {
281+
"project": "namespace/project",
282+
"ref": "1.2.3"
283+
},
284+
"context_project": "namespace/current-project",
285+
"context_sha": "abcd1234"
286+
}
287+
]
246288
}`,
247289
want: &ProjectLintResult{
248290
Valid: true,
249291
Warnings: []string{},
250292
Errors: []string{},
251293
MergedYaml: "---\n:build:\n :script:\n - echo build",
294+
Includes: []Include{
295+
{
296+
Type: "file",
297+
Location: "template/pipeline.yml",
298+
Blob: "https://gitlab.com/namespace/project/-/blob/abcd1234/template/pipeline.yml",
299+
Raw: "https://gitlab.com/namespace/project/-/raw/abcd1234/template/pipeline.yml",
300+
Extra: map[string]interface{}{
301+
"project": "namespace/project",
302+
"ref": "1.2.3",
303+
},
304+
ContextProject: "namespace/current-project",
305+
ContextSHA: "abcd1234",
306+
},
307+
},
252308
},
253309
},
254310
}

0 commit comments

Comments
 (0)