Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Add type column to project_hook table

天舟a247c7dc6330
diff --git a/api/project_hook.go b/api/project_hook.go
index 446bbe6602..545ee8e203 100644
--- a/api/project_hook.go
+++ b/api/project_hook.go
@@ -21,6 +21,7 @@ type ProjectHook struct {
ProjectId int `jsonapi:"attr,projecId"`
// Domain specific fields
+ Type string `jsonapi:"attr,type"`
Name string `jsonapi:"attr,name"`
URL string `jsonapi:"attr,url"`
ActivityList []string `jsonapi:"attr,activityList"`
@@ -35,6 +36,7 @@ type ProjectHookCreate struct {
ProjectId int
// Domain specific fields
+ Type string `jsonapi:"attr,type"`
Name string `jsonapi:"attr,name"`
URL string `jsonapi:"attr,url"`
ActivityList []string `jsonapi:"attr,activityList"`
@@ -64,9 +66,9 @@ type ProjectHookPatch struct {
UpdaterId int
// Domain specific fields
- Name *string `jsonapi:"attr,name"`
- URL *string `jsonapi:"attr,url"`
- ActivityList *[]string `jsonapi:"attr,activityList"`
+ Name *string `jsonapi:"attr,name"`
+ URL *string `jsonapi:"attr,url"`
+ ActivityList *string `jsonapi:"attr,activityList"`
}
type ProjectHookDelete struct {
diff --git a/plugin/webhook/dingtalk.go b/plugin/webhook/dingtalk.go
index fb26fbf8a3..b1b5e3a4f0 100644
--- a/plugin/webhook/dingtalk.go
+++ b/plugin/webhook/dingtalk.go
@@ -19,7 +19,7 @@ type DingTalkWebhook struct {
}
func init() {
- register("oapi.dingtalk.com", &DingTalkReceiver{})
+ register("bb.plugin.webhook.dingtalk", &DingTalkReceiver{})
}
type DingTalkReceiver struct {
diff --git a/plugin/webhook/discord.go b/plugin/webhook/discord.go
index 25959530ff..15a9c189a8 100644
--- a/plugin/webhook/discord.go
+++ b/plugin/webhook/discord.go
@@ -25,7 +25,7 @@ type DiscordWebhook struct {
}
func init() {
- register("discord.com", &DiscordReceiver{})
+ register("bb.plugin.webhook.discord", &DiscordReceiver{})
}
type DiscordReceiver struct {
diff --git a/plugin/webhook/feishu.go b/plugin/webhook/feishu.go
index 66ca3fa0cf..4226142dd5 100644
--- a/plugin/webhook/feishu.go
+++ b/plugin/webhook/feishu.go
@@ -36,7 +36,7 @@ type FeishuWebhook struct {
}
func init() {
- register("open.feishu.cn", &FeishuReceiver{})
+ register("bb.plugin.webhook.feishu", &FeishuReceiver{})
}
type FeishuReceiver struct {
diff --git a/plugin/webhook/slack.go b/plugin/webhook/slack.go
index 442a89fab1..7f7d0bd684 100644
--- a/plugin/webhook/slack.go
+++ b/plugin/webhook/slack.go
@@ -23,7 +23,7 @@ type SlackWebhook struct {
}
func init() {
- register("hooks.slack.com", &SlackReceiver{})
+ register("bb.plugin.webhook.slack", &SlackReceiver{})
}
type SlackReceiver struct {
diff --git a/plugin/webhook/teams.go b/plugin/webhook/teams.go
index 7d2a8b57ab..bb6961171d 100644
--- a/plugin/webhook/teams.go
+++ b/plugin/webhook/teams.go
@@ -41,7 +41,7 @@ type TeamsWebhook struct {
}
func init() {
- register("webhook.office.com", &TeamsReceiver{})
+ register("bb.plugin.webhook.teams", &TeamsReceiver{})
}
type TeamsReceiver struct {
diff --git a/plugin/webhook/webhook.go b/plugin/webhook/webhook.go
index f0f823a5e4..eddba00097 100644
--- a/plugin/webhook/webhook.go
+++ b/plugin/webhook/webhook.go
@@ -2,8 +2,6 @@ package webhook
import (
"fmt"
- "net/url"
- "strings"
"sync"
"time"
)
@@ -38,25 +36,12 @@ func register(host string, r WebhookReceiver) {
receivers[host] = r
}
-func Post(urlstr string, title string, description string, metaList []WebHookMeta, link string) error {
- u, err := url.Parse(urlstr)
- if err != nil {
- return fmt.Errorf("webhook: invalid url: %v", urlstr)
- }
-
+func Post(webhookType string, urlstr string, title string, description string, metaList []WebHookMeta, link string) error {
receiverMu.RLock()
- var r WebhookReceiver
- for key, value := range receivers {
- // Microsfot Teams webhook host is like https://xxx.webhook.office.com where xxx is the team.
- // So we use contains instead of exact match
- if strings.Contains(u.Host, key) {
- r = value
- break
- }
- }
+ r, ok := receivers[webhookType]
receiverMu.RUnlock()
- if r == nil {
- return fmt.Errorf("webhook: no applicable receiver for host: %v", u.Host)
+ if !ok {
+ return fmt.Errorf("webhook: no applicable receiver for webhook type: %v", webhookType)
}
return r.post(urlstr, title, description, metaList, link)
diff --git a/plugin/webhook/wecom.go b/plugin/webhook/wecom.go
index 35dbb0a897..089df2f945 100644
--- a/plugin/webhook/wecom.go
+++ b/plugin/webhook/wecom.go
@@ -18,7 +18,7 @@ type WeComWebhook struct {
}
func init() {
- register("qyapi.weixin.qq.com", &WeComReceiver{})
+ register("bb.plugin.webhook.wecom", &WeComReceiver{})
}
type WeComReceiver struct {
diff --git a/server/issue.go b/server/issue.go
index badc474968..3ee566f8ea 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -547,6 +547,7 @@ func (s *Server) ChangeIssueStatus(ctx context.Context, issue *api.Issue, newSta
}
err := webhook.Post(
+ hook.Type,
hook.URL,
title,
comment,
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 35d5a283ea..13e4afcb60 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -267,6 +267,7 @@ CREATE TABLE project_hook (
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
project_id INTEGER NOT NULL REFERENCES project (id),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.plugin.webhook.%'),
name TEXT NOT NULL,
url TEXT NOT NULL,
-- Comma separated list of activity triggers.
diff --git a/store/project_hook.go b/store/project_hook.go
index 176974babc..2c2ef040aa 100644
--- a/store/project_hook.go
+++ b/store/project_hook.go
@@ -132,16 +132,18 @@ func createProjectHook(ctx context.Context, tx *Tx, create *api.ProjectHookCreat
creator_id,
updater_id,
project_id,
+ type,
name,
url,
activity_list
)
- VALUES (?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, name, url, activity_list
+ VALUES (?, ?, ?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, type, name, url, activity_list
`,
create.CreatorId,
create.CreatorId,
create.ProjectId,
+ create.Type,
create.Name,
create.URL,
strings.Join(create.ActivityList, ","),
@@ -162,6 +164,7 @@ func createProjectHook(ctx context.Context, tx *Tx, create *api.ProjectHookCreat
&projectHook.UpdaterId,
&projectHook.UpdatedTs,
&projectHook.ProjectId,
+ &projectHook.Type,
&projectHook.Name,
&projectHook.URL,
&activityList,
@@ -191,6 +194,7 @@ func findProjectHookList(ctx context.Context, tx *Tx, find *api.ProjectHookFind)
updater_id,
updated_ts,
project_id,
+ type,
name,
url,
activity_list
@@ -215,6 +219,7 @@ func findProjectHookList(ctx context.Context, tx *Tx, find *api.ProjectHookFind)
&projectHook.UpdaterId,
&projectHook.UpdatedTs,
&projectHook.ProjectId,
+ &projectHook.Type,
&projectHook.Name,
&projectHook.URL,
&activityList,
@@ -252,8 +257,7 @@ func patchProjectHook(ctx context.Context, tx *Tx, patch *api.ProjectHookPatch)
set, args = append(set, "url = ?"), append(args, *v)
}
if v := patch.ActivityList; v != nil {
- activityList := strings.Join(*v, ",")
- set, args = append(set, "activity_list = ?"), append(args, activityList)
+ set, args = append(set, "activity_list = ?"), append(args, *v)
}
args = append(args, patch.ID)
@@ -263,7 +267,7 @@ func patchProjectHook(ctx context.Context, tx *Tx, patch *api.ProjectHookPatch)
UPDATE project_hook
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, name, url, activity_list
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, type, name, url, activity_list
`,
args...,
)
@@ -282,6 +286,7 @@ func patchProjectHook(ctx context.Context, tx *Tx, patch *api.ProjectHookPatch)
&projectHook.UpdaterId,
&projectHook.UpdatedTs,
&projectHook.ProjectId,
+ &projectHook.Type,
&projectHook.Name,
&projectHook.URL,
&activityList,