Skip to content

Commit

Permalink
add tag to ruleset for deployment event, if it is from a tag #606 (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayCeeJr committed Jun 2, 2022
1 parent ef0c7a1 commit 748bcb3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/step/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func Skip(c *pipeline.Container, b *library.Build, r *library.Repo) bool {

// check if the build event is deployment
if strings.EqualFold(b.GetEvent(), constants.EventDeploy) {
// handle when deployment event is for a tag
if strings.HasPrefix(b.GetRef(), "refs/tags/") {
// add tag information to ruledata with refs/tags prefix removed
ruledata.Tag = strings.TrimPrefix(b.GetRef(), "refs/tags/")
}
// add deployment target information to ruledata
ruledata.Target = b.GetDeploy()
}
Expand Down
35 changes: 35 additions & 0 deletions internal/step/skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ func TestStep_Skip(t *testing.T) {
Distribution: vela.String("linux"),
}

_deployFromTag := &library.Build{
ID: vela.Int64(1),
Number: vela.Int(1),
Parent: vela.Int(1),
Event: vela.String("deployment"),
EventAction: vela.String(""),
Status: vela.String("success"),
Error: vela.String(""),
Enqueued: vela.Int64(1563474077),
Created: vela.Int64(1563474076),
Started: vela.Int64(1563474077),
Finished: vela.Int64(0),
Deploy: vela.String(""),
Clone: vela.String("https://github.com/github/octocat.git"),
Source: vela.String("https://github.com/github/octocat/abcdefghi123456789"),
Title: vela.String("push received from https://github.com/github/octocat"),
Message: vela.String("First commit..."),
Commit: vela.String("48afb5bdc41ad69bf22588491333f7cf71135163"),
Sender: vela.String("OctoKitty"),
Author: vela.String("OctoKitty"),
Branch: vela.String("master"),
Ref: vela.String("refs/tags/v1.0.0"),
BaseRef: vela.String(""),
Host: vela.String("example.company.com"),
Runtime: vela.String("docker"),
Distribution: vela.String("linux"),
}

_tag := &library.Build{
ID: vela.Int64(1),
Number: vela.Int(1),
Expand Down Expand Up @@ -183,6 +211,13 @@ func TestStep_Skip(t *testing.T) {
repo: _repo,
want: false,
},
{
name: "deployFromTag",
build: _deployFromTag,
container: _container,
repo: _repo,
want: false,
},
{
name: "tag",
build: _tag,
Expand Down

0 comments on commit 748bcb3

Please sign in to comment.