Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for corporate WeChat webhooks #15910

Merged
merged 83 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
12c9224
企业微信webhook
lengyuqu May 17, 2021
75f0f17
企业微信webhook
lengyuqu May 17, 2021
5112a6e
企业微信webhook
lengyuqu May 17, 2021
49c9678
Merge branch 'go-gitea:main' into master
lengyuqu May 17, 2021
254aaa6
Merge branch 'main' into master
lengyuqu May 18, 2021
701cee8
Update templates/admin/hook_new.tmpl
lengyuqu May 18, 2021
2ede040
Update services/webhook/wechatwork.go
lengyuqu May 18, 2021
dd25990
修善wechatwork
May 18, 2021
84fd130
修善wechatwork
May 19, 2021
40763c2
Merge branch 'go-gitea:main' into master
lengyuqu May 20, 2021
b6166e5
Merge branch 'main' into master
lengyuqu May 24, 2021
eda8b88
Merge branch 'go-gitea:main' into master
lengyuqu May 29, 2021
4fc7d6c
fix
Jun 1, 2021
b17eeb1
Update locale_cs-CZ.ini
lengyuqu Jun 1, 2021
6242c08
Merge branch 'go-gitea:main' into master
lengyuqu Jun 2, 2021
d161fc3
Merge branch 'go-gitea:main' into master
lengyuqu Jun 4, 2021
302c5ec
Merge branch 'master' of https://github.com/lengyuqu/gitea
Jun 4, 2021
c42ae73
Merge branch 'main' of https://github.com/go-gitea/gitea
Jun 10, 2021
639a929
fix build
Jun 10, 2021
646d8de
fix
Jun 10, 2021
a891430
fix build
Jun 10, 2021
b90fc28
Merge branch 'go-gitea:main' into master
lengyuqu Jun 10, 2021
f91fb27
make webhooks.zh-cn.md
lengyuqu Jun 10, 2021
1148054
delet unnecessary blank line
lengyuqu Jun 10, 2021
51ea36a
delet unnecessary blank line
lengyuqu Jun 10, 2021
475091d
Merge branch 'go-gitea:main' into master
lengyuqu Jun 16, 2021
ccf9a15
Merge branch 'go-gitea:main' into master
lengyuqu Jun 18, 2021
2c39f37
Merge branch 'go-gitea:main' into master
lengyuqu Jun 21, 2021
6a6c50a
企业微信webhook
lengyuqu May 17, 2021
59c5426
企业微信webhook
lengyuqu May 17, 2021
1386ce8
企业微信webhook
lengyuqu May 17, 2021
657c0c9
Update templates/admin/hook_new.tmpl
lengyuqu May 18, 2021
7b0c404
Update services/webhook/wechatwork.go
lengyuqu May 18, 2021
d603dd4
修善wechatwork
May 18, 2021
c5a9858
修善wechatwork
May 19, 2021
20f9d45
fix
Jun 1, 2021
c891c28
fix build
Jun 10, 2021
a371851
fix
Jun 10, 2021
ae944ff
fix build
Jun 10, 2021
bf9aa2e
make webhooks.zh-cn.md
lengyuqu Jun 10, 2021
83a68a1
delet unnecessary blank line
lengyuqu Jun 10, 2021
cdac829
delet unnecessary blank line
lengyuqu Jun 10, 2021
66614aa
Merge remote-tracking branch 'origin/master'
lengyuqu Jul 9, 2021
03c353c
企业微信webhook
lengyuqu May 17, 2021
eea9001
企业微信webhook
lengyuqu May 17, 2021
1e026c8
企业微信webhook
lengyuqu May 17, 2021
23c16a5
企业微信webhook
lengyuqu May 17, 2021
760914f
企业微信webhook
lengyuqu May 17, 2021
c064b01
fix
Jun 1, 2021
98318c8
fix
Jun 10, 2021
a538aa0
企业微信webhook
lengyuqu May 17, 2021
ea9b3da
企业微信webhook
lengyuqu May 17, 2021
d93d821
企业微信webhook
lengyuqu May 17, 2021
d69d628
fix wechat
lengyuqu Jul 10, 2021
cbf6319
Merge remote-tracking branch 'origin/master'
lengyuqu Jul 10, 2021
8b6f467
fix wechat
lengyuqu Jul 10, 2021
6983469
Merge branch 'main' of https://github.com/go-gitea/gitea
lengyuqu Jul 10, 2021
ec3e72a
fix wechat
lengyuqu Jul 10, 2021
b26728e
fix wechat
lengyuqu Jul 10, 2021
118cfbc
Fix invalid params and typo of email templates (#16394)
Meano Jul 10, 2021
8d3b1fd
Add LRU mem cache implementation (#16226)
zeripath Jul 10, 2021
f6f4a08
[skip ci] Updated translations via Crowdin
GiteaBot Jul 12, 2021
2e048f5
Replace `plugins/docker` with `techknowlogick/drone-docker`in ci (#16…
6543 Jul 12, 2021
bc5da3f
docs: rewrite email setup (#16404)
bagasme Jul 12, 2021
370d1d1
Validate Issue Index before querying DB (#16406)
noerw Jul 12, 2021
815fa0e
Fix external renderer (#16401)
6543 Jul 12, 2021
c039ecc
Add checkbox to delete pull branch after successful merge (#16049)
jpraet Jul 12, 2021
b04748d
[skip ci] Updated translations via Crowdin
GiteaBot Jul 13, 2021
a748490
Detect encoding changes while parsing diff (#16330)
jpraet Jul 13, 2021
5fa390a
Let branch/tag name be a valid ref to get CI status (#16400)
6543 Jul 13, 2021
14ddbc8
fix
Jun 1, 2021
47a8e0e
fix
Jun 10, 2021
75855d5
企业微信webhook
lengyuqu May 17, 2021
f1fbdd1
企业微信webhook
lengyuqu May 17, 2021
f53d723
企业微信webhook
lengyuqu May 17, 2021
dffb2af
fix build
Jul 13, 2021
fdc4633
Merge branch 'main' into master
lengyuqu Jul 13, 2021
4861d91
fix build
Jul 13, 2021
6b3f71c
Merge branch 'go-gitea:main' into master
lengyuqu Jul 15, 2021
2fe8e10
Merge branch 'main' into master
lengyuqu Jul 19, 2021
9d0ef12
Merge branch 'main' into master
6543 Jul 21, 2021
b1e45aa
Apply suggestions from code review
6543 Jul 21, 2021
e5b6888
Merge branch 'main' into master
lunny Jul 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/doc/features/webhooks.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ All event pushes are POST requests. The methods currently supported are:
- Telegram
- Microsoft Teams
- Feishu
- Wechatwork

### Event information

Expand Down
13 changes: 13 additions & 0 deletions docs/content/doc/features/webhooks.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@ menu:

# Webhooks


6543 marked this conversation as resolved.
Show resolved Hide resolved
Gitea 的存储 webhook。这可以有存储库管路设定页 `/:username/:reponame/settings/hooks` 中的。Webhook 也可以按照组织调整或全系统调整,所有时间的推送都是POST请求
。此方法目前被下列服务支援:

- Gitea (也可以是 GET 請求)
- Gogs
- Slack
- Discord
- Dingtalk
- Telegram
- Microsoft Teams
- Feishu
- Wechatwork
6543 marked this conversation as resolved.
Show resolved Hide resolved
## TBD
1 change: 1 addition & 0 deletions docs/content/doc/features/webhooks.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gitea 的儲存庫事件支援 web hook。這可以有儲存庫管理員在設
- Telegram
- Microsoft Teams
- Feishu
- Wechatwork
lengyuqu marked this conversation as resolved.
Show resolved Hide resolved

### 事件資訊

Expand Down
20 changes: 11 additions & 9 deletions models/migrations/v161.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 11 additions & 9 deletions models/migrations/v162.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 10 additions & 9 deletions models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/setting/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion modules/structs/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_cs-CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,7 @@ settings.add_telegram_hook_desc=Integrovat <a href="%s">Telegram</a> do vašeho
settings.add_matrix_hook_desc=Integrovat <a href="%s">Matrix</a> do vašeho repozitáře.
settings.add_msteams_hook_desc=Integrovat <a href="%s">Microsoft Teams</a> do vašeho repozitáře.
settings.add_feishu_hook_desc=Integrovat <a href="%s">Feishu</a> do vašeho repozitáře.
settings.add_wechatwork_hook_desc=Integrovat <a href="%s">Wechatwork</a> do vašeho repozitáře.
lengyuqu marked this conversation as resolved.
Show resolved Hide resolved
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í.
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ settings.add_telegram_hook_desc = Integrate <a href="%s">Telegram</a> into your
settings.add_matrix_hook_desc = Integrate <a href="%s">Matrix</a> into your repository.
settings.add_msteams_hook_desc = Integrate <a href="%s">Microsoft Teams</a> into your repository.
settings.add_feishu_hook_desc = Integrate <a href="%s">Feishu</a> into your repository.
settings.add_Wechat_hook_desc = Integrate <a href="%s">Wechatwork</a> 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.
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ settings.add_telegram_hook_desc=将 <a href="%s">Telegram</a> 集成到您的仓
settings.add_matrix_hook_desc=将 <a href="%s">Matrix</a> 集成到您的仓库中。
settings.add_msteams_hook_desc=将 <a href="%s">Microsoft Teams</a> 集成到您的仓库中。
settings.add_feishu_hook_desc=将 <a href="%s">Feishu</a> 集成到您的仓库中。
settings.add_wechatwork_hook_desc=将 <a href="%s">Wechatwork</a> 集成到您的仓库中。
lengyuqu marked this conversation as resolved.
Show resolved Hide resolved
settings.deploy_keys=部署密钥
settings.add_deploy_key=添加部署密钥
settings.deploy_key_desc=部署密钥具有对仓库的只读拉取权限。
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,7 @@ settings.add_telegram_hook_desc=將 <a href="%s">Telegram</a> 整合到您的儲
settings.add_matrix_hook_desc=將 <a href="%s">Matrix</a> 整合到您的儲存庫。
settings.add_msteams_hook_desc=將 <a href="%s">Microsoft Teams</a> 整合到您的儲存庫。
settings.add_feishu_hook_desc=將 <a href="%s">Feishu</a> 整合到您的儲存庫。
settings.add_wechatwork_hook_desc=将 <a href="%s">Wechatwork</a> 整合到您的儲存庫。
settings.deploy_keys=部署金鑰
settings.add_deploy_key=新增部署金鑰
settings.deploy_key_desc=部署金鑰具有唯讀權限,可拉取此儲存庫。
Expand Down
Binary file added public/img/wechatwork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions routers/web/repo/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,50 @@ func FeishuHooksNewPost(ctx *context.Context) {
ctx.Redirect(orCtx.Link)
}

// WechatworkHooksNewPost response for creating wechatwork hook
func WechatworkHooksNewPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm)

ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
ctx.Data["HookType"] = models.WECHATWORK

orCtx, err := getOrgRepoCtx(ctx)
if err != nil {
ctx.ServerError("getOrgRepoCtx", err)
return
}

if ctx.HasError() {
ctx.HTML(http.StatusOK, orCtx.NewTemplate)
return
}

w := &models.Webhook{
RepoID: orCtx.RepoID,
URL: form.PayloadURL,
ContentType: models.ContentTypeJSON,
HookEvent: ParseHookEvent(form.WebhookForm),
IsActive: form.Active,
Type: models.WECHATWORK,
Meta: "",
OrgID: orCtx.OrgID,
IsSystemWebhook: orCtx.IsSystemWebhook,
}
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
ctx.ServerError("CreateWebhook", err)
return
}

ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
ctx.Redirect(orCtx.Link)
}

func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
ctx.Data["RequireHighlightJS"] = true

Expand Down Expand Up @@ -1062,6 +1106,39 @@ func FeishuHooksEditPost(ctx *context.Context) {
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
}

// WechatworkHooksEditPost response for editing wechatwork hook
func WechatworkHooksEditPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true

orCtx, w := checkWebhook(ctx)
if ctx.Written() {
return
}
ctx.Data["Webhook"] = w

if ctx.HasError() {
ctx.HTML(http.StatusOK, orCtx.NewTemplate)
return
}

w.URL = form.PayloadURL
w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil {
ctx.ServerError("UpdateEvent", err)
return
} else if err := models.UpdateWebhook(w); err != nil {
ctx.ServerError("UpdateWebhook", err)
return
}

ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
}

// TestWebhook test if web hook is work fine
func TestWebhook(ctx *context.Context) {
hookID := ctx.ParamsInt64(":id")
Expand Down
5 changes: 5 additions & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/matrix/{id}", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
m.Post("/wechatwork/{id}", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksEditPost)
}, webhooksEnabled)

m.Group("/{configType:default-hooks|system-hooks}", func() {
Expand All @@ -438,6 +439,8 @@ func RegisterRoutes(m *web.Route) {
m.Post("/matrix/new", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost)

})

m.Group("/auths", func() {
Expand Down Expand Up @@ -628,6 +631,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/matrix/new", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost)
m.Get("/{id}", repo.WebHooksEdit)
m.Post("/{id}/test", repo.TestWebhook)
m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost)
Expand All @@ -639,6 +643,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/matrix/{id}", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
m.Post("/wechatwork/{id}", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksEditPost)
}, webhooksEnabled)

m.Group("/keys", func() {
Expand Down
12 changes: 12 additions & 0 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) bin
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

// NewWechatWorkHookForm form for creating wechatwork hook
type NewWechatWorkHookForm struct {
PayloadURL string `binding:"Required;ValidUrl"`
WebhookForm
}

// Validate validates the fields
func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
ctx := context.GetContext(req)
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

// .___
// | | ______ ________ __ ____
// | |/ ___// ___/ | \_/ __ \
Expand Down
4 changes: 4 additions & 0 deletions services/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ var (
name: models.MATRIX,
payloadCreator: GetMatrixPayload,
},
models.WECHATWORK: {
name: models.WECHATWORK,
payloadCreator: GetWechatworkPayload,
},
}
)

Expand Down
Loading