diff --git a/glide.lock b/glide.lock index 19aa9f8..7443c62 100644 --- a/glide.lock +++ b/glide.lock @@ -1,6 +1,16 @@ -hash: b63ca4eb6e194481209bad2e58f3c4eb2c0ef2b4411ead5b3b7a77677ef815ab -updated: 2016-10-04T21:46:25.713693812+08:00 +hash: 5bdcf53533d043ba1cb6ab55ae6a93aca40c812a20264406bd6e0fe342f51d61 +updated: 2016-10-31T09:50:34.654875319+08:00 imports: +- name: github.com/appleboy/drone-facebook + version: abda8124c404d424b150cf2a9935e3e108519c6e + subpackages: + - template +- name: github.com/aymerick/raymond + version: a2232af10b53ef1ae5a767f5178db3a6c1dab655 + subpackages: + - ast + - parser + - lexer - name: github.com/joho/godotenv version: 4ed13390c0acd2ff4e371e64d8b97c8954138243 subpackages: @@ -8,7 +18,7 @@ imports: - name: github.com/technoweenie/multipartstreamer version: a90a01d73ae432e2611d178c18367fbaa13e0154 - name: github.com/urfave/cli - version: d53eb991652b1d438abdd34ce4bfa3ef1539108e + version: 3eb41f1bb122ac7535cc7b32db6b78b541879726 - name: gopkg.in/telegram-bot-api.v4 version: a7f48eb2dd301356942677e65bebe0c9aef07013 testImports: diff --git a/glide.yaml b/glide.yaml index 48a0e12..55cc016 100644 --- a/glide.yaml +++ b/glide.yaml @@ -5,6 +5,10 @@ import: - autoload - package: github.com/urfave/cli - package: gopkg.in/telegram-bot-api.v4 +- package: github.com/appleboy/drone-facebook + version: ^1.3.0 + subpackages: + - template testImport: - package: github.com/stretchr/testify subpackages: diff --git a/main.go b/main.go index 6493c56..eb7b438 100644 --- a/main.go +++ b/main.go @@ -136,6 +136,16 @@ func main() { Usage: "build link", EnvVar: "DRONE_BUILD_LINK", }, + cli.Float64Flag{ + Name: "job.started", + Usage: "job started", + EnvVar: "DRONE_JOB_STARTED", + }, + cli.Float64Flag{ + Name: "job.finished", + Usage: "job finished", + EnvVar: "DRONE_JOB_FINISHED", + }, } app.Run(os.Args) } @@ -147,14 +157,16 @@ func run(c *cli.Context) error { Name: c.String("repo.name"), }, Build: Build{ - Number: c.Int("build.number"), - Event: c.String("build.event"), - Status: c.String("build.status"), - Commit: c.String("commit.sha"), - Branch: c.String("commit.branch"), - Author: c.String("commit.author"), - Message: c.String("commit.message"), - Link: c.String("build.link"), + Number: c.Int("build.number"), + Event: c.String("build.event"), + Status: c.String("build.status"), + Commit: c.String("commit.sha"), + Branch: c.String("commit.branch"), + Author: c.String("commit.author"), + Message: c.String("commit.message"), + Link: c.String("build.link"), + Started: c.Float64("job.started"), + Finished: c.Float64("job.finished"), }, Config: Config{ Token: c.String("token"), diff --git a/plugin.go b/plugin.go index 2319796..0225bfe 100644 --- a/plugin.go +++ b/plugin.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" + "github.com/appleboy/drone-facebook/template" "gopkg.in/telegram-bot-api.v4" ) @@ -20,14 +21,16 @@ type ( // Build information. Build struct { - Event string - Number int - Commit string - Message string - Branch string - Author string - Status string - Link string + Event string + Number int + Commit string + Message string + Branch string + Author string + Status string + Link string + Started float64 + Finished float64 } // Config for the plugin. @@ -187,7 +190,12 @@ func (p Plugin) Exec() error { // send message. for _, user := range ids { for _, value := range trimElement(message) { - msg := tgbotapi.NewMessage(user, value) + txt, err := template.RenderTrim(value, p) + if err != nil { + return err + } + + msg := tgbotapi.NewMessage(user, txt) msg.ParseMode = p.Config.Format p.Send(bot, msg) } diff --git a/plugin_test.go b/plugin_test.go index 62d5656..05409e0 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -68,7 +68,7 @@ func TestSendMessage(t *testing.T) { Config: Config{ Token: os.Getenv("TELEGRAM_TOKEN"), 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", "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", " "},