Skip to content

Commit ddb971f

Browse files
authored
fix(pipeline): validate presence of tag on tag events to avoid panic (#529)
1 parent 08b96be commit ddb971f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

action/pipeline/validate.go

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/go-vela/cli/internal/output"
1212
"github.com/go-vela/sdk-go/vela"
13+
"github.com/go-vela/types/constants"
1314
"github.com/go-vela/types/library"
1415

1516
"github.com/go-vela/server/compiler"
@@ -69,6 +70,10 @@ func (c *Config) Validate() error {
6970
return fmt.Errorf("invalid format for template file: %s (valid format: <name>:<source>)", file)
7071
}
7172
}
73+
case "exec":
74+
if strings.EqualFold(c.Event, constants.EventTag) && len(c.Tag) == 0 {
75+
return fmt.Errorf("no tag provided for tag event")
76+
}
7277
}
7378

7479
return nil

action/pipeline/validate_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ func TestPipeline_Config_Validate(t *testing.T) {
3232
Output: "",
3333
},
3434
},
35+
{
36+
failure: true,
37+
config: &Config{
38+
Action: "exec",
39+
Org: "github",
40+
Repo: "octocat",
41+
Event: "tag",
42+
},
43+
},
44+
{
45+
failure: false,
46+
config: &Config{
47+
Action: "exec",
48+
Org: "github",
49+
Repo: "octocat",
50+
Event: "tag",
51+
Tag: "v1.0.0",
52+
},
53+
},
3554
{
3655
failure: false,
3756
config: &Config{

0 commit comments

Comments
 (0)