Support debug mode.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-10-04 22:23:13 +08:00
parent 541efa4e5b
commit f80e79f1c6
4 changed files with 11 additions and 2 deletions

View File

@ -42,9 +42,10 @@ Execute from the working directory:
``` ```
docker run --rm \ docker run --rm \
-e PLUGIN_TOKEN=xxxxxxx \ -e PLUGIN_TELEGRAM_TOKEN=xxxxxxx \
-e PLUGIN_TO=xxxxxxx \ -e PLUGIN_TO=xxxxxxx \
-e PLUGIN_MESSAGE=test \ -e PLUGIN_MESSAGE=test \
-e PLUGIN_DEBUG=true \
-e DRONE_REPO_OWNER=appleboy \ -e DRONE_REPO_OWNER=appleboy \
-e DRONE_REPO_NAME=go-hello \ -e DRONE_REPO_NAME=go-hello \
-e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \ -e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \

View File

@ -32,6 +32,11 @@ func main() {
Usage: "send telegram message", Usage: "send telegram message",
EnvVar: "PLUGIN_MESSAGE", EnvVar: "PLUGIN_MESSAGE",
}, },
cli.BoolFlag{
Name: "debug",
Usage: "enable debug message",
EnvVar: "PLUGIN_DEBUG",
},
cli.StringFlag{ cli.StringFlag{
Name: "repo.owner", Name: "repo.owner",
Usage: "repository owner", Usage: "repository owner",
@ -107,6 +112,7 @@ func run(c *cli.Context) error {
}, },
Config: Config{ Config: Config{
Token: c.String("telegram.token"), Token: c.String("telegram.token"),
Debug: c.Bool("debug"),
To: c.StringSlice("to"), To: c.StringSlice("to"),
Message: c.StringSlice("message"), Message: c.StringSlice("message"),
}, },

View File

@ -32,6 +32,7 @@ type (
// Config for the plugin. // Config for the plugin.
Config struct { Config struct {
Token string Token string
Debug bool
To []string To []string
Message []string Message []string
} }
@ -98,7 +99,7 @@ func (p Plugin) Exec() error {
return err return err
} }
bot.Debug = false bot.Debug = p.Config.Debug
// parse ids // parse ids
ids := parseID(p.Config.To) ids := parseID(p.Config.To)

View File

@ -69,6 +69,7 @@ func TestSendMessage(t *testing.T) {
Token: os.Getenv("TELEGRAM_TOKEN"), Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"}, To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"},
Message: []string{"Test Telegram Chat Bot From Travis or Local", " "}, Message: []string{"Test Telegram Chat Bot From Travis or Local", " "},
Debug: false,
}, },
} }