mirror of
https://github.com/lddsb/drone-dingtalk-message.git
synced 2026-06-16 14:50:42 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a9e3dbbf4b | |||
| c82a6a8c79 | |||
| aec957818e | |||
| 6c497aa777 | |||
| 9e4a2ae0dc | |||
| 00b6d66762 | |||
| 26933681c4 | |||
| b6dd3953d2 |
+34
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: default
|
||||||
|
|
||||||
|
workspace:
|
||||||
|
base: /go
|
||||||
|
path: src/github.com/lddsb/drone-dingtalk-message
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- go get -u github.com/golang/dep/cmd/dep
|
||||||
|
- dep ensure
|
||||||
|
- CGO_ENABLED=0 GOOS=linux go build -a -o drone-dingtalk-message .
|
||||||
|
- ./drone-dingtalk-message -h
|
||||||
|
- name: publish
|
||||||
|
image: plugins/docker
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- beta
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
settings:
|
||||||
|
repo: lddsb/drone-dingtalk-message
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
tags: beta
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
|
||||||
@@ -330,6 +330,12 @@ func main() {
|
|||||||
Usage: "link sha source page or not",
|
Usage: "link sha source page or not",
|
||||||
EnvVar: "PLUGIN_SHA_LINK,PLUGIN_MESSAGE_SHA_LINK",
|
EnvVar: "PLUGIN_SHA_LINK,PLUGIN_MESSAGE_SHA_LINK",
|
||||||
},
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "config.retry.time",
|
||||||
|
Usage: "time out retry times, default 3",
|
||||||
|
Value: 3,
|
||||||
|
EnvVar: "PLUGIN_RETRY_TIME,PLUGIN_RETRY",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); nil != err {
|
if err := app.Run(os.Args); nil != err {
|
||||||
@@ -386,6 +392,7 @@ func run(c *cli.Context) {
|
|||||||
WithColor: c.Bool("config.message.color"),
|
WithColor: c.Bool("config.message.color"),
|
||||||
WithPic: c.Bool("config.message.pic"),
|
WithPic: c.Bool("config.message.pic"),
|
||||||
LinkSha: c.Bool("config.message.sha.link"),
|
LinkSha: c.Bool("config.message.sha.link"),
|
||||||
|
RetryTime: c.Int("config.retry.time"),
|
||||||
},
|
},
|
||||||
CI: CI{
|
CI: CI{
|
||||||
RepoLink: c.String("ci.repo.link"),
|
RepoLink: c.String("ci.repo.link"),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ type (
|
|||||||
WithColor bool
|
WithColor bool
|
||||||
WithPic bool
|
WithPic bool
|
||||||
LinkSha bool
|
LinkSha bool
|
||||||
|
RetryTime int
|
||||||
}
|
}
|
||||||
// plugin all config
|
// plugin all config
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
@@ -120,26 +122,22 @@ func (p *Plugin) Exec() error {
|
|||||||
linkUrls := strings.Split(p.Config.LinkUrls, ",")
|
linkUrls := strings.Split(p.Config.LinkUrls, ",")
|
||||||
linkTitles := strings.Split(p.Config.LinkTitles, ",")
|
linkTitles := strings.Split(p.Config.LinkTitles, ",")
|
||||||
log.Println("sending message type: " + p.Config.MsgType)
|
log.Println("sending message type: " + p.Config.MsgType)
|
||||||
|
var err error
|
||||||
|
retryTime := 1
|
||||||
|
for retryTime <= p.Config.RetryTime {
|
||||||
|
log.Printf("start a %d try", retryTime)
|
||||||
switch strings.ToLower(p.Config.MsgType) {
|
switch strings.ToLower(p.Config.MsgType) {
|
||||||
case "markdown":
|
case "markdown":
|
||||||
err := p.WebHook.SendMarkdownMsg(
|
err = p.WebHook.SendMarkdownMsg(
|
||||||
"You have a new message...",
|
"You have a new message...",
|
||||||
p.baseTpl(),
|
p.baseTpl(),
|
||||||
p.Config.IsAtALL,
|
p.Config.IsAtALL,
|
||||||
mobiles...
|
mobiles...
|
||||||
)
|
)
|
||||||
if nil != err {
|
|
||||||
log.Println(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "text":
|
case "text":
|
||||||
err := p.WebHook.SendTextMsg(p.baseTpl(), p.Config.IsAtALL, mobiles...)
|
err = p.WebHook.SendTextMsg(p.baseTpl(), p.Config.IsAtALL, mobiles...)
|
||||||
if nil != err {
|
|
||||||
log.Println(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "actioncard":
|
case "actioncard":
|
||||||
err := p.WebHook.SendActionCardMsg(
|
err = p.WebHook.SendActionCardMsg(
|
||||||
"A actionCard title",
|
"A actionCard title",
|
||||||
p.baseTpl(),
|
p.baseTpl(),
|
||||||
linkUrls,
|
linkUrls,
|
||||||
@@ -147,21 +145,22 @@ func (p *Plugin) Exec() error {
|
|||||||
p.Config.HideAvatar,
|
p.Config.HideAvatar,
|
||||||
p.Config.BtnOrientation,
|
p.Config.BtnOrientation,
|
||||||
)
|
)
|
||||||
if nil != err {
|
|
||||||
log.Println(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "link":
|
case "link":
|
||||||
err := p.WebHook.SendLinkMsg(p.Build.Status, p.baseTpl(), p.Commit.Authors.Avatar, p.Build.Link)
|
err = p.WebHook.SendLinkMsg(p.Build.Status, p.baseTpl(), p.Commit.Authors.Avatar, p.Build.Link)
|
||||||
|
default:
|
||||||
|
err = errors.New("not support message type")
|
||||||
|
}
|
||||||
|
|
||||||
|
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||||
|
retryTime++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if nil != err {
|
if nil != err {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
msg := "not support message type"
|
|
||||||
log.Println(msg)
|
|
||||||
return errors.New(msg)
|
|
||||||
}
|
|
||||||
log.Println("send " + p.Config.MsgType + " message success!")
|
log.Println("send " + p.Config.MsgType + " message success!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user