mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 17:00:30 +00:00
Merge pull request #613 from ciarand/master
Adjust Slack message format to match HipChat's
This commit is contained in:
commit
2872b3ce4a
3 changed files with 87 additions and 26 deletions
28
plugin/notify/notify_test.go
Normal file
28
plugin/notify/notify_test.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package notify
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/drone/drone/shared/model"
|
||||
)
|
||||
|
||||
func Test_getBuildUrl(t *testing.T) {
|
||||
c := &model.Request{
|
||||
Host: "http://examplehost.com",
|
||||
Repo: &model.Repo{
|
||||
Host: "examplegit.com",
|
||||
Owner: "owner",
|
||||
Name: "repo",
|
||||
},
|
||||
Commit: &model.Commit{
|
||||
Sha: "abc",
|
||||
Branch: "example",
|
||||
},
|
||||
}
|
||||
expected := "http://examplehost.com/examplegit.com/owner/repo/example/abc"
|
||||
output := getBuildUrl(c)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("Failed to build url. Expected: %s, got %s", expected, output)
|
||||
}
|
||||
}
|
|
@ -9,9 +9,9 @@ import (
|
|||
|
||||
const (
|
||||
slackEndpoint = "https://%s.slack.com/services/hooks/incoming-webhook?token=%s"
|
||||
slackStartedMessage = "*Building* %s, commit <%s|%s>, author %s"
|
||||
slackSuccessMessage = "*Success* %s, commit <%s|%s>, author %s"
|
||||
slackFailureMessage = "*Failed* %s, commit <%s|%s>, author %s"
|
||||
slackStartedMessage = "*Building* <%s|%s> (%s) by %s"
|
||||
slackSuccessMessage = "*Success* <%s|%s> (%s) by %s"
|
||||
slackFailureMessage = "*Failed* <%s|%s> (%s) by %s"
|
||||
)
|
||||
|
||||
type Slack struct {
|
||||
|
@ -39,11 +39,14 @@ func (s *Slack) Send(context *model.Request) error {
|
|||
|
||||
func (s *Slack) getMessage(context *model.Request, message string) string {
|
||||
url := getBuildUrl(context)
|
||||
return fmt.Sprintf(message, context.Repo.Name, url, context.Commit.ShaShort(), context.Commit.Author)
|
||||
// drone/drone#3333333
|
||||
linktext := context.Repo.Owner + "/" + context.Repo.Name + "#" + context.Commit.ShaShort()
|
||||
|
||||
return fmt.Sprintf(message, linktext, url, context.Commit.Branch, context.Commit.Author)
|
||||
}
|
||||
|
||||
func (s *Slack) sendStarted(context *model.Request) error {
|
||||
return s.send(s.getMessage(context, slackStartedMessage), "warning")
|
||||
return s.send(s.getMessage(context, slackStartedMessage)+"\n - "+context.Commit.Message, "warning")
|
||||
}
|
||||
|
||||
func (s *Slack) sendSuccess(context *model.Request) error {
|
||||
|
|
|
@ -1,27 +1,57 @@
|
|||
package notify
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/shared/model"
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
func Test_getBuildUrl(t *testing.T) {
|
||||
c := &model.Request{
|
||||
Host: "http://examplehost.com",
|
||||
Repo: &model.Repo{
|
||||
Host: "examplegit.com",
|
||||
Owner: "owner",
|
||||
Name: "repo",
|
||||
},
|
||||
Commit: &model.Commit{
|
||||
Sha: "abc",
|
||||
Branch: "example",
|
||||
},
|
||||
}
|
||||
expected := "http://examplehost.com/examplegit.com/owner/repo/example/abc"
|
||||
output := getBuildUrl(c)
|
||||
/*
|
||||
var request = &model.Request{
|
||||
Host: "http://examplehost.com",
|
||||
Repo: &model.Repo{
|
||||
Host: "examplegit.com",
|
||||
Owner: "owner",
|
||||
Name: "repo",
|
||||
},
|
||||
Commit: &model.Commit{
|
||||
Sha: "abc",
|
||||
Branch: "example",
|
||||
Status: "Started",
|
||||
Message: "Test Commit",
|
||||
Author: "Test User",
|
||||
},
|
||||
User: &model.User{
|
||||
Login: "TestUser",
|
||||
},
|
||||
}
|
||||
*/
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("Failed to build url. Expected: %s, got %s", expected, output)
|
||||
var slackExpectedLink = "<owner/repo#abc|http://examplehost.com/examplegit.com/owner/repo/example/abc>"
|
||||
var slackExpectedBase = slackExpectedLink + " (example) by Test User"
|
||||
|
||||
func Test_slackStartedMessage(t *testing.T) {
|
||||
actual := (&Slack{}).getMessage(request, slackStartedMessage)
|
||||
|
||||
expected := "*Building* " + slackExpectedBase
|
||||
|
||||
if actual != expected {
|
||||
t.Errorf("Invalid getStarted message for Slack. Expected %v, got %v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_slackSuccessMessage(t *testing.T) {
|
||||
actual := (&Slack{}).getMessage(request, slackSuccessMessage)
|
||||
|
||||
expected := "*Success* " + slackExpectedBase
|
||||
|
||||
if actual != expected {
|
||||
t.Errorf("Invalid getStarted message for Slack. Expected %v, got %v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_slackFailureMessage(t *testing.T) {
|
||||
actual := (&Slack{}).getMessage(request, slackFailureMessage)
|
||||
|
||||
expected := "*Failed* " + slackExpectedBase
|
||||
|
||||
if actual != expected {
|
||||
t.Errorf("Invalid getStarted message for Slack. Expected %v, got %v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue