Skip to content

Commit 076fa90

Browse files
authored
Merge pull request #1922 from sergiodj/extend-git-checkout-tag-or-branch
lint: Extend `valid-pipeline-git-checkout-tag` to account for `branch`
2 parents f71b9c4 + 051334d commit 076fa90

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

pkg/lint/rules.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,17 @@ var AllRules = func(l *Linter) Rules { //nolint:gocyclo
353353
},
354354
},
355355
{
356-
Name: "valid-pipeline-git-checkout-tag",
357-
Description: "every git-checkout pipeline should have a tag",
356+
Name: "valid-pipeline-git-checkout-tag-or-branch",
357+
Description: "every git-checkout pipeline should have a tag or branch",
358358
Severity: SeverityError,
359359
LintFunc: func(config config.Configuration) error {
360360
for _, p := range config.Pipeline {
361361
if p.Uses == gitCheckout {
362-
if _, ok := p.With["tag"]; !ok {
363-
return fmt.Errorf("tag is missing")
362+
_, hasTag := p.With["tag"]
363+
_, hasBranch := p.With["branch"]
364+
// "branch" and "tag" are mutually exclusive
365+
if !hasTag && !hasBranch {
366+
return fmt.Errorf("tag or branch is missing")
364367
}
365368
}
366369
}

pkg/lint/rules_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,17 @@ func TestLinter_Rules(t *testing.T) {
312312
matches: 1,
313313
},
314314
{
315-
file: "wrong-pipeline-git-checkout-tag.yaml",
315+
file: "wrong-pipeline-git-checkout-tag-or-branch.yaml",
316316
minSeverity: SeverityWarning,
317317
want: EvalResult{
318-
File: "wrong-pipeline-git-checkout-tag",
318+
File: "wrong-pipeline-git-checkout-tag-or-branch",
319319
Errors: EvalRuleErrors{
320320
{
321321
Rule: Rule{
322-
Name: "valid-pipeline-git-checkout-tag",
322+
Name: "valid-pipeline-git-checkout-tag-or-branch",
323323
Severity: SeverityError,
324324
},
325-
Error: fmt.Errorf("[valid-pipeline-git-checkout-tag]: tag is missing (ERROR)"),
325+
Error: fmt.Errorf("[valid-pipeline-git-checkout-tag-or-branch]: tag or branch is missing (ERROR)"),
326326
},
327327
},
328328
},

pkg/lint/testdata/files/wrong-pipeline-git-checkout-tag.yaml renamed to pkg/lint/testdata/files/wrong-pipeline-git-checkout-tag-or-branch.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package:
2-
name: wrong-pipeline-git-checkout-tag
2+
name: wrong-pipeline-git-checkout-tag-or-branch
33
version: 1.0.0
44
epoch: 0
5-
description: "a package with missing pipeline git-checkout tag"
5+
description: "a package with missing pipeline git-checkout tag or branch"
66
copyright:
77
- paths:
88
- "*"
@@ -13,7 +13,6 @@ pipeline:
1313
- uses: git-checkout
1414
with:
1515
repository: https://test.com/missing-copyright/${{package.version}}.tar.gz
16-
branch: main
1716
expected-commit: 9c5cfe0525dc7415cec482342ca674875c1e9115
1817
update:
1918
enabled: true

0 commit comments

Comments
 (0)