diff --git a/httpd/wrobot/webhook.go b/httpd/wrobot/webhook.go index 94f40e5f..8d4600c6 100644 --- a/httpd/wrobot/webhook.go +++ b/httpd/wrobot/webhook.go @@ -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") diff --git a/wclient/whapp/gitea/handlers/create.go b/wclient/whapp/gitea/handlers/create.go index 2746fed7..e1ccf402 100644 --- a/wclient/whapp/gitea/handlers/create.go +++ b/wclient/whapp/gitea/handlers/create.go @@ -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) } diff --git a/wclient/whapp/gitea/handlers/push.go b/wclient/whapp/gitea/handlers/push.go index d95bee02..5ddfe24b 100644 --- a/wclient/whapp/gitea/handlers/push.go +++ b/wclient/whapp/gitea/handlers/push.go @@ -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) { @@ -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) } diff --git a/wclient/whapp/gitea/templates/template.go b/wclient/whapp/gitea/templates/template.go index f0934905..f6953669 100644 --- a/wclient/whapp/gitea/templates/template.go +++ b/wclient/whapp/gitea/templates/template.go @@ -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 }})