mirror of
https://github.com/lddsb/drone-dingtalk-message.git
synced 2026-06-16 14:50:42 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f9aff987bb |
@@ -41,6 +41,10 @@ String. Message type, plan support text, markdown, link and action card, but due
|
||||
|
||||
String. Your custom `tpl`, it can be a local path or a remote http link.
|
||||
|
||||
`tips_title`
|
||||
|
||||
String. You can customize the title for the message tips, just work when message type is markdown.
|
||||
|
||||
`success_color`
|
||||
|
||||
String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `008000`.
|
||||
@@ -75,7 +79,7 @@ String. You can customize the [TPL_BUILD_STATUS] (when status=`success`) by this
|
||||
|
||||
`tpl_build_status_failure`
|
||||
|
||||
String. You can customize the [TPL_BUILD_STATUS] (when status=`failure`) by this configuration item.
|
||||
String. You can customize the [TPL_BUILD_STATUS] (when status=`failure`) by this configuration item.
|
||||
|
||||
### TPL
|
||||
> `tpl` won't work with message type `link` !!!
|
||||
@@ -84,11 +88,11 @@ That's a good news, we support `tpl` now.This is a example for `markdown` messag
|
||||
|
||||
# [TPL_REPO_FULL_NAME] build [TPL_BUILD_STATUS], takes [TPL_BUILD_CONSUMING]s
|
||||
[TPL_COMMIT_MSG]
|
||||
|
||||
|
||||
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
|
||||
|
||||
|
||||
[[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
|
||||
|
||||
|
||||
[Click To The Build Detail Page [TPL_STATUS_EMOTICON)]]([TPL_BUILD_LINK])
|
||||
You can write your own `tpl` what you want. The syntax of `tpl` is very simple, you can fill `tpl` with preset variables. It's a list of currently supported preset variables:
|
||||
|
||||
@@ -161,4 +165,4 @@ $ ./drone-dingtalk-message -h
|
||||
```
|
||||
|
||||
### Todo
|
||||
- implement all message type
|
||||
- implement all message type
|
||||
|
||||
@@ -2,10 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/urfave/cli"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// Version of cli
|
||||
@@ -30,6 +31,11 @@ func main() {
|
||||
Usage: "debug mode",
|
||||
EnvVar: "PLUGIN_DEBUG",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.tips.title",
|
||||
Usage: "customize the tips title",
|
||||
EnvVar: "PLUGIN_TIPS_TITLE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.token,access_token,token",
|
||||
Usage: "dingtalk webhook access token",
|
||||
@@ -148,13 +154,13 @@ func main() {
|
||||
EnvVar: "DRONE_BUILD_FINISHED",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tpl.build.status.success",
|
||||
Usage: "tpl.build status for replace success",
|
||||
Name: "tpl.build.status.success",
|
||||
Usage: "tpl.build status for replace success",
|
||||
EnvVar: "TPL_BUILD_STATUS_SUCCESS, PLUGIN_TPL_BUILD_STATUS_SUCCESS",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tpl.build.status.failure",
|
||||
Usage: "tpl.build status for replace failure",
|
||||
Name: "tpl.build.status.failure",
|
||||
Usage: "tpl.build status for replace failure",
|
||||
EnvVar: "TPL_BUILD_STATUS_FAILURE, PLUGIN_TPL_BUILD_STATUS_FAILURE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
@@ -183,18 +189,18 @@ func main() {
|
||||
EnvVar: "PLUGIN_TPL,PLUGIN_CUSTOM_TPL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tpl.repo.full.name",
|
||||
Usage: "tpl custom repo full name",
|
||||
Name: "tpl.repo.full.name",
|
||||
Usage: "tpl custom repo full name",
|
||||
EnvVar: "PLUGIN_TPL_REPO_FULL_NAME,TPL_REPO_FULL_NAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tpl.repo.short.name",
|
||||
Usage: "tpl custom repo short name",
|
||||
Name: "tpl.repo.short.name",
|
||||
Usage: "tpl custom repo short name",
|
||||
EnvVar: "PLUGIN_TPL_REPO_SHORT_NAME,TPL_REPO_SHORT_NAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tpl.commit.branch.name",
|
||||
Usage: "tpl custom commit branch name",
|
||||
Name: "tpl.commit.branch.name",
|
||||
Usage: "tpl custom commit branch name",
|
||||
EnvVar: "PLUGIN_TPL_COMMIT_BRANCH_NAME,TPL_COMMIT_BRANCH_NAME",
|
||||
},
|
||||
}
|
||||
@@ -244,6 +250,7 @@ func run(c *cli.Context) {
|
||||
MsgType: c.String("config.message.type"),
|
||||
Mobiles: c.String("config.message.at.mobiles"),
|
||||
Debug: c.Bool("config.debug"),
|
||||
TipsTitle: c.String("config.tips.title"),
|
||||
},
|
||||
Custom: Custom{
|
||||
Pic: Pic{
|
||||
@@ -256,16 +263,16 @@ func run(c *cli.Context) {
|
||||
},
|
||||
Tpl: c.String("custom.tpl"),
|
||||
},
|
||||
Tpl:Tpl{
|
||||
Repo: TplRepo{
|
||||
FullName: c.String("tpl.repo.full.name"),
|
||||
Tpl: Tpl{
|
||||
Repo: TplRepo{
|
||||
FullName: c.String("tpl.repo.full.name"),
|
||||
ShortName: c.String("tpl.repo.short.name"),
|
||||
},
|
||||
Commit: TplCommit{
|
||||
Branch: c.String("tpl.commit.branch.name"),
|
||||
},
|
||||
Build: TplBuild{
|
||||
Status:Status{
|
||||
Status: Status{
|
||||
Success: c.String("tpl.build.status.success"),
|
||||
Failure: c.String("tpl.build.status.failure"),
|
||||
},
|
||||
@@ -275,5 +282,6 @@ func run(c *cli.Context) {
|
||||
|
||||
if err := plugin.Exec(); nil != err {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
webhook "github.com/lddsb/dingtalk-webhook"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -11,6 +10,8 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
webhook "github.com/lddsb/dingtalk-webhook"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -65,6 +66,7 @@ type (
|
||||
Mobiles string
|
||||
Username string
|
||||
MsgType string
|
||||
TipsTitle string
|
||||
}
|
||||
|
||||
// MessageConfig DingTalk message struct
|
||||
@@ -102,15 +104,15 @@ type (
|
||||
}
|
||||
|
||||
Custom struct {
|
||||
Tpl string
|
||||
Color Color
|
||||
Pic Pic
|
||||
Tpl string
|
||||
Color Color
|
||||
Pic Pic
|
||||
}
|
||||
|
||||
Tpl struct {
|
||||
Repo TplRepo
|
||||
Commit TplCommit
|
||||
Build TplBuild
|
||||
Build TplBuild
|
||||
}
|
||||
|
||||
TplRepo struct {
|
||||
@@ -145,11 +147,15 @@ func (p *Plugin) Exec() error {
|
||||
return err
|
||||
}
|
||||
|
||||
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("new message", tpl, p.Config.IsAtALL, mobiles...)
|
||||
err = newWebhook.SendMarkdownMsg(p.Config.TipsTitle, tpl, p.Config.IsAtALL, mobiles...)
|
||||
case "text":
|
||||
err = newWebhook.SendTextMsg(tpl, p.Config.IsAtALL, mobiles...)
|
||||
case "link":
|
||||
@@ -226,7 +232,6 @@ func (p *Plugin) getTpl() (tpl string, err error) {
|
||||
tpl = string(tplStr)
|
||||
}
|
||||
|
||||
|
||||
return tpl, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user