From 078e2b2c39f119b9cbe5678ce12f1cc9eb6ddda9 Mon Sep 17 00:00:00 2001 From: lengyuqu Date: Fri, 23 Jul 2021 12:41:27 +0800 Subject: [PATCH] Add support for corporate WeChat webhooks (#15910) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 企业微信webhook * 企业微信webhook * 企业微信webhook * Update templates/admin/hook_new.tmpl Co-authored-by: a1012112796 <1012112796@qq.com> * Update services/webhook/wechatwork.go Co-authored-by: a1012112796 <1012112796@qq.com> * 修善wechatwork * 修善wechatwork * fix * Update locale_cs-CZ.ini fix * fix build * fix * fix build * make webhooks.zh-cn.md * delet unnecessary blank line * delet unnecessary blank line * 企业微信webhook * 企业微信webhook * 企业微信webhook * Update templates/admin/hook_new.tmpl Co-authored-by: a1012112796 <1012112796@qq.com> * Update services/webhook/wechatwork.go Co-authored-by: a1012112796 <1012112796@qq.com> * 修善wechatwork * 修善wechatwork * fix * fix build * fix * fix build * make webhooks.zh-cn.md * delet unnecessary blank line * delet unnecessary blank line * 企业微信webhook * 企业微信webhook * 企业微信webhook * 企业微信webhook * 企业微信webhook * fix * fix * 企业微信webhook * 企业微信webhook * 企业微信webhook * fix wechat * fix wechat * fix wechat * fix wechat * Fix invalid params and typo of email templates (#16394) Signed-off-by: Meano * Add LRU mem cache implementation (#16226) The current default memory cache implementation is unbounded in size and number of objects cached. This is hardly ideal. This PR proposes creating a TwoQueue LRU cache as the underlying cache for Gitea. The cache is limited by the number of objects stored in the cache (rather than size) for simplicity. The default number of objects is 50000 - which is perhaps too small as most of our objects cached are going to be much less than 1kB. It may be worth considering using a different LRU implementation that actively limits sizes or avoids GC - however, this is just a beginning implementation. Signed-off-by: Andrew Thornton * [skip ci] Updated translations via Crowdin * Replace `plugins/docker` with `techknowlogick/drone-docker`in ci (#16407) * plugins/docker -> techknowlogick/drone-docker * It is multi-arch * docs: rewrite email setup (#16404) * Add intro for both the docs page and mailer methods * Fix numbering level in SMTP section * Recommends implicit TLS Signed-off-by: Bagas Sanjaya * Validate Issue Index before querying DB (#16406) * Fix external renderer (#16401) * fix external renderer * use GBackground context as fallback * no fallback, return error Co-authored-by: Lauris BH * Add checkbox to delete pull branch after successful merge (#16049) * Add checkbox to delete pull branch after successful merge * Omit DeleteBranchAfterMerge field in json * Log a warning instead of error when PR head branch deleted * Add DefaultDeleteBranchAfterMerge to PullRequestConfig * Add support for delete_branch_after_merge via API * Fix for API: the branch should be deleted from the HEAD repo If head and base repo are the same, reuse the already opened ctx.Repo.GitRepo * Don't delegate to CleanupBranch, only reuse branch deletion code CleanupBranch contains too much logic that has already been performed by the Merge * Reuse gitrepo in MergePullRequest Co-authored-by: Andrew Thornton * [skip ci] Updated translations via Crowdin * Detect encoding changes while parsing diff (#16330) * Detect encoding changes while parsing diff * Let branch/tag name be a valid ref to get CI status (#16400) * fix #16384# * refactor: move shared helper func to utils package * extend Tests * use ctx.Repo.GitRepo if not nil * fix * fix * 企业微信webhook * 企业微信webhook * 企业微信webhook * fix build * fix build * Apply suggestions from code review Co-authored-by: a1012112796 <1012112796@qq.com> Co-authored-by: myheavily Co-authored-by: zhaoxin Co-authored-by: Meano Co-authored-by: zeripath Co-authored-by: GiteaBot Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Bagas Sanjaya Co-authored-by: Norwin Co-authored-by: Lauris BH Co-authored-by: Jimmy Praet Co-authored-by: Lunny Xiao --- docs/content/doc/features/webhooks.en-us.md | 1 + docs/content/doc/features/webhooks.zh-cn.md | 13 ++ docs/content/doc/features/webhooks.zh-tw.md | 1 + models/migrations/v161.go | 20 +- models/migrations/v162.go | 20 +- models/webhook.go | 19 +- modules/setting/webhook.go | 2 +- modules/structs/hook.go | 2 +- options/locale/locale_cs-CZ.ini | 1 + options/locale/locale_en-US.ini | 1 + options/locale/locale_zh-CN.ini | 1 + options/locale/locale_zh-TW.ini | 1 + public/img/wechatwork.png | Bin 0 -> 9341 bytes routers/web/repo/webhook.go | 77 +++++++ routers/web/web.go | 5 + services/forms/repo_form.go | 12 ++ services/webhook/webhook.go | 4 + services/webhook/wechatwork.go | 188 ++++++++++++++++++ templates/admin/hook_new.tmpl | 3 + templates/org/settings/hook_new.tmpl | 3 + .../repo/settings/webhook/base_list.tmpl | 3 + templates/repo/settings/webhook/new.tmpl | 3 + .../repo/settings/webhook/wechatwork.tmpl | 11 + templates/swagger/v1_json.tmpl | 3 +- 24 files changed, 364 insertions(+), 30 deletions(-) create mode 100644 public/img/wechatwork.png create mode 100644 services/webhook/wechatwork.go create mode 100644 templates/repo/settings/webhook/wechatwork.tmpl diff --git a/docs/content/doc/features/webhooks.en-us.md b/docs/content/doc/features/webhooks.en-us.md index 5d792f5f5..7a88f2a5e 100644 --- a/docs/content/doc/features/webhooks.en-us.md +++ b/docs/content/doc/features/webhooks.en-us.md @@ -27,6 +27,7 @@ All event pushes are POST requests. The methods currently supported are: - Telegram - Microsoft Teams - Feishu +- Wechatwork ### Event information diff --git a/docs/content/doc/features/webhooks.zh-cn.md b/docs/content/doc/features/webhooks.zh-cn.md index fe9008717..f3a312eee 100644 --- a/docs/content/doc/features/webhooks.zh-cn.md +++ b/docs/content/doc/features/webhooks.zh-cn.md @@ -15,4 +15,17 @@ menu: # Webhooks +Gitea 的存储 webhook。这可以有存储库管路设定页 `/:username/:reponame/settings/hooks` 中的。Webhook 也可以按照组织调整或全系统调整,所有时间的推送都是POST请求 +。此方法目前被下列服务支援: + +- Gitea (也可以是 GET 請求) +- Gogs +- Slack +- Discord +- Dingtalk +- Telegram +- Microsoft Teams +- Feishu +- Wechatwork + ## TBD diff --git a/docs/content/doc/features/webhooks.zh-tw.md b/docs/content/doc/features/webhooks.zh-tw.md index 0d1c564f6..697b41391 100644 --- a/docs/content/doc/features/webhooks.zh-tw.md +++ b/docs/content/doc/features/webhooks.zh-tw.md @@ -26,6 +26,7 @@ Gitea 的儲存庫事件支援 web hook。這可以有儲存庫管理員在設 - Telegram - Microsoft Teams - Feishu +- Wechatwork ### 事件資訊 diff --git a/models/migrations/v161.go b/models/migrations/v161.go index 4ca9f0121..7ef06b4c2 100644 --- a/models/migrations/v161.go +++ b/models/migrations/v161.go @@ -19,18 +19,20 @@ func convertTaskTypeToString(x *xorm.Engine) error { MSTEAMS FEISHU MATRIX + WECHATWORK ) hookTaskTypes := map[int]string{ - GITEA: "gitea", - GOGS: "gogs", - SLACK: "slack", - DISCORD: "discord", - DINGTALK: "dingtalk", - TELEGRAM: "telegram", - MSTEAMS: "msteams", - FEISHU: "feishu", - MATRIX: "matrix", + GITEA: "gitea", + GOGS: "gogs", + SLACK: "slack", + DISCORD: "discord", + DINGTALK: "dingtalk", + TELEGRAM: "telegram", + MSTEAMS: "msteams", + FEISHU: "feishu", + MATRIX: "matrix", + WECHATWORK: "wechatwork", } type HookTask struct { diff --git a/models/migrations/v162.go b/models/migrations/v162.go index 9dd175cd3..cf2baadbc 100644 --- a/models/migrations/v162.go +++ b/models/migrations/v162.go @@ -19,18 +19,20 @@ func convertWebhookTaskTypeToString(x *xorm.Engine) error { MSTEAMS FEISHU MATRIX + WECHATWORK ) hookTaskTypes := map[int]string{ - GITEA: "gitea", - GOGS: "gogs", - SLACK: "slack", - DISCORD: "discord", - DINGTALK: "dingtalk", - TELEGRAM: "telegram", - MSTEAMS: "msteams", - FEISHU: "feishu", - MATRIX: "matrix", + GITEA: "gitea", + GOGS: "gogs", + SLACK: "slack", + DISCORD: "discord", + DINGTALK: "dingtalk", + TELEGRAM: "telegram", + MSTEAMS: "msteams", + FEISHU: "feishu", + MATRIX: "matrix", + WECHATWORK: "wechatwork", } type Webhook struct { diff --git a/models/webhook.go b/models/webhook.go index 29cfcf6ed..9c8c0a568 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -114,15 +114,16 @@ type HookType = string // Types of webhooks const ( - GITEA HookType = "gitea" - GOGS HookType = "gogs" - SLACK HookType = "slack" - DISCORD HookType = "discord" - DINGTALK HookType = "dingtalk" - TELEGRAM HookType = "telegram" - MSTEAMS HookType = "msteams" - FEISHU HookType = "feishu" - MATRIX HookType = "matrix" + GITEA HookType = "gitea" + GOGS HookType = "gogs" + SLACK HookType = "slack" + DISCORD HookType = "discord" + DINGTALK HookType = "dingtalk" + TELEGRAM HookType = "telegram" + MSTEAMS HookType = "msteams" + FEISHU HookType = "feishu" + MATRIX HookType = "matrix" + WECHATWORK HookType = "wechatwork" ) // HookStatus is the status of a web hook diff --git a/modules/setting/webhook.go b/modules/setting/webhook.go index 4a0c593c8..8ef54f5cb 100644 --- a/modules/setting/webhook.go +++ b/modules/setting/webhook.go @@ -36,7 +36,7 @@ func newWebhookService() { Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000) Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5) Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool() - Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix"} + Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork"} Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10) Webhook.ProxyURL = sec.Key("PROXY_URL").MustString("") if Webhook.ProxyURL != "" { diff --git a/modules/structs/hook.go b/modules/structs/hook.go index e4ec99df4..ad86cb35a 100644 --- a/modules/structs/hook.go +++ b/modules/structs/hook.go @@ -42,7 +42,7 @@ type CreateHookOptionConfig map[string]string // CreateHookOption options when create a hook type CreateHookOption struct { // required: true - // enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu + // enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork Type string `json:"type" binding:"Required"` // required: true Config CreateHookOptionConfig `json:"config" binding:"Required"` diff --git a/options/locale/locale_cs-CZ.ini b/options/locale/locale_cs-CZ.ini index 2ee17ef36..373ee9457 100644 --- a/options/locale/locale_cs-CZ.ini +++ b/options/locale/locale_cs-CZ.ini @@ -1758,6 +1758,7 @@ settings.add_telegram_hook_desc=Integrovat Telegram do vašeho settings.add_matrix_hook_desc=Integrovat Matrix do vašeho repozitáře. settings.add_msteams_hook_desc=Integrovat Microsoft Teams do vašeho repozitáře. settings.add_feishu_hook_desc=Integrovat Feishu do vašeho repozitáře. +settings.add_wechatwork_hook_desc=Integrovat Wechatwork do vašeho repozitáře. settings.deploy_keys=Klíče pro nasazení settings.add_deploy_key=Přidat klíč pro nasazení settings.deploy_key_desc=Klíče pro nasazení mají k tomuto repozitáři přístup pouze pro čtení. diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 2479bc5bb..760c02611 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1848,6 +1848,7 @@ settings.add_telegram_hook_desc = Integrate Telegram into your settings.add_matrix_hook_desc = Integrate Matrix into your repository. settings.add_msteams_hook_desc = Integrate Microsoft Teams into your repository. settings.add_feishu_hook_desc = Integrate Feishu into your repository. +settings.add_Wechat_hook_desc = Integrate Wechatwork into your repository. settings.deploy_keys = Deploy Keys settings.add_deploy_key = Add Deploy Key settings.deploy_key_desc = Deploy keys have read-only pull access to the repository. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 60a2e5c9f..9e1374cec 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1848,6 +1848,7 @@ settings.add_telegram_hook_desc=将 Telegram 集成到您的仓 settings.add_matrix_hook_desc=将 Matrix 集成到您的仓库中。 settings.add_msteams_hook_desc=将 Microsoft Teams 集成到您的仓库中。 settings.add_feishu_hook_desc=将 Feishu 集成到您的仓库中。 +settings.add_wechatwork_hook_desc=将 Wechatwork 集成到您的仓库中。 settings.deploy_keys=部署密钥 settings.add_deploy_key=添加部署密钥 settings.deploy_key_desc=部署密钥具有对仓库的只读拉取权限。 diff --git a/options/locale/locale_zh-TW.ini b/options/locale/locale_zh-TW.ini index e8c0e3c92..39f5b38e4 100644 --- a/options/locale/locale_zh-TW.ini +++ b/options/locale/locale_zh-TW.ini @@ -1833,6 +1833,7 @@ settings.add_telegram_hook_desc=將 Telegram 整合到您的儲 settings.add_matrix_hook_desc=將 Matrix 整合到您的儲存庫。 settings.add_msteams_hook_desc=將 Microsoft Teams 整合到您的儲存庫。 settings.add_feishu_hook_desc=將 Feishu 整合到您的儲存庫。 +settings.add_wechatwork_hook_desc=将 Wechatwork 整合到您的儲存庫。 settings.deploy_keys=部署金鑰 settings.add_deploy_key=新增部署金鑰 settings.deploy_key_desc=部署金鑰具有唯讀權限,可拉取此儲存庫。 diff --git a/public/img/wechatwork.png b/public/img/wechatwork.png new file mode 100644 index 0000000000000000000000000000000000000000..296225fb885144f88c2b02073d7ca642877be9ac GIT binary patch literal 9341 zcmcIq^bXg~ zSem-oI6Ba3+1Oj6@o;eqi*WOZ@bJ=d3ySb^iSP=yR)mG4p}qN|C?l!mWpuQHokcv* ziG?)2JpA)qv;kaj8YTBErU2mehIKG)_wq}8*=awm+!uKurw3UB7WovI0;A^*MGPk2 zpcUWLaDEv%24~0n7`a?BYmZNZPF0;vMB;2(@Uf4^1KE0_OL`( z;yiu_Ot#VZhql;fos8r>OH>iB@sY?PT`^qZ(#t>0rOxQt&?J(cQ z#xEtmSsG6j-=Eskye|(gyLMuRZJwly#9QHr((&=dey-;DJj<+3?8-Lq3F#ePiuTvD zti~%i0e++t?WgXAy`fJfZ!rB~Qh@RKgj=BLn)bQSf%LRz*Q|Z+SF(a?vXP+ULgL)gY2d7)CNw ztA!L&U1-rvKzgLyENkf0{^g)7yzuAV9c15DoMk7opt&S>B|~K2V0vQkpK(lGa^nN3 zCj6PnWW;D3Ts`;ob4p$t=7k}I%;$z_&O+U^*y0)A#x0HzS!eosJTlf*$zWGO z#%ML207C1(YEQa>VDTTF!BUoc@P9SOrAX?kd28h|uR%ma#K;kxYv4GjNyYu5-20{M zig4^_M+%>0qw!s9EI(?UQz@;>`{f5s!OY(s{Im1Yd56+qMZCg{{6_a(VG} zu;hEf!WCDc8IK{$`H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moAiI>x(@A-i?ml6LL8h=V!5i+9t@tS6VOjj zkH0dkrwEu~x{NtKWBj|k#v%gUt9hrj&S8}+>qDi7+W{t2Hd7Cqpv7V3;_6T;9+fr~ z&xv19rNOO^E$pINvp%C*WVPOUCTu)uJTTqzE|UJQ#z!j7VL<`orkwD97pnw)5>%J+t21hA^g8ayLHF*H40=s-*#`ZvmI9S216UZ<3U~P z8MLyTFK?33+qk zMOANxw-QnCu<-2BdS=Tv?y{Qg3RB9*}`9;^S49H$j|-stG9`3a_(b zS@(wG#c0F-{qJZN37d<9E`cjY-(0oL_$>|ws?uWk1B}9}r1D*x1~RGFzC@1;B_)eA zTG-VB?yS4%TW_CTzK$EkfF3_xweJNzH52K9N#pHS8c(|h#lvY`jHZ;A@r-EbXp>Ah z-sZ%%GO>eEiWz~Qj~7!3PiN-X6+1C9lIP5~&`#NcWdhb)iGJ_qLtgL`dss$w#`w!F zr4R7NpZ~14l=1=4J0d?~U+f!^x$5rh$Z836BV(na0**8Ep0^YG@R*TRtFEUH8 z*RT&lK#CHkf63 %s ", p.Repo.FullName, branchName, commitDesc) + + var text string + // for each commit, generate attachment text + for i, commit := range p.Commits { + var authorName string + if commit.Author != nil { + authorName = "Author:" + commit.Author.Name + } + + message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n") + text += fmt.Sprintf(" > [%s](%s) \r\n >%s \n >%s", commit.ID[:7], commit.URL, + message, authorName) + + // add linebreak to each commit but the last + if i < len(p.Commits)-1 { + text += "\n" + } + } + return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil + +} + +// Issue implements PayloadConvertor Issue method +func (f *WechatworkPayload) Issue(p *api.IssuePayload) (api.Payloader, error) { + text, issueTitle, attachmentText, _ := getIssuesPayloadInfo(p, noneLinkFormatter, true) + var content string + content += fmt.Sprintf(" >%s\n >%s \n > %s", text, attachmentText, issueTitle) + + return newWechatworkMarkdownPayload(content), nil + +} + +// IssueComment implements PayloadConvertor IssueComment method +func (f *WechatworkPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error) { + text, issueTitle, _ := getIssueCommentPayloadInfo(p, noneLinkFormatter, true) + var content string + content += fmt.Sprintf(" >%s\n >%s \n >%s", text, p.Comment.Body, issueTitle) + + return newWechatworkMarkdownPayload(content), nil + +} + +// PullRequest implements PayloadConvertor PullRequest method +func (f *WechatworkPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error) { + text, issueTitle, attachmentText, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, true) + pr := fmt.Sprintf("> %s \r\n > %s \r\n > %s \r\n", + text, issueTitle, attachmentText) + + return newWechatworkMarkdownPayload(pr), nil + +} + +// Review implements PayloadConvertor Review method +func (f *WechatworkPayload) Review(p *api.PullRequestPayload, event models.HookEventType) (api.Payloader, error) { + var text, title string + switch p.Action { + case api.HookIssueSynchronized: + action, err := parseHookPullRequestEventType(event) + if err != nil { + return nil, err + } + title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) + text = p.Review.Content + } + + return newWechatworkMarkdownPayload("# " + title + "\r\n\r\n >" + text), nil + +} + +// Repository implements PayloadConvertor Repository method +func (f *WechatworkPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error) { + var title string + switch p.Action { + case api.HookRepoCreated: + title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName) + return newWechatworkMarkdownPayload(title), nil + case api.HookRepoDeleted: + title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) + return newWechatworkMarkdownPayload(title), nil + } + + return nil, nil +} + +// Release implements PayloadConvertor Release method +func (f *WechatworkPayload) Release(p *api.ReleasePayload) (api.Payloader, error) { + text, _ := getReleasePayloadInfo(p, noneLinkFormatter, true) + + return newWechatworkMarkdownPayload(text), nil +} + +// GetWechatworkPayload GetWechatworkPayload converts a ding talk webhook into a WechatworkPayload +func GetWechatworkPayload(p api.Payloader, event models.HookEventType, meta string) (api.Payloader, error) { + return convertPayloader(new(WechatworkPayload), p, event) +} diff --git a/templates/admin/hook_new.tmpl b/templates/admin/hook_new.tmpl index 01e9e429a..4710498b2 100644 --- a/templates/admin/hook_new.tmpl +++ b/templates/admin/hook_new.tmpl @@ -32,6 +32,8 @@ {{else if eq .HookType "matrix"}} + {{else if eq .HookType "wechatwork"}} + {{end}} @@ -45,6 +47,7 @@ {{template "repo/settings/webhook/msteams" .}} {{template "repo/settings/webhook/feishu" .}} {{template "repo/settings/webhook/matrix" .}} + {{template "repo/settings/webhook/wechatwork" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/org/settings/hook_new.tmpl b/templates/org/settings/hook_new.tmpl index d070b8bc4..43351d0ce 100644 --- a/templates/org/settings/hook_new.tmpl +++ b/templates/org/settings/hook_new.tmpl @@ -27,6 +27,8 @@ {{else if eq .HookType "matrix"}} + {{else if eq .HookType "wechatwork"}} + {{end}} @@ -40,6 +42,7 @@ {{template "repo/settings/webhook/msteams" .}} {{template "repo/settings/webhook/feishu" .}} {{template "repo/settings/webhook/matrix" .}} + {{template "repo/settings/webhook/wechatwork" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/repo/settings/webhook/base_list.tmpl b/templates/repo/settings/webhook/base_list.tmpl index e77e74774..e96d08603 100644 --- a/templates/repo/settings/webhook/base_list.tmpl +++ b/templates/repo/settings/webhook/base_list.tmpl @@ -31,6 +31,9 @@ Matrix + + Wechatwork + diff --git a/templates/repo/settings/webhook/new.tmpl b/templates/repo/settings/webhook/new.tmpl index 7c2e5b1a9..6df128f40 100644 --- a/templates/repo/settings/webhook/new.tmpl +++ b/templates/repo/settings/webhook/new.tmpl @@ -25,6 +25,8 @@ {{else if eq .HookType "matrix"}} + {{else if eq .HookType "wechatwork"}} + {{end}} @@ -38,6 +40,7 @@ {{template "repo/settings/webhook/msteams" .}} {{template "repo/settings/webhook/feishu" .}} {{template "repo/settings/webhook/matrix" .}} + {{template "repo/settings/webhook/wechatwork" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/repo/settings/webhook/wechatwork.tmpl b/templates/repo/settings/webhook/wechatwork.tmpl new file mode 100644 index 000000000..503fab205 --- /dev/null +++ b/templates/repo/settings/webhook/wechatwork.tmpl @@ -0,0 +1,11 @@ +{{if eq .HookType "wechatwork"}} +

{{.i18n.Tr "repo.settings.add_wechatwork_hook_desc" "https://work.weixin.qq.com" | Str2html}}

+
+ {{.CsrfTokenHtml}} +
+ + +
+ {{template "repo/settings/webhook/settings" .}} +
+{{end}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index eeb002cb9..238265fd7 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -12917,7 +12917,8 @@ "msteams", "slack", "telegram", - "feishu" + "feishu", + "wechatwork" ], "x-go-name": "Type" }