mirror of https://github.com/harness/drone.git
Enhance status check label for promotions (#3263)
* Better status check label for promotions * slugify deployTopull/3290/head
parent
99cb5c1456
commit
fa73a8531b
|
@ -84,7 +84,7 @@ func (s *service) Send(ctx context.Context, user *core.User, req *core.StatusInp
|
|||
_, _, err = s.client.Repositories.CreateStatus(ctx, req.Repo.Slug, req.Build.After, &scm.StatusInput{
|
||||
Title: fmt.Sprintf("Build #%d", req.Build.Number),
|
||||
Desc: createDesc(req.Build.Status),
|
||||
Label: createLabel(s.name, req.Build.Event),
|
||||
Label: createLabel(s.name, req.Build.Event, req.Build.Deploy),
|
||||
State: convertStatus(req.Build.Status),
|
||||
Target: fmt.Sprintf("%s/%s/%d", s.base, req.Repo.Slug, req.Build.Number),
|
||||
})
|
||||
|
|
|
@ -19,9 +19,10 @@ import (
|
|||
|
||||
"github.com/drone/drone/core"
|
||||
"github.com/drone/go-scm/scm"
|
||||
"github.com/gosimple/slug"
|
||||
)
|
||||
|
||||
func createLabel(name, event string) string {
|
||||
func createLabel(name, event, deployTo string) string {
|
||||
if name == "" {
|
||||
name = "continuous-integration/drone"
|
||||
}
|
||||
|
@ -32,6 +33,8 @@ func createLabel(name, event string) string {
|
|||
return fmt.Sprintf("%s/pr", name)
|
||||
case core.EventTag:
|
||||
return fmt.Sprintf("%s/tag", name)
|
||||
case core.EventPromote:
|
||||
return fmt.Sprintf("%s/promote/%s", name, slug.Make(deployTo))
|
||||
default:
|
||||
return name
|
||||
}
|
||||
|
|
|
@ -13,9 +13,10 @@ import (
|
|||
|
||||
func TestCreateLabel(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
event string
|
||||
label string
|
||||
name string
|
||||
event string
|
||||
label string
|
||||
deployTo string
|
||||
}{
|
||||
{
|
||||
event: core.EventPullRequest,
|
||||
|
@ -29,6 +30,16 @@ func TestCreateLabel(t *testing.T) {
|
|||
event: core.EventTag,
|
||||
label: "continuous-integration/drone/tag",
|
||||
},
|
||||
{
|
||||
event: core.EventPromote,
|
||||
deployTo: "production",
|
||||
label: "continuous-integration/drone/promote/production",
|
||||
},
|
||||
{
|
||||
event: core.EventPromote,
|
||||
deployTo: "$production%",
|
||||
label: "continuous-integration/drone/promote/production",
|
||||
},
|
||||
{
|
||||
event: "unknown",
|
||||
label: "continuous-integration/drone",
|
||||
|
@ -40,7 +51,7 @@ func TestCreateLabel(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if got, want := createLabel(test.name, test.event), test.label; got != want {
|
||||
if got, want := createLabel(test.name, test.event, test.deployTo), test.label; got != want {
|
||||
t.Errorf("Want label %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue