From ce15798a06fbb7e6c6f0c18940ae3877517f22b7 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 20 Jun 2020 13:51:48 +0800 Subject: [PATCH] chore: update message format --- main.go | 4 ++-- plugin.go | 4 ++-- plugin_test.go | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index e5b76c1..52fc5af 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func main() { Usage: "telegram user", EnvVar: "PLUGIN_TO,TELEGRAM_TO,INPUT_TO", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "message", Usage: "send telegram message", EnvVar: "PLUGIN_MESSAGE,TELEGRAM_MESSAGE,INPUT_MESSAGE", @@ -302,7 +302,7 @@ func run(c *cli.Context) error { MatchEmail: c.Bool("match.email"), WebPreview: c.Bool("webpage.preview"), To: c.StringSlice("to"), - Message: c.StringSlice("message"), + Message: c.String("message"), MessageFile: c.String("message.file"), TemplateVars: c.String("template.vars"), Photo: c.StringSlice("photo"), diff --git a/plugin.go b/plugin.go index fe87497..7eb7778 100644 --- a/plugin.go +++ b/plugin.go @@ -72,7 +72,7 @@ type ( MatchEmail bool WebPreview bool To []string - Message []string + Message string MessageFile string TemplateVars string Photo []string @@ -270,7 +270,7 @@ func (p Plugin) Exec() (err error) { return fmt.Errorf("error loading message file '%s': %v", p.Config.MessageFile, err) } case len(p.Config.Message) > 0: - message = p.Config.Message + message = []string{p.Config.Message} default: p.Config.Format = formatMarkdown message = p.Message() diff --git a/plugin_test.go b/plugin_test.go index b55e594..e9c0fa6 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -97,7 +97,7 @@ func TestSendMessage(t *testing.T) { Config: Config{ Token: os.Getenv("TELEGRAM_TOKEN"), To: []string{os.Getenv("TELEGRAM_TO"), os.Getenv("TELEGRAM_TO") + ":appleboy@gmail.com", "中文ID", "1234567890"}, - Message: []string{"Test Telegram Chat Bot From Travis or Local", "commit message: 『{{ build.message }}』", " "}, + Message: "Test Telegram Chat Bot From Travis or Local, commit message: 『{{ build.message }}』", Photo: []string{"tests/github.png", "1234", " "}, Document: []string{"tests/gophercolor.png", "1234", " "}, Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "}, @@ -114,12 +114,12 @@ func TestSendMessage(t *testing.T) { assert.NotNil(t, err) plugin.Config.Format = formatMarkdown - plugin.Config.Message = []string{"Test escape under_score"} + plugin.Config.Message = "Test escape under_score" err = plugin.Exec() assert.NotNil(t, err) // disable message - plugin.Config.Message = []string{} + plugin.Config.Message = "" err = plugin.Exec() assert.NotNil(t, err) } @@ -145,7 +145,7 @@ func TestBotError(t *testing.T) { Config: Config{ Token: "appleboy", To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"}, - Message: []string{"Test Telegram Chat Bot From Travis or Local", " "}, + Message: "Test Telegram Chat Bot From Travis or Local", }, } @@ -410,7 +410,7 @@ func TestProxySendMessage(t *testing.T) { Config: Config{ Token: os.Getenv("TELEGRAM_TOKEN"), To: []string{os.Getenv("TELEGRAM_TO")}, - Message: []string{"Send message from socks5 proxy URL."}, + Message: "Send message from socks5 proxy URL.", Debug: false, Socks5: os.Getenv("SOCKS5"), },