diff --git a/plugin.go b/plugin.go index b6e9e6b..8d7cd3d 100644 --- a/plugin.go +++ b/plugin.go @@ -107,6 +107,12 @@ type ( } ) +var icons = map[string]string{ + "failure": "❗", + "cancelled": "❕", + "success": "✅", +} + func trimElement(keys []string) []string { var newKeys []string @@ -266,6 +272,7 @@ func (p Plugin) Exec() (err error) { case len(p.Config.Message) > 0: message = p.Config.Message default: + p.Config.Format = formatMarkdown message = p.Message() } @@ -435,6 +442,8 @@ func (p Plugin) Send(bot *tgbotapi.BotAPI, msg tgbotapi.Chattable) error { // Message is plugin default message. func (p Plugin) Message() []string { + icon := icons[strings.ToLower(p.Build.Status)] + if p.Config.GitHub { return []string{fmt.Sprintf("%s/%s triggered by %s (%s)", p.Repo.FullName, @@ -444,10 +453,11 @@ func (p Plugin) Message() []string { )} } - return []string{fmt.Sprintf("[%s] <%s> (%s)『%s』by %s", + return []string{fmt.Sprintf("%s*%s* [%s](%s)『%s』by %s", + icon, p.Build.Status, + p.Repo.FullName, p.Build.Link, - p.Commit.Branch, p.Commit.Message, p.Commit.Author, )} diff --git a/plugin_test.go b/plugin_test.go index 6a89d7d..362f2ca 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -30,6 +30,7 @@ func TestMissingUserConfig(t *testing.T) { func TestDefaultMessageFormat(t *testing.T) { plugin := Plugin{ Repo: Repo{ + FullName: "appleboy/go-hello", Name: "go-hello", Namespace: "appleboy", }, @@ -48,7 +49,7 @@ func TestDefaultMessageFormat(t *testing.T) { message := plugin.Message() - assert.Equal(t, []string{"[success] (master)『update travis』by Bo-Yi Wu"}, message) + assert.Equal(t, []string{"✅*success* [appleboy/go-hello](https://github.com/appleboy/go-hello)『update travis』by Bo-Yi Wu"}, message) } func TestDefaultMessageFormatFromGitHub(t *testing.T) {