Skip to content
Open
2 changes: 1 addition & 1 deletion modules/setting/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func loadWebhookFrom(rootCfg ConfigProvider) {
Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
Webhook.AllowedHostList = sec.Key("ALLOWED_HOST_LIST").MustString("")
Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork", "packagist"}
Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork", "packagist", "bark"}
Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
Webhook.ProxyURL = sec.Key("PROXY_URL").MustString("")
if Webhook.ProxyURL != "" {
Expand Down
1 change: 1 addition & 0 deletions modules/webhook/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
MATRIX HookType = "matrix"
WECHATWORK HookType = "wechatwork"
PACKAGIST HookType = "packagist"
BARK HookType = "bark"
)

// HookStatus is the status of a web hook
Expand Down
5 changes: 5 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2467,9 +2467,14 @@ settings.web_hook_name_feishu = Feishu
settings.web_hook_name_larksuite = Lark Suite
settings.web_hook_name_wechatwork = WeCom (Wechat Work)
settings.web_hook_name_packagist = Packagist
settings.web_hook_name_bark = Bark
settings.packagist_username = Packagist username
settings.packagist_api_token = API token
settings.packagist_package_url = Packagist package URL
settings.bark_url = Bark URL
settings.bark_url_help = Full Bark URL including device key (e.g., https://api.day.app/your_device_key/)
settings.bark_sound = Sound (optional)
settings.bark_group = Group (optional)
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
5 changes: 5 additions & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2465,9 +2465,14 @@ settings.web_hook_name_feishu=飞书
settings.web_hook_name_larksuite=Lark Suite
settings.web_hook_name_wechatwork=企业微信
settings.web_hook_name_packagist=Packagist
settings.web_hook_name_bark=Bark
settings.packagist_username=Packagist 用户名
settings.packagist_api_token=API 令牌
settings.packagist_package_url=Packagist 软件包 URL
settings.bark_url=Bark URL
settings.bark_url_help=完整的 Bark URL,包含设备密钥(例如:https://api.day.app/your_device_key/)
settings.bark_sound=提示音(可选)
settings.bark_group=分组(可选)
settings.deploy_keys=部署密钥
settings.add_deploy_key=添加部署密钥
settings.deploy_key_desc=部署密钥具有对仓库的只读拉取权限。
Expand Down
Binary file added public/assets/img/bark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions routers/web/repo/setting/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,32 @@ func packagistHookParams(ctx *context.Context) webhookParams {
}
}

// BarkHooksNewPost response for creating Bark webhook
func BarkHooksNewPost(ctx *context.Context) {
createWebhook(ctx, barkHookParams(ctx))
}

// BarkHooksEditPost response for editing Bark webhook
func BarkHooksEditPost(ctx *context.Context) {
editWebhook(ctx, barkHookParams(ctx))
}

func barkHookParams(ctx *context.Context) webhookParams {
form := web.GetForm(ctx).(*forms.NewBarkHookForm)

return webhookParams{
Type: webhook_module.BARK,
URL: form.PayloadURL,
ContentType: webhook.ContentTypeJSON,
HTTPMethod: http.MethodPost,
WebhookForm: form.WebhookForm,
Meta: &webhook_service.BarkMeta{
Sound: form.Sound,
Group: form.Group,
},
}
}

func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
orCtx, err := getOwnerRepoCtx(ctx)
if err != nil {
Expand Down Expand Up @@ -619,6 +645,8 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
ctx.Data["MatrixHook"] = webhook_service.GetMatrixHook(w)
case webhook_module.PACKAGIST:
ctx.Data["PackagistHook"] = webhook_service.GetPackagistHook(w)
case webhook_module.BARK:
ctx.Data["BarkHook"] = webhook_service.GetBarkHook(w)
}

ctx.Data["History"], err = w.History(ctx, 1)
Expand Down
2 changes: 2 additions & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func registerWebRoutes(m *web.Router) {
m.Post("/feishu/new", web.Bind(forms.NewFeishuHookForm{}), repo_setting.FeishuHooksNewPost)
m.Post("/wechatwork/new", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksNewPost)
m.Post("/packagist/new", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksNewPost)
m.Post("/bark/new", web.Bind(forms.NewBarkHookForm{}), repo_setting.BarkHooksNewPost)
}

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

addSettingsVariablesRoutes := func() {
Expand Down
14 changes: 14 additions & 0 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@ func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors)
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

// NewBarkHookForm form for creating Bark hook
type NewBarkHookForm struct {
PayloadURL string `binding:"Required;ValidUrl" form:"payload_url"`
Sound string `form:"sound"`
Group string `form:"group"`
WebhookForm
}

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

// .___
// | | ______ ________ __ ____
// | |/ ___// ___/ | \_/ __ \
Expand Down
Loading