Compare commits

..

10 Commits

Author SHA1 Message Date
Bo-Yi Wu e0760eaf80 change , to :
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 11:39:30 +08:00
Bo-Yi Wu b16d4444dc update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 10:11:39 +08:00
Bo-Yi Wu b154d3d0d0 Merge pull request #22 from appleboy/parseID
Support send notification to commit author by check email.
2016-11-04 10:10:37 +08:00
Bo-Yi Wu ac5786266a remove codecov arg.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 09:54:12 +08:00
Bo-Yi Wu dbb5972732 update testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 09:43:21 +08:00
Bo-Yi Wu dc6dc4a444 Support send notification to commit author by check email.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 09:38:21 +08:00
Bo-Yi Wu ee5a200955 [ci skip] update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-02 10:01:26 +08:00
Bo-Yi Wu bd3806e778 Merge pull request #20 from appleboy/template
Add support handlebar template
2016-10-31 10:09:34 +08:00
Bo-Yi Wu 8b2af04235 Add 1.7.3 version testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-31 09:57:51 +08:00
Bo-Yi Wu e2fc930461 support handlebar template
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-31 09:57:34 +08:00
7 changed files with 110 additions and 48 deletions
+4 -4
View File
@@ -7,7 +7,7 @@ services:
go:
- 1.5.4
- 1.6.3
- 1.7.1
- 1.7.3
- tip
env:
@@ -40,14 +40,14 @@ script:
after_success:
# ignore main.go coverage
- sed -i '/main.go/d' coverage.txt
- bash <(curl -s https://codecov.io/bash) -f coverage.txt
- bash <(curl -s https://codecov.io/bash)
# 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
+3
View File
@@ -72,9 +72,12 @@ docker run --rm \
-e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_AUTHOR=appleboy \
-e DRONE_COMMIT_AUTHOR_EMAIL=appleboy@gmail.com \
-e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/appleboy/go-hello \
-e DRONE_JOB_STARTED=1477550550 \
-e DRONE_JOB_FINISHED=1477550750 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-telegram
Generated
+13 -3
View File
@@ -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:
+4
View File
@@ -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:
+26 -8
View File
@@ -109,6 +109,11 @@ func main() {
Usage: "git author name",
EnvVar: "DRONE_COMMIT_AUTHOR",
},
cli.StringFlag{
Name: "commit.author.email",
Usage: "git author email",
EnvVar: "DRONE_COMMIT_AUTHOR_EMAIL",
},
cli.StringFlag{
Name: "commit.message",
Usage: "commit message",
@@ -136,6 +141,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 +162,17 @@ 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"),
Email: c.String("commit.author.email"),
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"),
+36 -22
View File
@@ -8,6 +8,7 @@ import (
"strconv"
"strings"
"github.com/appleboy/drone-facebook/template"
"gopkg.in/telegram-bot-api.v4"
)
@@ -20,14 +21,17 @@ 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
Email string
Status string
Link string
Started float64
Finished float64
}
// Config for the plugin.
@@ -131,20 +135,22 @@ func convertLocation(value string) (Location, bool) {
}, false
}
func parseID(keys []string) []int64 {
var newKeys []int64
func parseTo(value, authorEmail string) (int64, bool) {
ids := trimElement(strings.Split(value, ":"))
for _, value := range keys {
id, err := strconv.ParseInt(value, 10, 64)
if err != nil {
log.Println(err.Error())
continue
if len(ids) > 1 {
if email := ids[1]; email != authorEmail {
log.Println("email not match")
return int64(0), false
}
newKeys = append(newKeys, id)
}
return newKeys
id, err := strconv.ParseInt(ids[0], 10, 64)
if err != nil {
return int64(0), false
}
return id, true
}
// Exec executes the plugin.
@@ -173,8 +179,6 @@ func (p Plugin) Exec() error {
bot.Debug = p.Config.Debug
// parse ids
ids := parseID(p.Config.To)
photos := fileExist(trimElement(p.Config.Photo))
documents := fileExist(trimElement(p.Config.Document))
stickers := fileExist(trimElement(p.Config.Sticker))
@@ -185,9 +189,19 @@ func (p Plugin) Exec() error {
venues := trimElement(p.Config.Venue)
// send message.
for _, user := range ids {
for _, to := range p.Config.To {
user, enable := parseTo(to, p.Build.Email)
if !enable {
continue
}
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)
}
+24 -11
View File
@@ -63,12 +63,13 @@ func TestSendMessage(t *testing.T) {
Branch: "master",
Message: "update travis by drone plugin",
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Email: "test@gmail.com",
},
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", " "},
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 }}』", " "},
Photo: []string{"tests/github.png", "1234", " "},
Document: []string{"tests/gophercolor.png", "1234", " "},
Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "},
@@ -131,19 +132,31 @@ func TestTrimElement(t *testing.T) {
assert.Equal(t, result, trimElement(input))
}
func TestParseID(t *testing.T) {
var input []string
var result []int64
func TestParseTo(t *testing.T) {
id, enable := parseTo("1234567890", "test@gmail.com")
input = []string{"1", "測試", "3"}
result = []int64{int64(1), int64(3)}
assert.Equal(t, true, enable)
assert.Equal(t, int64(1234567890), id)
assert.Equal(t, result, parseID(input))
id, enable = parseTo("1234567890:test2@gmail.com", "test@gmail.com")
input = []string{"1", "2"}
result = []int64{int64(1), int64(2)}
assert.Equal(t, false, enable)
assert.Equal(t, int64(0), id)
assert.Equal(t, result, parseID(input))
id, enable = parseTo("1234567890:test@gmail.com", "test@gmail.com")
assert.Equal(t, true, enable)
assert.Equal(t, int64(1234567890), id)
id, enable = parseTo("測試:test@gmail.com", "test@gmail.com")
assert.Equal(t, false, enable)
assert.Equal(t, int64(0), id)
id, enable = parseTo("測試", "test@gmail.com")
assert.Equal(t, false, enable)
assert.Equal(t, int64(0), id)
}
func TestCheckFileExist(t *testing.T) {