Skip to content

Commit

Permalink
enhance(api/webhook): update hook status to skipped when build is ski…
Browse files Browse the repository at this point in the history
…pped (#993)

* enhance(api/webhook): update hook status to skipped when build is skipped

* fix tests

* use lowercase and — in skip message
  • Loading branch information
ecrupper authored Oct 27, 2023
1 parent e12a3dd commit 262d7f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions api/build/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import (
func SkipEmptyBuild(p *pipeline.Build) string {
if len(p.Stages) == 1 {
if p.Stages[0].Name == "init" {
return "skipping build since only init stage found"
return "skipping build since only init stage found — it is likely no rulesets matched for the webhook payload"
}
}

if len(p.Stages) == 2 {
if p.Stages[0].Name == "init" && p.Stages[1].Name == "clone" {
return "skipping build since only init and clone stages found"
return "skipping build since only init and clone stages found — it is likely no rulesets matched for the webhook payload"
}
}

if len(p.Steps) == 1 {
if p.Steps[0].Name == "init" {
return "skipping build since only init step found"
return "skipping build since only init step found — it is likely no rulesets matched for the webhook payload"
}
}

if len(p.Steps) == 2 {
if p.Steps[0].Name == "init" && p.Steps[1].Name == "clone" {
return "skipping build since only init and clone steps found"
return "skipping build since only init and clone steps found — it is likely no rulesets matched for the webhook payload"
}
}

Expand Down
8 changes: 4 additions & 4 deletions api/build/skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func Test_SkipEmptyBuild(t *testing.T) {
{
Name: "init",
},
}}}, "skipping build since only init stage found"},
}}}, "skipping build since only init stage found — it is likely no rulesets matched for the webhook payload"},
{"init and clone stages", args{p: &pipeline.Build{Stages: []*pipeline.Stage{
{
Name: "init",
},
{
Name: "clone",
},
}}}, "skipping build since only init and clone stages found"},
}}}, "skipping build since only init and clone stages found — it is likely no rulesets matched for the webhook payload"},
{"three stages", args{p: &pipeline.Build{Stages: []*pipeline.Stage{
{
Name: "init",
Expand All @@ -46,15 +46,15 @@ func Test_SkipEmptyBuild(t *testing.T) {
{
Name: "init",
},
}}}, "skipping build since only init step found"},
}}}, "skipping build since only init step found — it is likely no rulesets matched for the webhook payload"},
{"init and clone steps", args{p: &pipeline.Build{Steps: []*pipeline.Container{
{
Name: "init",
},
{
Name: "clone",
},
}}}, "skipping build since only init and clone steps found"},
}}}, "skipping build since only init and clone steps found — it is likely no rulesets matched for the webhook payload"},
{"three steps", args{p: &pipeline.Build{Steps: []*pipeline.Container{
{
Name: "init",
Expand Down
4 changes: 4 additions & 0 deletions api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ func PostWebhook(c *gin.Context) {
// set build to successful status
b.SetStatus(constants.StatusSkipped)

// set hook status and message
h.SetStatus(constants.StatusSkipped)
h.SetError(skip)

// send API call to set the status on the commit
err = scm.FromContext(c).Status(ctx, u, b, repo.GetOrg(), repo.GetName())
if err != nil {
Expand Down

0 comments on commit 262d7f0

Please sign in to comment.