Compare commits

...

4 Commits

Author SHA1 Message Date
lddsb b54a0fc981 fix: patch for k8s missing env 2020-04-29 11:04:24 +08:00
lddsb b7390525e1 fix: default image cdn url 2020-01-20 11:34:31 +08:00
lddsb 9df9c9aa37 add tips title option 2019-11-07 21:40:28 +08:00
lddsb f931e70cc7 compatible full token url as token parameter 2019-09-24 09:26:28 +08:00
6 changed files with 43 additions and 15 deletions
+11 -3
View File
@@ -1,9 +1,17 @@
FROM alpine:latest
FROM golang AS builder
WORKDIR /app
COPY . .
ENV GO111MODULE on
ENV CGO_ENABLED 0
ENV GOOS linux
RUN go build -a -o drone-dingtalk .
FROM alpine:latest
RUN apk update && \
apk add \
ca-certificates && \
rm -rf /var/cache/apk/*
ADD drone-dingtalk-message /bin/
ENTRYPOINT ["/bin/drone-dingtalk-message"]
COPY --from=builder /app/drone-dingtalk /bin/
ENTRYPOINT ["/bin/drone-dingtalk"]
+5 -1
View File
@@ -36,6 +36,10 @@ String. Access token for group bot. (you can get the access token when you add a
String. Message type, plan support text, markdown, link and action card, but due to time issue, it's only support `markdown` and `text` now, and you can get the best experience by use markdown.
`tips_title`
String. You can customize the title for the message tips, just work when message type is markdown.
`message_color`(when `type=markdown`)
Boolean value. This option can change the title and commit message color if turn on.
@@ -113,4 +117,4 @@ cd $GOPATH/src/github.com/lddsb/drone-dingtalk-message && go build .
- run
```shell
./drone-dingtalk-message -h
```
```
+1 -1
View File
@@ -4,6 +4,6 @@ go 1.12
require (
github.com/joho/godotenv v1.3.0
github.com/lddsb/dingtalk-webhook v0.0.0-20190307231412-b4abe34b5fa9
github.com/lddsb/dingtalk-webhook v0.0.1
github.com/urfave/cli v1.20.0
)
+2 -2
View File
@@ -1,6 +1,6 @@
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/lddsb/dingtalk-webhook v0.0.0-20190307231412-b4abe34b5fa9 h1:ZeUdCEbcT0+l10jTSyjU9+18ZbDTz6TdkH6yGiCd9dQ=
github.com/lddsb/dingtalk-webhook v0.0.0-20190307231412-b4abe34b5fa9/go.mod h1:5E+/sOBb6m+3ztqnZl4danEY3I5FeIwb12v12s9osbw=
github.com/lddsb/dingtalk-webhook v0.0.1 h1:l4FdTMaRaHnrYfByALukFWK0ru9Rttl0dANg13/SnTI=
github.com/lddsb/dingtalk-webhook v0.0.1/go.mod h1:5E+/sOBb6m+3ztqnZl4danEY3I5FeIwb12v12s9osbw=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
+16 -5
View File
@@ -5,7 +5,7 @@ import (
"log"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
@@ -144,6 +144,16 @@ func main() {
Usage: "link sha source page or not",
EnvVar: "PLUGIN_SHA_LINK,PLUGIN_MESSAGE_SHA_LINK",
},
cli.StringFlag{
Name: "config.tips.title",
Usage: "tips title, just work for markdown type message",
EnvVar: "PLUGIN_TIPS_TITLE",
},
}
// patch for k8s missing env
if _, err := os.Stat("/run/drone/env"); err == nil {
godotenv.Overload("/run/drone/env")
}
if err := app.Run(os.Args); nil != err {
@@ -184,10 +194,11 @@ func run(c *cli.Context) {
Config: Config{
AccessToken: c.String("config.token"),
//Lang: c.String("config.lang"),
IsAtALL: c.Bool("config.message.at.all"),
MsgType: c.String("config.message.type"),
Mobiles: c.String("config.message.at.mobiles"),
Debug: c.Bool("config.debug"),
IsAtALL: c.Bool("config.message.at.all"),
MsgType: c.String("config.message.type"),
Mobiles: c.String("config.message.at.mobiles"),
Debug: c.Bool("config.debug"),
TipsTitle: c.String("config.tips.title"),
},
Extra: Extra{
Pic: ExtraPic{
+8 -3
View File
@@ -52,6 +52,7 @@ type (
Mobiles string
Username string
MsgType string
TipsTitle string
}
// MessageConfig `DingTalk message struct`
@@ -108,11 +109,15 @@ func (p *Plugin) Exec() error {
return errors.New("commit sha cannot short than 6")
}
if p.Config.TipsTitle == "" {
p.Config.TipsTitle = "you have a new message"
}
newWebhook := webhook.NewWebHook(p.Config.AccessToken)
mobiles := strings.Split(p.Config.Mobiles, ",")
switch strings.ToLower(p.Config.MsgType) {
case "markdown":
err = newWebhook.SendMarkdownMsg("You have a new message...", p.baseTpl(), p.Config.IsAtALL, mobiles...)
err = newWebhook.SendMarkdownMsg(p.Config.TipsTitle, p.baseTpl(), p.Config.IsAtALL, mobiles...)
case "text":
err = newWebhook.SendTextMsg(p.baseTpl(), p.Config.IsAtALL, mobiles...)
case "link":
@@ -232,12 +237,12 @@ get picture url
func (p *Plugin) getPicURL() string {
pics := make(map[string]string)
// success picture url
pics["success"] = "https://ws4.sinaimg.cn/large/006tNc79gy1fz05g5a7utj30he0bfjry.jpg"
pics["success"] = "https://wx1.sinaimg.cn/large/006tNc79gy1fz05g5a7utj30he0bfjry.jpg"
if p.Extra.Pic.SuccessPicURL != "" {
pics["success"] = p.Extra.Pic.SuccessPicURL
}
// failure picture url
pics["failure"] = "https://ws1.sinaimg.cn/large/006tNc79gy1fz0b4fghpnj30hd0bdmxn.jpg"
pics["failure"] = "https://wx1.sinaimg.cn/large/006tNc79gy1fz0b4fghpnj30hd0bdmxn.jpg"
if p.Extra.Pic.FailurePicURL != "" {
pics["failure"] = p.Extra.Pic.FailurePicURL
}