Skip to content

Commit faf0966

Browse files
feat: add method to checkout step fields (#365)
1 parent 7cb12a9 commit faf0966

File tree

7 files changed

+93
-2
lines changed

7 files changed

+93
-2
lines changed

pkg/ast/step.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func (step Run) GetName() string {
8282

8383
type Checkout struct {
8484
protocol.Range
85-
Path string
85+
Path string
86+
Method string
8687
}
8788

8889
func (step Checkout) GetRange() protocol.Range {

pkg/parser/steps.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ func (doc *YamlDocument) parseCheckoutStep(checkoutNode *sitter.Node) ast.Checko
302302
switch keyName {
303303
case "path":
304304
res.Path = doc.GetNodeText(valueNode)
305+
case "method":
306+
res.Method = doc.GetNodeText(valueNode)
305307
}
306308
})
307309
return res

pkg/parser/validate/steps.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func (val Validate) validateSteps(steps []ast.Step, name string, jobOrCommandPar
3131
val.validateNamedStep(step, jobOrCommandParameters)
3232
case ast.Steps:
3333
val.validateStepSteps(step, name)
34+
case ast.Checkout:
35+
val.validateCheckout(step)
3436
}
3537
}
3638
return nil
@@ -211,6 +213,21 @@ func (val Validate) validateStepSteps(step ast.Steps, name string) {
211213
}
212214
}
213215

216+
func (val Validate) validateCheckout(step ast.Checkout) {
217+
if step.Method == "" {
218+
return
219+
}
220+
221+
m := []string{"blobless", "full"}
222+
if !slices.Contains(m, step.Method) {
223+
val.addDiagnostic(protocol.Diagnostic{
224+
Severity: protocol.DiagnosticSeverityError,
225+
Range: step.Range,
226+
Message: fmt.Sprintf("Checkout method '%s' is invalid", step.Method),
227+
})
228+
}
229+
}
230+
214231
func (val Validate) checkIfStepsContainStep(steps []ast.Step, stepName string) bool {
215232
for _, step := range steps {
216233
if step.GetName() == stepName {

pkg/parser/validate/steps_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package validate
22

33
import (
4+
"os"
45
"testing"
56

67
"go.lsp.dev/protocol"
@@ -69,3 +70,40 @@ workflows:
6970

7071
CheckYamlErrors(t, testCases)
7172
}
73+
74+
func TestYamlDocument_parseCheckout(t *testing.T) {
75+
validConfigFilePath := "./testdata/valid_checkout_method.yml"
76+
validConfig, err := os.ReadFile(validConfigFilePath)
77+
if err != nil {
78+
t.Fatal("Failed to read valid_checkout_method.yml")
79+
}
80+
81+
invalidConfigFilePath := "./testdata/invalid_checkout_method.yml"
82+
invalidConfig, err := os.ReadFile(invalidConfigFilePath)
83+
if err != nil {
84+
t.Fatal("Failed to read invalid_checkout_method.yml")
85+
}
86+
87+
testCases := []ValidateTestCase{
88+
{
89+
Name: "Specifying checkout method full does not result in an error",
90+
YamlContent: string(validConfig),
91+
Diagnostics: []protocol.Diagnostic{},
92+
},
93+
{
94+
Name: "Specifying an invalid checkout method results in an error",
95+
YamlContent: string(invalidConfig),
96+
Diagnostics: []protocol.Diagnostic{
97+
{
98+
Severity: protocol.DiagnosticSeverityError,
99+
Range: protocol.Range{
100+
Start: protocol.Position{Line: 7, Character: 8},
101+
End: protocol.Position{Line: 7, Character: 16},
102+
},
103+
Message: "Checkout method 'invalid' is invalid",
104+
},
105+
},
106+
},
107+
}
108+
CheckYamlErrors(t, testCases)
109+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2.1
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: cimg/base:stable
7+
steps:
8+
- checkout:
9+
method: "invalid"
10+
- run: echo "hello world"
11+
12+
workflows:
13+
test-build:
14+
jobs:
15+
- build
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2.1
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: cimg/base:stable
7+
steps:
8+
- checkout:
9+
method: full
10+
- run: echo "hello world"
11+
12+
workflows:
13+
test-build:
14+
jobs:
15+
- build

publicschema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,10 @@
687687
"path": {
688688
"description": "Checkout directory (default: job's `working_directory`)",
689689
"type": "string"
690-
}
690+
},
691+
"method": {
692+
"description": "The checkout method to be used ('blobless' or 'full', default 'full')",
693+
"type": "string"
691694
}
692695
},
693696
"setup_remote_docker": {

0 commit comments

Comments
 (0)