mirror of
https://github.com/lddsb/drone-dingtalk-message.git
synced 2026-06-04 18:33:48 +08:00
rewrite markdown message tpl
This commit is contained in:
@@ -298,22 +298,37 @@ func main() {
|
||||
cli.StringFlag{
|
||||
Name: "config.success.pic.url",
|
||||
Usage: "config success picture url",
|
||||
EnvVar: "SUCCESS_PICTURE_URL",
|
||||
EnvVar: "SUCCESS_PICTURE_URL,PLUGIN_SUCCESS_PIC",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.failure.pic.url",
|
||||
Usage: "config failure picture url",
|
||||
EnvVar: "FAILURE_PICTURE_URL",
|
||||
EnvVar: "FAILURE_PICTURE_URL,PLUGIN_FAILURE_PIC",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.success.color",
|
||||
Usage: "config success color for title in markdown",
|
||||
EnvVar: "SUCCESS_COLOR",
|
||||
EnvVar: "SUCCESS_COLOR,PLUGIN_SUCCESS_COLOR",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.failure.color",
|
||||
Usage: "config failure color for title in markdown",
|
||||
EnvVar: "FAILURE_COLOR",
|
||||
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "config.message.color",
|
||||
Usage: "configure the message with color or not",
|
||||
EnvVar: "PLUGIN_COLOR,PLUGIN_MESSAGE_COLOR",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "config.message.pic",
|
||||
Usage: "configure the message with picture or not",
|
||||
EnvVar: "PLUGIN_PIC,PLUGIN_MESSAGE_PIC",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "config.message.sha.link",
|
||||
Usage: "link sha source page or not",
|
||||
EnvVar: "PLUGIN_SHA_LINK,PLUGIN_MESSAGE_SHA_LINK",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -368,6 +383,9 @@ func run(c *cli.Context) {
|
||||
FailurePicUrl: c.String("config.failure.pic.url"),
|
||||
SuccessColor: c.String("config.success.color"),
|
||||
FailureColor: c.String("config.failure.color"),
|
||||
WithColor: c.Bool("config.message.color"),
|
||||
WithPic: c.Bool("config.message.pic"),
|
||||
LinkSha: c.Bool("config.message.sha.link"),
|
||||
},
|
||||
CI: CI{
|
||||
RepoLink: c.String("ci.repo.link"),
|
||||
|
||||
@@ -89,6 +89,9 @@ type (
|
||||
FailurePicUrl string
|
||||
SuccessColor string
|
||||
FailureColor string
|
||||
WithColor bool
|
||||
WithPic bool
|
||||
LinkSha bool
|
||||
}
|
||||
// plugin all config
|
||||
Plugin struct {
|
||||
@@ -163,29 +166,58 @@ func (p *Plugin) Exec() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) markdownTpl() string {
|
||||
var tpl string
|
||||
|
||||
// title
|
||||
title := fmt.Sprintf(" %s *Branch Build %s*",
|
||||
strings.Title(p.Commit.Branch),
|
||||
strings.Title(p.Build.Status))
|
||||
// with color on title
|
||||
if p.Config.WithColor {
|
||||
title = fmt.Sprintf("<font color=%s>%s</font>", p.getColor(), title)
|
||||
}
|
||||
|
||||
tpl = fmt.Sprintf("# %s \n", title)
|
||||
|
||||
// with pic
|
||||
if p.Config.WithPic {
|
||||
tpl += fmt.Sprintf(")
|
||||
}
|
||||
|
||||
// commit message
|
||||
commitMsg := fmt.Sprintf("%s", p.Commit.Message)
|
||||
if p.Config.WithColor {
|
||||
commitMsg = fmt.Sprintf("<font color=%s>%s</font>", p.getColor(), commitMsg)
|
||||
}
|
||||
tpl += commitMsg + "\n\n"
|
||||
|
||||
// sha info
|
||||
commitSha := p.Commit.Sha
|
||||
if p.Config.LinkSha {
|
||||
commitSha = fmt.Sprintf("[Click To %s Commit Detail Page](%s)", commitSha[:6], p.Commit.Link)
|
||||
}
|
||||
tpl += commitSha + "\n\n"
|
||||
|
||||
// author info
|
||||
authorInfo := fmt.Sprintf("`%s(%s)`", p.Commit.Authors.Name, p.Commit.Authors.Email)
|
||||
tpl += authorInfo + "\n\n"
|
||||
|
||||
// build detail link
|
||||
buildDetail := fmt.Sprintf("[Click To The Build Detail Page %s](%s)",
|
||||
p.getEmoticon(),
|
||||
p.Build.Link)
|
||||
tpl += buildDetail
|
||||
return tpl
|
||||
}
|
||||
|
||||
func (p *Plugin) baseTpl() string {
|
||||
tpl := ""
|
||||
switch strings.ToLower(p.Config.MsgType) {
|
||||
case "markdown":
|
||||
tpl = fmt.Sprintf("# <font color=%s >%s *Branch Build %s*</font>\n"+
|
||||
"\n\n"+
|
||||
"<font color=%s >%s</font>\n\n"+
|
||||
"[%s](%s)\n\n"+
|
||||
"`%s(%s)`\n\n"+
|
||||
"[Build's Detail Click Me %s](%s)",
|
||||
p.getColor(),
|
||||
strings.Title(p.Commit.Branch),
|
||||
strings.Title(p.Build.Status),
|
||||
p.Build.Status,
|
||||
p.getPicUrl(),
|
||||
p.getColor(),
|
||||
p.Commit.Message,
|
||||
p.Commit.Sha,
|
||||
p.Commit.Link,
|
||||
p.Commit.Authors.Name,
|
||||
p.Commit.Authors.Email,
|
||||
p.getEmoticon(),
|
||||
p.Build.Link)
|
||||
tpl = p.markdownTpl()
|
||||
case "text":
|
||||
tpl = fmt.Sprintf(`[%s] %s
|
||||
%s (%s)
|
||||
|
||||
Reference in New Issue
Block a user