Skip to content

Commit e72d742

Browse files
committed
Add support for Bark webhook integration
This commit introduces the Bark notification integration, allowing users to configure Bark webhooks in repositories. It includes form models, templates, routing changes, and test cases to handle Bark webhook functionality.
1 parent b2ee5be commit e72d742

File tree

14 files changed

+646
-1
lines changed

14 files changed

+646
-1
lines changed

modules/setting/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func loadWebhookFrom(rootCfg ConfigProvider) {
3535
Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
3636
Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
3737
Webhook.AllowedHostList = sec.Key("ALLOWED_HOST_LIST").MustString("")
38-
Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork", "packagist"}
38+
Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork", "packagist", "bark"}
3939
Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
4040
Webhook.ProxyURL = sec.Key("PROXY_URL").MustString("")
4141
if Webhook.ProxyURL != "" {

modules/webhook/type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const (
114114
MATRIX HookType = "matrix"
115115
WECHATWORK HookType = "wechatwork"
116116
PACKAGIST HookType = "packagist"
117+
BARK HookType = "bark"
117118
)
118119

119120
// HookStatus is the status of a web hook

options/locale/locale_en-US.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,9 +2467,14 @@ settings.web_hook_name_feishu = Feishu
24672467
settings.web_hook_name_larksuite = Lark Suite
24682468
settings.web_hook_name_wechatwork = WeCom (Wechat Work)
24692469
settings.web_hook_name_packagist = Packagist
2470+
settings.web_hook_name_bark = Bark
24702471
settings.packagist_username = Packagist username
24712472
settings.packagist_api_token = API token
24722473
settings.packagist_package_url = Packagist package URL
2474+
settings.bark_url = Bark URL
2475+
settings.bark_url_help = Full Bark URL including device key (e.g., https://api.day.app/your_device_key/)
2476+
settings.bark_sound = Sound (optional)
2477+
settings.bark_group = Group (optional)
24732478
settings.deploy_keys = Deploy Keys
24742479
settings.add_deploy_key = Add Deploy Key
24752480
settings.deploy_key_desc = Deploy keys have read-only pull access to the repository.

options/locale/locale_zh-CN.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,9 +2465,14 @@ settings.web_hook_name_feishu=飞书
24652465
settings.web_hook_name_larksuite=Lark Suite
24662466
settings.web_hook_name_wechatwork=企业微信
24672467
settings.web_hook_name_packagist=Packagist
2468+
settings.web_hook_name_bark=Bark
24682469
settings.packagist_username=Packagist 用户名
24692470
settings.packagist_api_token=API 令牌
24702471
settings.packagist_package_url=Packagist 软件包 URL
2472+
settings.bark_url=Bark URL
2473+
settings.bark_url_help=完整的 Bark URL,包含设备密钥(例如:https://api.day.app/your_device_key/)
2474+
settings.bark_sound=提示音(可选)
2475+
settings.bark_group=分组(可选)
24712476
settings.deploy_keys=部署密钥
24722477
settings.add_deploy_key=添加部署密钥
24732478
settings.deploy_key_desc=部署密钥具有对仓库的只读拉取权限。

public/assets/img/bark.png

870 Bytes
Loading

routers/web/repo/setting/webhook.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,32 @@ func packagistHookParams(ctx *context.Context) webhookParams {
581581
}
582582
}
583583

584+
// BarkHooksNewPost response for creating Bark webhook
585+
func BarkHooksNewPost(ctx *context.Context) {
586+
createWebhook(ctx, barkHookParams(ctx))
587+
}
588+
589+
// BarkHooksEditPost response for editing Bark webhook
590+
func BarkHooksEditPost(ctx *context.Context) {
591+
editWebhook(ctx, barkHookParams(ctx))
592+
}
593+
594+
func barkHookParams(ctx *context.Context) webhookParams {
595+
form := web.GetForm(ctx).(*forms.NewBarkHookForm)
596+
597+
return webhookParams{
598+
Type: webhook_module.BARK,
599+
URL: form.PayloadURL,
600+
ContentType: webhook.ContentTypeJSON,
601+
HTTPMethod: http.MethodPost,
602+
WebhookForm: form.WebhookForm,
603+
Meta: &webhook_service.BarkMeta{
604+
Sound: form.Sound,
605+
Group: form.Group,
606+
},
607+
}
608+
}
609+
584610
func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
585611
orCtx, err := getOwnerRepoCtx(ctx)
586612
if err != nil {
@@ -619,6 +645,8 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
619645
ctx.Data["MatrixHook"] = webhook_service.GetMatrixHook(w)
620646
case webhook_module.PACKAGIST:
621647
ctx.Data["PackagistHook"] = webhook_service.GetPackagistHook(w)
648+
case webhook_module.BARK:
649+
ctx.Data["BarkHook"] = webhook_service.GetBarkHook(w)
622650
}
623651

624652
ctx.Data["History"], err = w.History(ctx, 1)

routers/web/web.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func registerWebRoutes(m *web.Router) {
434434
m.Post("/feishu/new", web.Bind(forms.NewFeishuHookForm{}), repo_setting.FeishuHooksNewPost)
435435
m.Post("/wechatwork/new", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksNewPost)
436436
m.Post("/packagist/new", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksNewPost)
437+
m.Post("/bark/new", web.Bind(forms.NewBarkHookForm{}), repo_setting.BarkHooksNewPost)
437438
}
438439

439440
addWebhookEditRoutes := func() {
@@ -448,6 +449,7 @@ func registerWebRoutes(m *web.Router) {
448449
m.Post("/feishu/{id}", web.Bind(forms.NewFeishuHookForm{}), repo_setting.FeishuHooksEditPost)
449450
m.Post("/wechatwork/{id}", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksEditPost)
450451
m.Post("/packagist/{id}", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksEditPost)
452+
m.Post("/bark/{id}", web.Bind(forms.NewBarkHookForm{}), repo_setting.BarkHooksEditPost)
451453
}
452454

453455
addSettingsVariablesRoutes := func() {

services/forms/repo_form.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors)
410410
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
411411
}
412412

413+
// NewBarkHookForm form for creating Bark hook
414+
type NewBarkHookForm struct {
415+
PayloadURL string `binding:"Required;ValidUrl" form:"payload_url"`
416+
Sound string `form:"sound"`
417+
Group string `form:"group"`
418+
WebhookForm
419+
}
420+
421+
// Validate validates the fields
422+
func (f *NewBarkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
423+
ctx := context.GetValidateContext(req)
424+
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
425+
}
426+
413427
// .___
414428
// | | ______ ________ __ ____
415429
// | |/ ___// ___/ | \_/ __ \

0 commit comments

Comments
 (0)