-
Notifications
You must be signed in to change notification settings - Fork 0
/
dingtalk.go
63 lines (55 loc) · 1.56 KB
/
dingtalk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package notify
import (
"fmt"
"github.com/hopeio/cherry/utils/sdk/dingding"
"github.com/urfave/cli/v2"
"time"
)
type Config struct {
Repo string
CommitAuthor string
Commit string
CommitTag string
CommitRef string
CommitMessage string
CommitBranch string
DingToken string
DingSecret string
BuildLink string
}
func GetConfig(c *cli.Context) *Config {
return &Config{
Repo: c.String("repo"),
CommitAuthor: c.String("commit_author_name"),
Commit: c.String("commit"),
CommitTag: c.String("commit_tag"),
CommitRef: c.String("commit_ref"),
CommitMessage: c.String("commit_message"),
CommitBranch: c.String("commit_branch"),
DingToken: c.String("ding_token"),
DingSecret: c.String("ding_secret"),
BuildLink: c.String("drone_build_link"),
}
}
func Notify(c *Config) error {
if c.DingToken == "" {
return nil
}
msg := "\\n # 发布通知 " +
" \\n ### 项目: " + c.Repo +
" \\n ### 操作人: " + c.CommitAuthor +
" \\n ### 参考: " + c.CommitRef +
" \\n ### 分支: " + c.CommitBranch +
" \\n ### 标签: " + c.CommitTag +
" \\n ### 时间: " + fmt.Sprint(time.Now().Format("2006-01-02 15:04:05")) +
" \\n ### 提交: " + c.Commit +
" \\n ### 提交信息: " + c.CommitMessage +
" \\n ### 发布详情: " + c.BuildLink
var err error
if c.DingSecret != "" {
err = dingding.SendRobotMarkDownMessageWithSecret(c.DingToken, c.DingSecret, "发布通知", msg)
} else {
err = dingding.SendRobotMarkDownMessage(c.DingToken, "发布通知", msg)
}
return err
}