support handlebar template
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
693f15783c
commit
e2fc930461
16
glide.lock
generated
16
glide.lock
generated
@ -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:
|
||||
|
@ -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:
|
||||
|
28
main.go
28
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"),
|
||||
|
26
plugin.go
26
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)
|
||||
}
|
||||
|
@ -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", " "},
|
||||
|
Loading…
Reference in New Issue
Block a user