diff --git a/plugin.go b/plugin.go index 45f3ebe..42c1fdf 100644 --- a/plugin.go +++ b/plugin.go @@ -220,7 +220,7 @@ func (p Plugin) Exec() error { if len(p.Config.Message) > 0 { message = p.Config.Message } else { - message = p.Message(p.Repo, p.Commit, p.Build) + message = p.Message() } bot, err := tgbotapi.NewBotAPI(p.Config.Token) @@ -369,12 +369,12 @@ func (p Plugin) Send(bot *tgbotapi.BotAPI, msg tgbotapi.Chattable) error { } // Message is plugin default message. -func (p Plugin) Message(repo Repo, commit Commit, build Build) []string { +func (p Plugin) Message() []string { return []string{fmt.Sprintf("[%s] <%s> (%s)『%s』by %s", - build.Status, - build.Link, - commit.Branch, - commit.Message, - commit.Author, + p.Build.Status, + p.Build.Link, + p.Commit.Branch, + p.Commit.Message, + p.Commit.Author, )} } diff --git a/plugin_test.go b/plugin_test.go index e3bac2f..c6c4f56 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -46,11 +46,35 @@ func TestDefaultMessageFormat(t *testing.T) { }, } - message := plugin.Message(plugin.Repo, plugin.Commit, plugin.Build) + message := plugin.Message() assert.Equal(t, []string{"[success] (master)『update travis』by Bo-Yi Wu"}, message) } +// func TestDefaultMessageFormatFromGitHub(t *testing.T) { +// plugin := Plugin{ +// Repo: Repo{ +// Name: "go-hello", +// Namespace: "appleboy", +// }, +// Commit: Commit{ +// Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2", +// Author: "Bo-Yi Wu", +// Branch: "master", +// Message: "update travis", +// }, +// Build: Build{ +// Number: 101, +// Status: "success", +// Link: "https://github.com/appleboy/go-hello", +// }, +// } + +// message := plugin.Message() + +// assert.Equal(t, []string{"[success] (master)『update travis』by Bo-Yi Wu"}, message) +// } + func TestSendMessage(t *testing.T) { plugin := Plugin{ Repo: Repo{