Skip to content

Commit

Permalink
feat(webhook): 优化提示信息模板
Browse files Browse the repository at this point in the history
  • Loading branch information
dydhyhwu committed Apr 24, 2024
1 parent 1d3e95e commit 74b26fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 6 additions & 1 deletion httpd/wrobot/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ func (w *Webhook) receive(c *gin.Context) {

// 根据app类型不同,调用不同的处理方式,参照handler的注册
msg := whapp.Handler(c.Request.Header, app, string(request))
res := wc.CmdClient.SendTxt(msg, hook.TargetId, "")

var res int32

if msg != "" {
res = wc.CmdClient.SendTxt(msg, hook.TargetId, "")
}

if res == 0 {
c.Set("Message", "OK")
Expand Down
2 changes: 1 addition & 1 deletion wclient/whapp/gitea/handlers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func CreateEventHandler(msg string) (string, error) {
return "", errors.New("解析Gitea Create事件失败")
}

switch data.Ref {
switch data.RefType {
case "tag":
return templates.Render(templates.TemplateCreateTag, data)
}
Expand Down
6 changes: 6 additions & 0 deletions wclient/whapp/gitea/handlers/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"github.com/opentdp/wrest-chat/wclient/whapp/gitea/events"
"github.com/opentdp/wrest-chat/wclient/whapp/gitea/templates"
"strings"
)

func PushEventHandler(msg string) (string, error) {
Expand All @@ -15,5 +16,10 @@ func PushEventHandler(msg string) (string, error) {
return "", errors.New("解析Gitea Push事件失败")
}

// ignore push tag
if strings.HasPrefix(data.Ref, "refs/tags/") {
return "", nil
}

return templates.Render(templates.TemplatePush, data)
}
12 changes: 5 additions & 7 deletions wclient/whapp/gitea/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ var (
⚠️ 暂不支持该类型
🙈 我们正在努力支持更多类型,敬请期待!
`
TemplatePush = NewTemplate("GITEA_PUSH", `🔔 来自Gitea的消息
👤 {{ .Pusher.FullName }}({{ .Pusher.Email }})
📌 向仓库 {{ .Repository.FullName }} 推送了{{ .TotalCommits }}次提交
TemplatePush = NewTemplate("GITEA_PUSH", `🔔 有人推送代码啦
📦 仓库:{{ .Repository.FullName }}
📊 提交记录:{{ range $index, $val := .Commits }}
{{inc $index}}: {{ getShortMsg $val.Message }}(by {{ $val.Author.Name }}){{ end }}
{{inc $index}}. {{ getShortMsg $val.Message }}(by @{{ $val.Author.Name }}){{ end }}
`)
TemplateCreateTag = NewTemplate("GITEA_CREATE_TAG", `🔖 新Tag
TemplateCreateTag = NewTemplate("GITEA_CREATE_TAG", `🔖 有人创建Tag啦
📦 {{ .Repository.FullName }}
🏷️ {{ .Ref }}
👤 {{ .Sender.FullName }}({{ .Sender.Email }})
`)
TemplateOpenIssue = NewTemplate("OPEN_ISSUE", `✨ 有人提Issue了
TemplateOpenIssue = NewTemplate("OPEN_ISSUE", `✨ 有人提Issue啦
📦 {{ .Repository.FullName }}#{{ .Issue.Number }}
💡 {{ .Issue.Title }}
👤 {{ .Sender.FullName }}({{ .Sender.Email }})
Expand Down

0 comments on commit 74b26fe

Please sign in to comment.