From cc5c89568c266c44665f9c5b6d514266ce1fd469 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Thu, 26 Oct 2023 13:10:37 -0500 Subject: [PATCH 1/3] enhance(api/webhook): update hook status to skipped when build is skipped --- api/build/skip.go | 8 ++++---- api/webhook/post.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/build/skip.go b/api/build/skip.go index 2d934fb93..8a6eeeeb7 100644 --- a/api/build/skip.go +++ b/api/build/skip.go @@ -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." } } diff --git a/api/webhook/post.go b/api/webhook/post.go index aa4449194..47562f80f 100644 --- a/api/webhook/post.go +++ b/api/webhook/post.go @@ -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 { From 3dfc0e48fd72c4345c3eeb94a1bff77776050b46 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Thu, 26 Oct 2023 14:16:08 -0500 Subject: [PATCH 2/3] fix tests --- api/build/skip_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/build/skip_test.go b/api/build/skip_test.go index 27cf416bd..f3aba19ab 100644 --- a/api/build/skip_test.go +++ b/api/build/skip_test.go @@ -22,7 +22,7 @@ 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", @@ -30,7 +30,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { 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", @@ -46,7 +46,7 @@ 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", @@ -54,7 +54,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { 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", From c8be89cd7753d3d5bbe65f7d1dde33e0a4f6f818 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Thu, 26 Oct 2023 18:13:17 -0500 Subject: [PATCH 3/3] =?UTF-8?q?use=20lowercase=20and=20=E2=80=94=20in=20sk?= =?UTF-8?q?ip=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/build/skip.go | 8 ++++---- api/build/skip_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/build/skip.go b/api/build/skip.go index 8a6eeeeb7..0987e99f6 100644 --- a/api/build/skip.go +++ b/api/build/skip.go @@ -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. It is likely no rulesets matched for the webhook payload." + 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. It is likely no rulesets matched for the webhook payload." + 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. It is likely no rulesets matched for the webhook payload." + 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. It is likely no rulesets matched for the webhook payload." + return "skipping build since only init and clone steps found — it is likely no rulesets matched for the webhook payload" } } diff --git a/api/build/skip_test.go b/api/build/skip_test.go index f3aba19ab..f55163227 100644 --- a/api/build/skip_test.go +++ b/api/build/skip_test.go @@ -22,7 +22,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "init", }, - }}}, "skipping build since only init stage found. It is likely no rulesets matched for the webhook payload."}, + }}}, "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", @@ -30,7 +30,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "clone", }, - }}}, "skipping build since only init and clone stages found. It is likely no rulesets matched for the webhook payload."}, + }}}, "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", @@ -46,7 +46,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "init", }, - }}}, "skipping build since only init step found. It is likely no rulesets matched for the webhook payload."}, + }}}, "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", @@ -54,7 +54,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "clone", }, - }}}, "skipping build since only init and clone steps found. It is likely no rulesets matched for the webhook payload."}, + }}}, "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",