Merge pull request #20 from appleboy/template
Add support handlebar template
This commit is contained in:
commit
bd3806e778
@ -7,7 +7,7 @@ services:
|
||||
go:
|
||||
- 1.5.4
|
||||
- 1.6.3
|
||||
- 1.7.1
|
||||
- 1.7.3
|
||||
- tip
|
||||
|
||||
env:
|
||||
@ -42,12 +42,12 @@ after_success:
|
||||
- sed -i '/main.go/d' coverage.txt
|
||||
- bash <(curl -s https://codecov.io/bash) -f coverage.txt
|
||||
# deploy from master
|
||||
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_GO_VERSION" == "1.7.1" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_GO_VERSION" == "1.7.3" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
|
||||
make docker_deploy tag=latest;
|
||||
fi
|
||||
# deploy from tag
|
||||
- if [ "$TRAVIS_GO_VERSION" == "1.7.1" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
|
||||
- if [ "$TRAVIS_GO_VERSION" == "1.7.3" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
|
||||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
|
||||
make docker_deploy tag=$TRAVIS_TAG;
|
||||
fi
|
||||
|
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:
|
||||
|
12
main.go
12
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)
|
||||
}
|
||||
@ -155,6 +165,8 @@ func run(c *cli.Context) error {
|
||||
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"),
|
||||
|
10
plugin.go
10
plugin.go
@ -8,6 +8,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/appleboy/drone-facebook/template"
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
)
|
||||
|
||||
@ -28,6 +29,8 @@ type (
|
||||
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