Skip to content

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

refactor: replace webhook string types with proto enums (#17790)

Danny Xu1d2460f524c0
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index e6504e1735..6df829ce87 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -476,7 +476,7 @@ func (s *IssueService) createIssueDatabaseChange(ctx context.Context, request *v
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueCreate,
+ Type: storepb.Activity_ISSUE_CREATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -566,7 +566,7 @@ func (s *IssueService) createIssueGrantRequest(ctx context.Context, request *v1p
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueCreate,
+ Type: storepb.Activity_ISSUE_CREATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -667,7 +667,7 @@ func (s *IssueService) createIssueDatabaseDataExport(ctx context.Context, reques
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueCreate,
+ Type: storepb.Activity_ISSUE_CREATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -798,7 +798,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, req *connect.Request[v1
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueApprovalCreate,
+ Type: storepb.Activity_ISSUE_APPROVAL_NOTIFY,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -816,7 +816,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, req *connect.Request[v1
// notify issue approved
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueApprovalPass,
+ Type: storepb.Activity_NOTIFY_ISSUE_APPROVED,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -843,7 +843,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, req *connect.Request[v1
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueRolloutReady,
+ Type: storepb.Activity_NOTIFY_PIPELINE_ROLLOUT,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -1045,7 +1045,7 @@ func (s *IssueService) RequestIssue(ctx context.Context, req *connect.Request[v1
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueApprovalCreate,
+ Type: storepb.Activity_ISSUE_APPROVAL_NOTIFY,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -1189,7 +1189,7 @@ func (s *IssueService) UpdateIssue(ctx context.Context, req *connect.Request[v1p
webhookEvents = append(webhookEvents, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueUpdate,
+ Type: storepb.Activity_ISSUE_FIELD_UPDATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -1220,7 +1220,7 @@ func (s *IssueService) UpdateIssue(ctx context.Context, req *connect.Request[v1p
webhookEvents = append(webhookEvents, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueUpdate,
+ Type: storepb.Activity_ISSUE_FIELD_UPDATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -1337,7 +1337,7 @@ func (s *IssueService) BatchUpdateIssuesStatus(ctx context.Context, req *connect
func() {
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueStatusUpdate,
+ Type: storepb.Activity_ISSUE_STATUS_UPDATE,
Comment: req.Msg.Reason,
Issue: webhook.NewIssue(updatedIssue),
Project: webhook.NewProject(updatedIssue.Project),
@@ -1433,7 +1433,7 @@ func (s *IssueService) CreateIssueComment(ctx context.Context, req *connect.Requ
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeIssueCommentCreate,
+ Type: storepb.Activity_ISSUE_COMMENT_CREATE,
Comment: req.Msg.IssueComment.Comment,
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index b346071f50..f6568de2b2 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -997,7 +997,7 @@ func (s *ProjectService) UpdateWebhook(ctx context.Context, req *connect.Request
case "url":
update.URL = &req.Msg.Webhook.Url
case "notification_type":
- types, err := convertToActivityTypeStrings(req.Msg.Webhook.NotificationTypes)
+ types, err := convertToStoreActivityTypes(req.Msg.Webhook.NotificationTypes)
if err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, err)
}
@@ -1006,7 +1006,7 @@ func (s *ProjectService) UpdateWebhook(ctx context.Context, req *connect.Request
}
update.Events = types
case "direct_message":
- update.Payload = &storepb.ProjectWebhookPayload{
+ update.Payload = &storepb.ProjectWebhook{
DirectMessage: req.Msg.Webhook.DirectMessage,
}
default:
@@ -1113,7 +1113,7 @@ func (s *ProjectService) TestWebhook(ctx context.Context, req *connect.Request[v
webhookplugin.Context{
URL: webhook.URL,
Level: webhookplugin.WebhookInfo,
- EventType: string(common.EventTypeIssueCreate),
+ EventType: storepb.Activity_ISSUE_CREATE.String(),
Title: fmt.Sprintf("Test webhook %q", webhook.Title),
TitleZh: fmt.Sprintf("测试 webhook %q", webhook.Title),
Description: "This is a test",
diff --git a/backend/api/v1/project_service_converter.go b/backend/api/v1/project_service_converter.go
index 8df0fa9cce..ed40c8329b 100644
--- a/backend/api/v1/project_service_converter.go
+++ b/backend/api/v1/project_service_converter.go
@@ -36,55 +36,55 @@ func convertToProtoAny(i any) (*anypb.Any, error) {
}
func convertToStoreProjectWebhookMessage(webhook *v1pb.Webhook) (*store.ProjectWebhookMessage, error) {
- tp, err := convertToAPIWebhookTypeString(webhook.Type)
+ storeType, err := convertToStoreWebhookType(webhook.Type)
if err != nil {
return nil, err
}
// Validate webhook URL against allowed domains
- if err := webhookplugin.ValidateWebhookURL(tp, webhook.Url); err != nil {
+ if err := webhookplugin.ValidateWebhookURL(storeType, webhook.Url); err != nil {
return nil, common.Errorf(common.Invalid, "invalid webhook URL: %v", err)
}
- activityTypes, err := convertToActivityTypeStrings(webhook.NotificationTypes)
+ activityTypes, err := convertToStoreActivityTypes(webhook.NotificationTypes)
if err != nil {
return nil, err
}
return &store.ProjectWebhookMessage{
- Type: tp,
+ Type: storeType,
URL: webhook.Url,
Title: webhook.Title,
Events: activityTypes,
- Payload: &storepb.ProjectWebhookPayload{
+ Payload: &storepb.ProjectWebhook{
DirectMessage: webhook.DirectMessage,
},
}, nil
}
-func convertToActivityTypeStrings(types []v1pb.Activity_Type) ([]string, error) {
- var result []string
+func convertToStoreActivityTypes(types []v1pb.Activity_Type) ([]storepb.Activity_Type, error) {
+ var result []storepb.Activity_Type
for _, tp := range types {
switch tp {
case v1pb.Activity_TYPE_UNSPECIFIED:
return nil, common.Errorf(common.Invalid, "activity type must not be unspecified")
case v1pb.Activity_ISSUE_CREATE:
- result = append(result, string(common.EventTypeIssueCreate))
+ result = append(result, storepb.Activity_ISSUE_CREATE)
case v1pb.Activity_ISSUE_COMMENT_CREATE:
- result = append(result, string(common.EventTypeIssueCommentCreate))
+ result = append(result, storepb.Activity_ISSUE_COMMENT_CREATE)
case v1pb.Activity_ISSUE_FIELD_UPDATE:
- result = append(result, string(common.EventTypeIssueUpdate))
+ result = append(result, storepb.Activity_ISSUE_FIELD_UPDATE)
case v1pb.Activity_ISSUE_STATUS_UPDATE:
- result = append(result, string(common.EventTypeIssueStatusUpdate))
+ result = append(result, storepb.Activity_ISSUE_STATUS_UPDATE)
case v1pb.Activity_ISSUE_APPROVAL_NOTIFY:
- result = append(result, string(common.EventTypeIssueApprovalCreate))
+ result = append(result, storepb.Activity_ISSUE_APPROVAL_NOTIFY)
case v1pb.Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE:
- result = append(result, string(common.EventTypeStageStatusUpdate))
+ result = append(result, storepb.Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE)
case v1pb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE:
- result = append(result, string(common.EventTypeTaskRunStatusUpdate))
+ result = append(result, storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE)
case v1pb.Activity_NOTIFY_ISSUE_APPROVED:
- result = append(result, string(common.EventTypeIssueApprovalPass))
+ result = append(result, storepb.Activity_NOTIFY_ISSUE_APPROVED)
case v1pb.Activity_NOTIFY_PIPELINE_ROLLOUT:
- result = append(result, string(common.EventTypeIssueRolloutReady))
+ result = append(result, storepb.Activity_NOTIFY_PIPELINE_ROLLOUT)
default:
return nil, common.Errorf(common.Invalid, "unsupported activity type: %v", tp)
}
@@ -92,27 +92,27 @@ func convertToActivityTypeStrings(types []v1pb.Activity_Type) ([]string, error)
return result, nil
}
-func convertNotificationTypeStrings(types []string) []v1pb.Activity_Type {
+func convertToV1ActivityTypes(types []storepb.Activity_Type) []v1pb.Activity_Type {
var result []v1pb.Activity_Type
for _, tp := range types {
switch tp {
- case string(common.EventTypeIssueCreate):
+ case storepb.Activity_ISSUE_CREATE:
result = append(result, v1pb.Activity_ISSUE_CREATE)
- case string(common.EventTypeIssueCommentCreate):
+ case storepb.Activity_ISSUE_COMMENT_CREATE:
result = append(result, v1pb.Activity_ISSUE_COMMENT_CREATE)
- case string(common.EventTypeIssueUpdate):
+ case storepb.Activity_ISSUE_FIELD_UPDATE:
result = append(result, v1pb.Activity_ISSUE_FIELD_UPDATE)
- case string(common.EventTypeIssueStatusUpdate):
+ case storepb.Activity_ISSUE_STATUS_UPDATE:
result = append(result, v1pb.Activity_ISSUE_STATUS_UPDATE)
- case string(common.EventTypeIssueApprovalCreate):
+ case storepb.Activity_ISSUE_APPROVAL_NOTIFY:
result = append(result, v1pb.Activity_ISSUE_APPROVAL_NOTIFY)
- case string(common.EventTypeStageStatusUpdate):
+ case storepb.Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE:
result = append(result, v1pb.Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE)
- case string(common.EventTypeTaskRunStatusUpdate):
+ case storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE:
result = append(result, v1pb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE)
- case string(common.EventTypeIssueApprovalPass):
+ case storepb.Activity_NOTIFY_ISSUE_APPROVED:
result = append(result, v1pb.Activity_NOTIFY_ISSUE_APPROVED)
- case string(common.EventTypeIssueRolloutReady):
+ case storepb.Activity_NOTIFY_PIPELINE_ROLLOUT:
result = append(result, v1pb.Activity_NOTIFY_PIPELINE_ROLLOUT)
default:
result = append(result, v1pb.Activity_TYPE_UNSPECIFIED)
@@ -121,45 +121,44 @@ func convertNotificationTypeStrings(types []string) []v1pb.Activity_Type {
return result
}
-func convertToAPIWebhookTypeString(tp v1pb.Webhook_Type) (string, error) {
+func convertToStoreWebhookType(tp v1pb.Webhook_Type) (storepb.ProjectWebhook_Type, error) {
switch tp {
case v1pb.Webhook_TYPE_UNSPECIFIED:
- return "", common.Errorf(common.Invalid, "webhook type must not be unspecified")
- // TODO(zp): find a better way to place the "bb.plugin.webhook.*".
+ return storepb.ProjectWebhook_TYPE_UNSPECIFIED, common.Errorf(common.Invalid, "webhook type must not be unspecified")
case v1pb.Webhook_SLACK:
- return "bb.plugin.webhook.slack", nil
+ return storepb.ProjectWebhook_SLACK, nil
case v1pb.Webhook_DISCORD:
- return "bb.plugin.webhook.discord", nil
+ return storepb.ProjectWebhook_DISCORD, nil
case v1pb.Webhook_TEAMS:
- return "bb.plugin.webhook.teams", nil
+ return storepb.ProjectWebhook_TEAMS, nil
case v1pb.Webhook_DINGTALK:
- return "bb.plugin.webhook.dingtalk", nil
+ return storepb.ProjectWebhook_DINGTALK, nil
case v1pb.Webhook_FEISHU:
- return "bb.plugin.webhook.feishu", nil
+ return storepb.ProjectWebhook_FEISHU, nil
case v1pb.Webhook_WECOM:
- return "bb.plugin.webhook.wecom", nil
+ return storepb.ProjectWebhook_WECOM, nil
case v1pb.Webhook_LARK:
- return "bb.plugin.webhook.lark", nil
+ return storepb.ProjectWebhook_LARK, nil
default:
- return "", common.Errorf(common.Invalid, "webhook type %q is not supported", tp)
+ return storepb.ProjectWebhook_TYPE_UNSPECIFIED, common.Errorf(common.Invalid, "webhook type %q is not supported", tp)
}
}
-func convertWebhookTypeString(tp string) v1pb.Webhook_Type {
+func convertToV1WebhookType(tp storepb.ProjectWebhook_Type) v1pb.Webhook_Type {
switch tp {
- case "bb.plugin.webhook.slack":
+ case storepb.ProjectWebhook_SLACK:
return v1pb.Webhook_SLACK
- case "bb.plugin.webhook.discord":
+ case storepb.ProjectWebhook_DISCORD:
return v1pb.Webhook_DISCORD
- case "bb.plugin.webhook.teams":
+ case storepb.ProjectWebhook_TEAMS:
return v1pb.Webhook_TEAMS
- case "bb.plugin.webhook.dingtalk":
+ case storepb.ProjectWebhook_DINGTALK:
return v1pb.Webhook_DINGTALK
- case "bb.plugin.webhook.feishu":
+ case storepb.ProjectWebhook_FEISHU:
return v1pb.Webhook_FEISHU
- case "bb.plugin.webhook.wecom":
+ case storepb.ProjectWebhook_WECOM:
return v1pb.Webhook_WECOM
- case "bb.plugin.webhook.lark":
+ case storepb.ProjectWebhook_LARK:
return v1pb.Webhook_LARK
default:
return v1pb.Webhook_TYPE_UNSPECIFIED
@@ -302,10 +301,10 @@ func convertToProject(projectMessage *store.ProjectMessage) *v1pb.Project {
for _, webhook := range projectMessage.Webhooks {
projectWebhooks = append(projectWebhooks, &v1pb.Webhook{
Name: fmt.Sprintf("%s/%s%d", common.FormatProject(projectMessage.ResourceID), common.WebhookIDPrefix, webhook.ID),
- Type: convertWebhookTypeString(webhook.Type),
+ Type: convertToV1WebhookType(webhook.Type),
Title: webhook.Title,
Url: webhook.URL,
- NotificationTypes: convertNotificationTypeStrings(webhook.Events),
+ NotificationTypes: convertToV1ActivityTypes(webhook.Events),
DirectMessage: webhook.Payload.GetDirectMessage(),
})
}
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 19afeaf4de..dab96c25ea 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -730,7 +730,7 @@ func (s *RolloutService) BatchRunTasks(ctx context.Context, req *connect.Request
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeTaskRunStatusUpdate,
+ Type: storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE,
Comment: request.Reason,
Issue: webhook.NewIssue(issueN),
Project: webhook.NewProject(project),
@@ -831,7 +831,7 @@ func (s *RolloutService) BatchSkipTasks(ctx context.Context, req *connect.Reques
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeTaskRunStatusUpdate,
+ Type: storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE,
Comment: request.Reason,
Issue: webhook.NewIssue(issueN),
Project: webhook.NewProject(project),
@@ -950,7 +950,7 @@ func (s *RolloutService) BatchCancelTaskRuns(ctx context.Context, req *connect.R
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: user,
- Type: common.EventTypeTaskRunStatusUpdate,
+ Type: storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE,
Comment: request.Reason,
Issue: webhook.NewIssue(issueN),
Rollout: webhook.NewRollout(rollout),
diff --git a/backend/common/const.go b/backend/common/const.go
index c44ce5616a..7b8df43f04 100644
--- a/backend/common/const.go
+++ b/backend/common/const.go
@@ -41,18 +41,3 @@ const (
// a prod instance after first signup, so it's safe to refer it.
DefaultProdEnvironmentID = "prod"
)
-
-type EventType string
-
-const (
- EventTypeIssueCreate = "bb.webhook.event.issue.create"
- EventTypeIssueUpdate = "bb.webhook.event.issue.update"
- EventTypeIssueStatusUpdate = "bb.webhook.event.issue.status.update"
- EventTypeIssueCommentCreate = "bb.webhook.event.issue.comment.create"
- EventTypeIssueApprovalCreate = "bb.webhook.event.issue.approval.create"
- EventTypeIssueApprovalPass = "bb.webhook.event.issue.approval.pass"
- EventTypeIssueRolloutReady = "bb.webhook.event.issue.rollout.ready"
-
- EventTypeStageStatusUpdate = "bb.webhook.event.stage.status.update"
- EventTypeTaskRunStatusUpdate = "bb.webhook.event.taskRun.status.update"
-)
diff --git a/backend/component/webhook/event.go b/backend/component/webhook/event.go
index 18c52d502a..7791f76b3a 100644
--- a/backend/component/webhook/event.go
+++ b/backend/component/webhook/event.go
@@ -1,14 +1,13 @@
package webhook
import (
- "github.com/bytebase/bytebase/backend/common"
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/store"
)
type Event struct {
Actor *store.UserMessage
- Type common.EventType
+ Type storepb.Activity_Type
Comment string
// nullable
Issue *Issue
diff --git a/backend/component/webhook/manager.go b/backend/component/webhook/manager.go
index f980911764..ec049ed3f2 100644
--- a/backend/component/webhook/manager.go
+++ b/backend/component/webhook/manager.go
@@ -66,7 +66,7 @@ func (m *Manager) CreateEvent(ctx context.Context, e *Event) {
go m.postWebhookList(ctx, webhookCtx, webhookList)
}
-func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, eventType common.EventType) (*webhook.Context, error) {
+func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, eventType storepb.Activity_Type) (*webhook.Context, error) {
var webhookCtx webhook.Context
var mentions []string
var mentionUsers []*store.UserMessage
@@ -87,11 +87,11 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
link = fmt.Sprintf("%s/projects/%s/rollouts/%d", setting.ExternalUrl, e.Project.ResourceID, e.Rollout.UID)
}
switch e.Type {
- case common.EventTypeIssueCreate:
+ case storepb.Activity_ISSUE_CREATE:
title = "Issue created"
titleZh = "创建工单"
- case common.EventTypeIssueStatusUpdate:
+ case storepb.Activity_ISSUE_STATUS_UPDATE:
switch e.Issue.Status {
case "OPEN":
title = "Issue reopened"
@@ -108,11 +108,11 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
titleZh = "工单状态变更"
}
- case common.EventTypeIssueCommentCreate:
+ case storepb.Activity_ISSUE_COMMENT_CREATE:
title = "Comment created"
titleZh = "工单新评论"
- case common.EventTypeIssueUpdate:
+ case storepb.Activity_ISSUE_FIELD_UPDATE:
update := e.IssueUpdate
switch update.Path {
case "description":
@@ -126,7 +126,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
titleZh = "工单信息变更"
}
- case common.EventTypeStageStatusUpdate:
+ case storepb.Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE:
u := e.StageStatusUpdate
if e.Issue != nil {
stageID := u.StageID
@@ -138,7 +138,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
title = "Stage ends"
titleZh = "阶段结束"
- case common.EventTypeTaskRunStatusUpdate:
+ case storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE:
u := e.TaskRunStatusUpdate
switch u.Status {
case storepb.TaskRun_PENDING.String():
@@ -166,7 +166,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
titleZh = "任务状态变更"
}
- case common.EventTypeIssueApprovalPass:
+ case storepb.Activity_NOTIFY_ISSUE_APPROVED:
title = "Issue approved"
titleZh = "工单审批通过"
@@ -178,7 +178,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
mentions = append(mentions, phone)
}
- case common.EventTypeIssueRolloutReady:
+ case storepb.Activity_NOTIFY_PIPELINE_ROLLOUT:
u := e.IssueRolloutReady
title = "Issue is waiting for rollout"
titleZh = "工单待发布"
@@ -222,7 +222,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
}
}
- case common.EventTypeIssueApprovalCreate:
+ case storepb.Activity_ISSUE_APPROVAL_NOTIFY:
roleWithPrefix := e.IssueApprovalCreate.Role
title = "Issue approval needed"
@@ -338,7 +338,7 @@ func (m *Manager) postWebhookList(ctx context.Context, webhookCtx *webhook.Conte
}); err != nil {
// The external webhook endpoint might be invalid which is out of our code control, so we just emit a warning
slog.Warn("Failed to post webhook event on activity",
- slog.String("webhook type", hook.Type),
+ slog.String("webhook type", hook.Type.String()),
slog.String("webhook name", hook.Title),
slog.String("activity type", webhookCtx.EventType),
slog.String("title", webhookCtx.Title),
@@ -398,10 +398,9 @@ func ChangeIssueStatus(ctx context.Context, stores *store.Store, webhookManager
return errors.Wrapf(err, "failed to update issue %q's status", issue.Title)
}
- // In the ChangeIssueStatus function
webhookManager.CreateEvent(ctx, &Event{
Actor: updater,
- Type: common.EventTypeIssueStatusUpdate,
+ Type: storepb.Activity_ISSUE_STATUS_UPDATE,
Comment: comment,
Issue: NewIssue(updatedIssue),
Project: NewProject(updatedIssue.Project),
diff --git a/backend/generated-go/store/project_webhook.pb.go b/backend/generated-go/store/project_webhook.pb.go
index 9c992173bf..04f2e04471 100644
--- a/backend/generated-go/store/project_webhook.pb.go
+++ b/backend/generated-go/store/project_webhook.pb.go
@@ -21,7 +21,201 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
-type ProjectWebhookPayload struct {
+// Activity type enumeration.
+type Activity_Type int32
+
+const (
+ // Unspecified type.
+ Activity_TYPE_UNSPECIFIED Activity_Type = 0
+ // Notifications via webhooks.
+ //
+ // NOTIFY_ISSUE_APPROVED represents the issue approved notification.
+ Activity_NOTIFY_ISSUE_APPROVED Activity_Type = 23
+ // NOTIFY_PIPELINE_ROLLOUT represents the pipeline rollout notification.
+ Activity_NOTIFY_PIPELINE_ROLLOUT Activity_Type = 24
+ // Issue related activity types.
+ //
+ // ISSUE_CREATE represents creating an issue.
+ Activity_ISSUE_CREATE Activity_Type = 1
+ // ISSUE_COMMENT_CREATE represents commenting on an issue.
+ Activity_ISSUE_COMMENT_CREATE Activity_Type = 2
+ // ISSUE_FIELD_UPDATE represents updating the issue field, likes title, description, etc.
+ Activity_ISSUE_FIELD_UPDATE Activity_Type = 3
+ // ISSUE_STATUS_UPDATE represents the issue status change, including OPEN, CLOSE, CANCEL for now.
+ Activity_ISSUE_STATUS_UPDATE Activity_Type = 4
+ // ISSUE_APPROVAL_NOTIFY is the type for notifying issue approval.
+ Activity_ISSUE_APPROVAL_NOTIFY Activity_Type = 21
+ // ISSUE_PIPELINE_STAGE_STATUS_UPDATE represents the pipeline stage status change, including BEGIN, END for now.
+ Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE Activity_Type = 5
+ // ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE represents the pipeline task run status change, including PENDING, RUNNING, DONE, FAILED, CANCELED.
+ Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE Activity_Type = 22
+)
+
+// Enum value maps for Activity_Type.
+var (
+ Activity_Type_name = map[int32]string{
+ 0: "TYPE_UNSPECIFIED",
+ 23: "NOTIFY_ISSUE_APPROVED",
+ 24: "NOTIFY_PIPELINE_ROLLOUT",
+ 1: "ISSUE_CREATE",
+ 2: "ISSUE_COMMENT_CREATE",
+ 3: "ISSUE_FIELD_UPDATE",
+ 4: "ISSUE_STATUS_UPDATE",
+ 21: "ISSUE_APPROVAL_NOTIFY",
+ 5: "ISSUE_PIPELINE_STAGE_STATUS_UPDATE",
+ 22: "ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE",
+ }
+ Activity_Type_value = map[string]int32{
+ "TYPE_UNSPECIFIED": 0,
+ "NOTIFY_ISSUE_APPROVED": 23,
+ "NOTIFY_PIPELINE_ROLLOUT": 24,
+ "ISSUE_CREATE": 1,
+ "ISSUE_COMMENT_CREATE": 2,
+ "ISSUE_FIELD_UPDATE": 3,
+ "ISSUE_STATUS_UPDATE": 4,
+ "ISSUE_APPROVAL_NOTIFY": 21,
+ "ISSUE_PIPELINE_STAGE_STATUS_UPDATE": 5,
+ "ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE": 22,
+ }
+)
+
+func (x Activity_Type) Enum() *Activity_Type {
+ p := new(Activity_Type)
+ *p = x
+ return p
+}
+
+func (x Activity_Type) String() string {
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
+}
+
+func (Activity_Type) Descriptor() protoreflect.EnumDescriptor {
+ return file_store_project_webhook_proto_enumTypes[0].Descriptor()
+}
+
+func (Activity_Type) Type() protoreflect.EnumType {
+ return &file_store_project_webhook_proto_enumTypes[0]
+}
+
+func (x Activity_Type) Number() protoreflect.EnumNumber {
+ return protoreflect.EnumNumber(x)
+}
+
+// Deprecated: Use Activity_Type.Descriptor instead.
+func (Activity_Type) EnumDescriptor() ([]byte, []int) {
+ return file_store_project_webhook_proto_rawDescGZIP(), []int{0, 0}
+}
+
+type ProjectWebhook_Type int32
+
+const (
+ // Unspecified type.
+ ProjectWebhook_TYPE_UNSPECIFIED ProjectWebhook_Type = 0
+ // Slack integration.
+ ProjectWebhook_SLACK ProjectWebhook_Type = 1
+ // Discord integration.
+ ProjectWebhook_DISCORD ProjectWebhook_Type = 2
+ // Microsoft Teams integration.
+ ProjectWebhook_TEAMS ProjectWebhook_Type = 3
+ // DingTalk integration.
+ ProjectWebhook_DINGTALK ProjectWebhook_Type = 4
+ // Feishu integration.
+ ProjectWebhook_FEISHU ProjectWebhook_Type = 5
+ // WeCom (WeChat Work) integration.
+ ProjectWebhook_WECOM ProjectWebhook_Type = 6
+ // Lark integration.
+ ProjectWebhook_LARK ProjectWebhook_Type = 8
+)
+
+// Enum value maps for ProjectWebhook_Type.
+var (
+ ProjectWebhook_Type_name = map[int32]string{
+ 0: "TYPE_UNSPECIFIED",
+ 1: "SLACK",
+ 2: "DISCORD",
+ 3: "TEAMS",
+ 4: "DINGTALK",
+ 5: "FEISHU",
+ 6: "WECOM",
+ 8: "LARK",
+ }
+ ProjectWebhook_Type_value = map[string]int32{
+ "TYPE_UNSPECIFIED": 0,
+ "SLACK": 1,
+ "DISCORD": 2,
+ "TEAMS": 3,
+ "DINGTALK": 4,
+ "FEISHU": 5,
+ "WECOM": 6,
+ "LARK": 8,
+ }
+)
+
+func (x ProjectWebhook_Type) Enum() *ProjectWebhook_Type {
+ p := new(ProjectWebhook_Type)
+ *p = x
+ return p
+}
+
+func (x ProjectWebhook_Type) String() string {
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
+}
+
+func (ProjectWebhook_Type) Descriptor() protoreflect.EnumDescriptor {
+ return file_store_project_webhook_proto_enumTypes[1].Descriptor()
+}
+
+func (ProjectWebhook_Type) Type() protoreflect.EnumType {
+ return &file_store_project_webhook_proto_enumTypes[1]
+}
+
+func (x ProjectWebhook_Type) Number() protoreflect.EnumNumber {
+ return protoreflect.EnumNumber(x)
+}
+
+// Deprecated: Use ProjectWebhook_Type.Descriptor instead.
+func (ProjectWebhook_Type) EnumDescriptor() ([]byte, []int) {
+ return file_store_project_webhook_proto_rawDescGZIP(), []int{1, 0}
+}
+
+// Activity types for webhook notifications.
+type Activity struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *Activity) Reset() {
+ *x = Activity{}
+ mi := &file_store_project_webhook_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *Activity) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*Activity) ProtoMessage() {}
+
+func (x *Activity) ProtoReflect() protoreflect.Message {
+ mi := &file_store_project_webhook_proto_msgTypes[0]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use Activity.ProtoReflect.Descriptor instead.
+func (*Activity) Descriptor() ([]byte, []int) {
+ return file_store_project_webhook_proto_rawDescGZIP(), []int{0}
+}
+
+type ProjectWebhook struct {
state protoimpl.MessageState `protogen:"open.v1"`
// If direct_message is set, the notification is sent directly
// to the persons and url will be ignored.
@@ -31,21 +225,21 @@ type ProjectWebhookPayload struct {
sizeCache protoimpl.SizeCache
}
-func (x *ProjectWebhookPayload) Reset() {
- *x = ProjectWebhookPayload{}
- mi := &file_store_project_webhook_proto_msgTypes[0]
+func (x *ProjectWebhook) Reset() {
+ *x = ProjectWebhook{}
+ mi := &file_store_project_webhook_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
-func (x *ProjectWebhookPayload) String() string {
+func (x *ProjectWebhook) String() string {
return protoimpl.X.MessageStringOf(x)
}
-func (*ProjectWebhookPayload) ProtoMessage() {}
+func (*ProjectWebhook) ProtoMessage() {}
-func (x *ProjectWebhookPayload) ProtoReflect() protoreflect.Message {
- mi := &file_store_project_webhook_proto_msgTypes[0]
+func (x *ProjectWebhook) ProtoReflect() protoreflect.Message {
+ mi := &file_store_project_webhook_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -56,12 +250,12 @@ func (x *ProjectWebhookPayload) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
-// Deprecated: Use ProjectWebhookPayload.ProtoReflect.Descriptor instead.
-func (*ProjectWebhookPayload) Descriptor() ([]byte, []int) {
- return file_store_project_webhook_proto_rawDescGZIP(), []int{0}
+// Deprecated: Use ProjectWebhook.ProtoReflect.Descriptor instead.
+func (*ProjectWebhook) Descriptor() ([]byte, []int) {
+ return file_store_project_webhook_proto_rawDescGZIP(), []int{1}
}
-func (x *ProjectWebhookPayload) GetDirectMessage() bool {
+func (x *ProjectWebhook) GetDirectMessage() bool {
if x != nil {
return x.DirectMessage
}
@@ -72,9 +266,31 @@ var File_store_project_webhook_proto protoreflect.FileDescriptor
const file_store_project_webhook_proto_rawDesc = "" +
"\n" +
- "\x1bstore/project_webhook.proto\x12\x0ebytebase.store\">\n" +
- "\x15ProjectWebhookPayload\x12%\n" +
- "\x0edirect_message\x18\x01 \x01(\bR\rdirectMessageB\x14Z\x12generated-go/storeb\x06proto3"
+ "\x1bstore/project_webhook.proto\x12\x0ebytebase.store\"\xac\x02\n" +
+ "\bActivity\"\x9f\x02\n" +
+ "\x04Type\x12\x14\n" +
+ "\x10TYPE_UNSPECIFIED\x10\x00\x12\x19\n" +
+ "\x15NOTIFY_ISSUE_APPROVED\x10\x17\x12\x1b\n" +
+ "\x17NOTIFY_PIPELINE_ROLLOUT\x10\x18\x12\x10\n" +
+ "\fISSUE_CREATE\x10\x01\x12\x18\n" +
+ "\x14ISSUE_COMMENT_CREATE\x10\x02\x12\x16\n" +
+ "\x12ISSUE_FIELD_UPDATE\x10\x03\x12\x17\n" +
+ "\x13ISSUE_STATUS_UPDATE\x10\x04\x12\x19\n" +
+ "\x15ISSUE_APPROVAL_NOTIFY\x10\x15\x12&\n" +
+ "\"ISSUE_PIPELINE_STAGE_STATUS_UPDATE\x10\x05\x12)\n" +
+ "%ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE\x10\x16\"\xa7\x01\n" +
+ "\x0eProjectWebhook\x12%\n" +
+ "\x0edirect_message\x18\x01 \x01(\bR\rdirectMessage\"n\n" +
+ "\x04Type\x12\x14\n" +
+ "\x10TYPE_UNSPECIFIED\x10\x00\x12\t\n" +
+ "\x05SLACK\x10\x01\x12\v\n" +
+ "\aDISCORD\x10\x02\x12\t\n" +
+ "\x05TEAMS\x10\x03\x12\f\n" +
+ "\bDINGTALK\x10\x04\x12\n" +
+ "\n" +
+ "\x06FEISHU\x10\x05\x12\t\n" +
+ "\x05WECOM\x10\x06\x12\b\n" +
+ "\x04LARK\x10\bB\x14Z\x12generated-go/storeb\x06proto3"
var (
file_store_project_webhook_proto_rawDescOnce sync.Once
@@ -88,9 +304,13 @@ func file_store_project_webhook_proto_rawDescGZIP() []byte {
return file_store_project_webhook_proto_rawDescData
}
-var file_store_project_webhook_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
+var file_store_project_webhook_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
+var file_store_project_webhook_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_store_project_webhook_proto_goTypes = []any{
- (*ProjectWebhookPayload)(nil), // 0: bytebase.store.ProjectWebhookPayload
+ (Activity_Type)(0), // 0: bytebase.store.Activity.Type
+ (ProjectWebhook_Type)(0), // 1: bytebase.store.ProjectWebhook.Type
+ (*Activity)(nil), // 2: bytebase.store.Activity
+ (*ProjectWebhook)(nil), // 3: bytebase.store.ProjectWebhook
}
var file_store_project_webhook_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
@@ -110,13 +330,14 @@ func file_store_project_webhook_proto_init() {
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_store_project_webhook_proto_rawDesc), len(file_store_project_webhook_proto_rawDesc)),
- NumEnums: 0,
- NumMessages: 1,
+ NumEnums: 2,
+ NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_store_project_webhook_proto_goTypes,
DependencyIndexes: file_store_project_webhook_proto_depIdxs,
+ EnumInfos: file_store_project_webhook_proto_enumTypes,
MessageInfos: file_store_project_webhook_proto_msgTypes,
}.Build()
File_store_project_webhook_proto = out.File
diff --git a/backend/generated-go/store/project_webhook_equal.pb.go b/backend/generated-go/store/project_webhook_equal.pb.go
index 79fba19c13..3d83186195 100644
--- a/backend/generated-go/store/project_webhook_equal.pb.go
+++ b/backend/generated-go/store/project_webhook_equal.pb.go
@@ -3,7 +3,17 @@
package store
-func (x *ProjectWebhookPayload) Equal(y *ProjectWebhookPayload) bool {
+func (x *Activity) Equal(y *Activity) bool {
+ if x == y {
+ return true
+ }
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
+ return true
+}
+
+func (x *ProjectWebhook) Equal(y *ProjectWebhook) bool {
if x == y {
return true
}
diff --git a/backend/generated-go/v1/project_service.pb.go b/backend/generated-go/v1/project_service.pb.go
index e0ed4374ef..6a03a6ef60 100644
--- a/backend/generated-go/v1/project_service.pb.go
+++ b/backend/generated-go/v1/project_service.pb.go
@@ -1476,12 +1476,15 @@ type Webhook struct {
// notification_types is the list of activities types that the webhook is interested in.
// Bytebase will only send notifications to the webhook if the activity type is in the list.
// It should not be empty, and should be a subset of the following:
- // - TYPE_ISSUE_CREATED
- // - TYPE_ISSUE_STATUS_UPDATE
- // - TYPE_ISSUE_PIPELINE_STAGE_UPDATE
- // - TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE
- // - TYPE_ISSUE_FIELD_UPDATE
- // - TYPE_ISSUE_COMMENT_CREATE
+ // - ISSUE_CREATE
+ // - ISSUE_COMMENT_CREATE
+ // - ISSUE_FIELD_UPDATE
+ // - ISSUE_STATUS_UPDATE
+ // - ISSUE_APPROVAL_NOTIFY
+ // - ISSUE_PIPELINE_STAGE_STATUS_UPDATE
+ // - ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE
+ // - NOTIFY_ISSUE_APPROVED
+ // - NOTIFY_PIPELINE_ROLLOUT
NotificationTypes []Activity_Type `protobuf:"varint,5,rep,packed,name=notification_types,json=notificationTypes,proto3,enum=bytebase.v1.Activity_Type" json:"notification_types,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -1560,7 +1563,6 @@ func (x *Webhook) GetNotificationTypes() []Activity_Type {
}
// Activity types for webhook notifications.
-// TODO(zp): move to activity later.
type Activity struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
diff --git a/backend/migrator/migration/3.11/0016##convert_webhook_enums.sql b/backend/migrator/migration/3.11/0016##convert_webhook_enums.sql
new file mode 100644
index 0000000000..c4b72443e9
--- /dev/null
+++ b/backend/migrator/migration/3.11/0016##convert_webhook_enums.sql
@@ -0,0 +1,33 @@
+-- Drop the old check constraint that enforces "bb.plugin.webhook.*" format
+ALTER TABLE project_webhook DROP CONSTRAINT IF EXISTS project_webhook_type_check;
+
+-- Convert webhook type from "bb.plugin.webhook.*" format to enum names
+UPDATE project_webhook SET type = 'SLACK' WHERE type = 'bb.plugin.webhook.slack';
+UPDATE project_webhook SET type = 'DISCORD' WHERE type = 'bb.plugin.webhook.discord';
+UPDATE project_webhook SET type = 'TEAMS' WHERE type = 'bb.plugin.webhook.teams';
+UPDATE project_webhook SET type = 'DINGTALK' WHERE type = 'bb.plugin.webhook.dingtalk';
+UPDATE project_webhook SET type = 'FEISHU' WHERE type = 'bb.plugin.webhook.feishu';
+UPDATE project_webhook SET type = 'WECOM' WHERE type = 'bb.plugin.webhook.wecom';
+UPDATE project_webhook SET type = 'LARK' WHERE type = 'bb.plugin.webhook.lark';
+
+-- Convert event_list from "bb.webhook.event.*" format to enum names
+UPDATE project_webhook
+SET event_list = ARRAY(
+ SELECT CASE event
+ WHEN 'bb.webhook.event.issue.create' THEN 'ISSUE_CREATE'
+ WHEN 'bb.webhook.event.issue.comment.create' THEN 'ISSUE_COMMENT_CREATE'
+ WHEN 'bb.webhook.event.issue.update' THEN 'ISSUE_FIELD_UPDATE'
+ WHEN 'bb.webhook.event.issue.status.update' THEN 'ISSUE_STATUS_UPDATE'
+ WHEN 'bb.webhook.event.stage.status.update' THEN 'ISSUE_PIPELINE_STAGE_STATUS_UPDATE'
+ WHEN 'bb.webhook.event.issue.approval.create' THEN 'ISSUE_APPROVAL_NOTIFY'
+ WHEN 'bb.webhook.event.taskRun.status.update' THEN 'ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE'
+ WHEN 'bb.webhook.event.issue.approval.pass' THEN 'NOTIFY_ISSUE_APPROVED'
+ WHEN 'bb.webhook.event.issue.rollout.ready' THEN 'NOTIFY_PIPELINE_ROLLOUT'
+ ELSE event -- Keep unknown events as-is
+ END
+ FROM unnest(event_list) AS event
+)
+WHERE EXISTS (
+ SELECT 1 FROM unnest(event_list) AS event
+ WHERE event LIKE 'bb.webhook.event.%'
+);
diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sql
index bab6e838ce..a287aa2478 100644
--- a/backend/migrator/migration/LATEST.sql
+++ b/backend/migrator/migration/LATEST.sql
@@ -108,11 +108,13 @@ CREATE UNIQUE INDEX idx_project_unique_resource_id ON project(resource_id);
CREATE TABLE project_webhook (
id serial PRIMARY KEY,
project text NOT NULL REFERENCES project(resource_id),
- type text NOT NULL CHECK (type LIKE 'bb.plugin.webhook.%'),
+ -- Enum name from ProjectWebhook.Type (proto/store/store/project_webhook.proto)
+ type text NOT NULL,
name text NOT NULL,
url text NOT NULL,
+ -- Array of enum names from Activity.Type (proto/store/store/project_webhook.proto)
event_list text ARRAY NOT NULL,
- -- Stored as ProjectWebhookPayload (proto/store/store/project_webhook.proto)
+ -- Stored as ProjectWebhook (proto/store/store/project_webhook.proto)
payload jsonb NOT NULL DEFAULT '{}'
);
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index b194b155aa..7bcd704281 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -12,7 +12,7 @@ import (
func TestLatestVersion(t *testing.T) {
files, err := getSortedVersionedFiles()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.11.15"), *files[len(files)-1].version)
+ require.Equal(t, semver.MustParse("3.11.16"), *files[len(files)-1].version)
}
func TestVersionUnique(t *testing.T) {
diff --git a/backend/plugin/webhook/dingtalk/dingtalk.go b/backend/plugin/webhook/dingtalk/dingtalk.go
index 937af2e8a3..327281f24b 100644
--- a/backend/plugin/webhook/dingtalk/dingtalk.go
+++ b/backend/plugin/webhook/dingtalk/dingtalk.go
@@ -16,6 +16,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/webhook"
)
@@ -45,7 +46,7 @@ type Message struct {
}
func init() {
- webhook.Register("bb.plugin.webhook.dingtalk", &Receiver{})
+ webhook.Register(storepb.ProjectWebhook_DINGTALK, &Receiver{})
}
// Receiver is the receiver for DingTalk.
diff --git a/backend/plugin/webhook/discord.go b/backend/plugin/webhook/discord.go
index 04da9424a5..f1f608ac41 100644
--- a/backend/plugin/webhook/discord.go
+++ b/backend/plugin/webhook/discord.go
@@ -8,6 +8,8 @@ import (
"net/http"
"github.com/pkg/errors"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
)
// DiscordWebhookResponse is the API message for Discord webhook response.
@@ -44,7 +46,7 @@ type DiscordWebhook struct {
}
func init() {
- Register("bb.plugin.webhook.discord", &DiscordReceiver{})
+ Register(storepb.ProjectWebhook_DISCORD, &DiscordReceiver{})
}
// DiscordReceiver is the receiver for Discord.
diff --git a/backend/plugin/webhook/feishu/feishu.go b/backend/plugin/webhook/feishu/feishu.go
index 3c5bbe2827..ccd66f94c0 100644
--- a/backend/plugin/webhook/feishu/feishu.go
+++ b/backend/plugin/webhook/feishu/feishu.go
@@ -15,6 +15,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/webhook"
)
@@ -95,7 +96,7 @@ type Webhook struct {
}
func init() {
- webhook.Register("bb.plugin.webhook.feishu", &feishuReceiver{})
+ webhook.Register(storepb.ProjectWebhook_FEISHU, &feishuReceiver{})
}
// feishuReceiver is the receiver for Feishu.
diff --git a/backend/plugin/webhook/lark/lark.go b/backend/plugin/webhook/lark/lark.go
index c90398c259..832bf3da7e 100644
--- a/backend/plugin/webhook/lark/lark.go
+++ b/backend/plugin/webhook/lark/lark.go
@@ -15,6 +15,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/webhook"
)
@@ -95,7 +96,7 @@ type Webhook struct {
}
func init() {
- webhook.Register("bb.plugin.webhook.lark", &larkReceiver{})
+ webhook.Register(storepb.ProjectWebhook_LARK, &larkReceiver{})
}
// larkReceiver is the receiver for Lark.
diff --git a/backend/plugin/webhook/slack/slack.go b/backend/plugin/webhook/slack/slack.go
index f804f6260c..455a8e9493 100644
--- a/backend/plugin/webhook/slack/slack.go
+++ b/backend/plugin/webhook/slack/slack.go
@@ -14,6 +14,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/webhook"
)
@@ -50,7 +51,7 @@ type MessagePayload struct {
}
func init() {
- webhook.Register("bb.plugin.webhook.slack", &Receiver{})
+ webhook.Register(storepb.ProjectWebhook_SLACK, &Receiver{})
}
// Receiver is the receiver for Slack.
diff --git a/backend/plugin/webhook/teams.go b/backend/plugin/webhook/teams.go
index cfdf909b61..174093a922 100644
--- a/backend/plugin/webhook/teams.go
+++ b/backend/plugin/webhook/teams.go
@@ -8,6 +8,8 @@ import (
"net/http"
"github.com/pkg/errors"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
)
var themeColor = "4f46e5"
@@ -51,7 +53,7 @@ type TeamsWebhook struct {
}
func init() {
- Register("bb.plugin.webhook.teams", &TeamsReceiver{})
+ Register(storepb.ProjectWebhook_TEAMS, &TeamsReceiver{})
}
// TeamsReceiver is the receiver for Teams.
diff --git a/backend/plugin/webhook/validator.go b/backend/plugin/webhook/validator.go
index 5a2099226f..d5ad3ceb98 100644
--- a/backend/plugin/webhook/validator.go
+++ b/backend/plugin/webhook/validator.go
@@ -5,45 +5,47 @@ import (
"strings"
"github.com/pkg/errors"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
)
var (
// AllowedDomains maps webhook types to their allowed domains.
- AllowedDomains = map[string][]string{
- "bb.plugin.webhook.slack": {
+ AllowedDomains = map[storepb.ProjectWebhook_Type][]string{
+ storepb.ProjectWebhook_SLACK: {
"hooks.slack.com",
"hooks.slack-gov.com",
},
- "bb.plugin.webhook.discord": {
+ storepb.ProjectWebhook_DISCORD: {
"discord.com",
"discordapp.com",
},
- "bb.plugin.webhook.teams": {
+ storepb.ProjectWebhook_TEAMS: {
".office.com", // Matches *.office.com
".office365.com", // Matches *.office365.com
},
- "bb.plugin.webhook.dingtalk": {
+ storepb.ProjectWebhook_DINGTALK: {
"oapi.dingtalk.com",
"api.dingtalk.com",
},
- "bb.plugin.webhook.feishu": {
+ storepb.ProjectWebhook_FEISHU: {
"open.feishu.cn",
},
- "bb.plugin.webhook.lark": {
+ storepb.ProjectWebhook_LARK: {
"open.larksuite.com",
},
- "bb.plugin.webhook.wecom": {
+ storepb.ProjectWebhook_WECOM: {
"qyapi.weixin.qq.com",
},
}
// TestOnlyAllowedDomains contains additional domains allowed for testing purposes only.
// This should only be modified in test files.
- TestOnlyAllowedDomains = map[string][]string{}
+ TestOnlyAllowedDomains = map[storepb.ProjectWebhook_Type][]string{}
)
// ValidateWebhookURL validates that the webhook URL matches the allowed domains for the webhook type.
-func ValidateWebhookURL(webhookType, webhookURL string) error {
+func ValidateWebhookURL(webhookType storepb.ProjectWebhook_Type, webhookURL string) error {
// Parse URL
u, err := url.Parse(webhookURL)
if err != nil {
diff --git a/backend/plugin/webhook/validator_test.go b/backend/plugin/webhook/validator_test.go
index 68fb2a8ddb..092f8c6522 100644
--- a/backend/plugin/webhook/validator_test.go
+++ b/backend/plugin/webhook/validator_test.go
@@ -2,171 +2,173 @@ package webhook
import (
"testing"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
)
func TestValidateWebhookURL(t *testing.T) {
tests := []struct {
name string
- webhookType string
+ webhookType storepb.ProjectWebhook_Type
webhookURL string
wantErr bool
}{
// Slack tests
{
name: "valid slack URL",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXX",
wantErr: false,
},
{
name: "valid slack-gov URL",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "https://hooks.slack-gov.com/services/T00000000/B00000000/XXXXXXXXXXXX",
wantErr: false,
},
{
name: "invalid slack domain",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "https://evil.com/hooks",
wantErr: true,
},
{
name: "slack SSRF attempt localhost",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "http://127.0.0.1:8080/",
wantErr: true,
},
{
name: "slack SSRF attempt private IP",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "http://192.168.1.1/",
wantErr: true,
},
// Discord tests
{
name: "valid discord URL",
- webhookType: "bb.plugin.webhook.discord",
+ webhookType: storepb.ProjectWebhook_DISCORD,
webhookURL: "https://discord.com/api/webhooks/123456789/abcdefg",
wantErr: false,
},
{
name: "valid discordapp URL (legacy)",
- webhookType: "bb.plugin.webhook.discord",
+ webhookType: storepb.ProjectWebhook_DISCORD,
webhookURL: "https://discordapp.com/api/webhooks/123456789/abcdefg",
wantErr: false,
},
{
name: "invalid discord domain",
- webhookType: "bb.plugin.webhook.discord",
+ webhookType: storepb.ProjectWebhook_DISCORD,
webhookURL: "https://evil-discord.com/api/webhooks/123456789/abcdefg",
wantErr: true,
},
// Teams tests
{
name: "valid teams office.com URL",
- webhookType: "bb.plugin.webhook.teams",
+ webhookType: storepb.ProjectWebhook_TEAMS,
webhookURL: "https://outlook.office.com/webhook/xxx",
wantErr: false,
},
{
name: "valid teams office365.com URL",
- webhookType: "bb.plugin.webhook.teams",
+ webhookType: storepb.ProjectWebhook_TEAMS,
webhookURL: "https://outlook.office365.com/webhook/xxx",
wantErr: false,
},
{
name: "valid teams subdomain",
- webhookType: "bb.plugin.webhook.teams",
+ webhookType: storepb.ProjectWebhook_TEAMS,
webhookURL: "https://example.office.com/webhook/xxx",
wantErr: false,
},
{
name: "invalid teams domain",
- webhookType: "bb.plugin.webhook.teams",
+ webhookType: storepb.ProjectWebhook_TEAMS,
webhookURL: "https://evil-office.com/webhook/xxx",
wantErr: true,
},
// DingTalk tests
{
name: "valid dingtalk oapi URL",
- webhookType: "bb.plugin.webhook.dingtalk",
+ webhookType: storepb.ProjectWebhook_DINGTALK,
webhookURL: "https://oapi.dingtalk.com/robot/send?access_token=xxx",
wantErr: false,
},
{
name: "valid dingtalk api URL",
- webhookType: "bb.plugin.webhook.dingtalk",
+ webhookType: storepb.ProjectWebhook_DINGTALK,
webhookURL: "https://api.dingtalk.com/robot/send?access_token=xxx",
wantErr: false,
},
{
name: "invalid dingtalk domain",
- webhookType: "bb.plugin.webhook.dingtalk",
+ webhookType: storepb.ProjectWebhook_DINGTALK,
webhookURL: "https://evil.dingtalk.com/robot/send",
wantErr: true,
},
// Feishu tests
{
name: "valid feishu URL",
- webhookType: "bb.plugin.webhook.feishu",
+ webhookType: storepb.ProjectWebhook_FEISHU,
webhookURL: "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
wantErr: false,
},
{
name: "invalid feishu domain",
- webhookType: "bb.plugin.webhook.feishu",
+ webhookType: storepb.ProjectWebhook_FEISHU,
webhookURL: "https://evil.feishu.cn/open-apis/bot/v2/hook/xxx",
wantErr: true,
},
// Lark tests
{
name: "valid lark URL",
- webhookType: "bb.plugin.webhook.lark",
+ webhookType: storepb.ProjectWebhook_LARK,
webhookURL: "https://open.larksuite.com/open-apis/bot/v2/hook/xxx",
wantErr: false,
},
{
name: "invalid lark domain",
- webhookType: "bb.plugin.webhook.lark",
+ webhookType: storepb.ProjectWebhook_LARK,
webhookURL: "https://evil.larksuite.com/open-apis/bot/v2/hook/xxx",
wantErr: true,
},
// WeCom tests
{
name: "valid wecom URL",
- webhookType: "bb.plugin.webhook.wecom",
+ webhookType: storepb.ProjectWebhook_WECOM,
webhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx",
wantErr: false,
},
{
name: "invalid wecom domain",
- webhookType: "bb.plugin.webhook.wecom",
+ webhookType: storepb.ProjectWebhook_WECOM,
webhookURL: "https://evil.weixin.qq.com/cgi-bin/webhook/send?key=xxx",
wantErr: true,
},
// URL format tests
{
name: "invalid URL format",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "not-a-url",
wantErr: true,
},
{
name: "invalid scheme ftp",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "ftp://hooks.slack.com/services/xxx",
wantErr: true,
},
{
name: "invalid scheme file",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "file:///etc/passwd",
wantErr: true,
},
// Unknown webhook type
{
name: "unknown webhook type",
- webhookType: "bb.plugin.webhook.unknown",
+ webhookType: storepb.ProjectWebhook_TYPE_UNSPECIFIED,
webhookURL: "https://example.com/webhook",
wantErr: true,
},
@@ -186,25 +188,25 @@ func TestValidateWebhookURL_CaseInsensitive(t *testing.T) {
// Test that domain matching is case-insensitive
tests := []struct {
name string
- webhookType string
+ webhookType storepb.ProjectWebhook_Type
webhookURL string
wantErr bool
}{
{
name: "slack uppercase domain",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "https://HOOKS.SLACK.COM/services/xxx",
wantErr: false,
},
{
name: "slack mixed case domain",
- webhookType: "bb.plugin.webhook.slack",
+ webhookType: storepb.ProjectWebhook_SLACK,
webhookURL: "https://Hooks.Slack.Com/services/xxx",
wantErr: false,
},
{
name: "discord uppercase",
- webhookType: "bb.plugin.webhook.discord",
+ webhookType: storepb.ProjectWebhook_DISCORD,
webhookURL: "https://DISCORD.COM/api/webhooks/123/abc",
wantErr: false,
},
diff --git a/backend/plugin/webhook/webhook.go b/backend/plugin/webhook/webhook.go
index f1509fee18..82d2348ff1 100644
--- a/backend/plugin/webhook/webhook.go
+++ b/backend/plugin/webhook/webhook.go
@@ -16,7 +16,7 @@ import (
var (
receiverMu sync.RWMutex
- receivers = make(map[string]Receiver)
+ receivers = make(map[storepb.ProjectWebhook_Type]Receiver)
// Based on the local test, Teams sometimes cannot finish the request in 1 second, so use 3s.
Timeout = 3 * time.Second
)
@@ -247,23 +247,23 @@ func (c *Context) GetMetaListZh() []Meta {
return m
}
-// Register makes a receiver available by the url host
-// If Register is called twice with the same url host or if receiver is nil,
+// Register makes a receiver available by the webhook type
+// If Register is called twice with the same type or if receiver is nil,
// it panics.
-func Register(host string, r Receiver) {
+func Register(webhookType storepb.ProjectWebhook_Type, r Receiver) {
receiverMu.Lock()
defer receiverMu.Unlock()
if r == nil {
panic("webhook: Register receiver is nil")
}
- if _, dup := receivers[host]; dup {
- panic("webhook: Register called twice for host " + host)
+ if _, dup := receivers[webhookType]; dup {
+ panic("webhook: Register called twice for type " + webhookType.String())
}
- receivers[host] = r
+ receivers[webhookType] = r
}
// Post posts the message to webhook.
-func Post(webhookType string, context Context) error {
+func Post(webhookType storepb.ProjectWebhook_Type, context Context) error {
receiverMu.RLock()
r, ok := receivers[webhookType]
receiverMu.RUnlock()
diff --git a/backend/plugin/webhook/wecom/wecom.go b/backend/plugin/webhook/wecom/wecom.go
index 586e4baf85..1874f5af5f 100644
--- a/backend/plugin/webhook/wecom/wecom.go
+++ b/backend/plugin/webhook/wecom/wecom.go
@@ -16,6 +16,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/webhook"
)
@@ -37,7 +38,7 @@ type Webhook struct {
}
func init() {
- webhook.Register("bb.plugin.webhook.wecom", &Receiver{})
+ webhook.Register(storepb.ProjectWebhook_WECOM, &Receiver{})
}
// Receiver is the receiver for WeCom.
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index 084055e0ab..a2590e5710 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -230,7 +230,7 @@ func (r *Runner) findApprovalTemplateForIssue(ctx context.Context, issue *store.
}
r.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: r.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueRolloutReady,
+ Type: storepb.Activity_NOTIFY_PIPELINE_ROLLOUT,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
@@ -254,7 +254,7 @@ func (r *Runner) findApprovalTemplateForIssue(ctx context.Context, issue *store.
}
r.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: r.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueApprovalCreate,
+ Type: storepb.Activity_ISSUE_APPROVAL_NOTIFY,
Comment: "",
Issue: webhook.NewIssue(issue),
Project: webhook.NewProject(issue.Project),
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index 38f16cc609..232d89f2cf 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -267,7 +267,7 @@ func (s *SchedulerV2) scheduleAutoRolloutTask(ctx context.Context, taskUID int)
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeTaskRunStatusUpdate,
+ Type: storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Rollout: webhook.NewRollout(pipeline),
@@ -854,7 +854,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {
// create "stage ends" activity.
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeStageStatusUpdate,
+ Type: storepb.Activity_ISSUE_PIPELINE_STAGE_STATUS_UPDATE,
Comment: "",
Issue: webhook.NewIssue(issueN),
Rollout: webhook.NewRollout(pipeline),
@@ -896,7 +896,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueRolloutReady,
+ Type: storepb.Activity_NOTIFY_PIPELINE_ROLLOUT,
Comment: "",
Issue: webhook.NewIssue(issueN),
Project: webhook.NewProject(project),
@@ -942,7 +942,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeIssueStatusUpdate,
+ Type: storepb.Activity_ISSUE_STATUS_UPDATE,
Comment: "",
Issue: webhook.NewIssue(updatedIssue),
Project: webhook.NewProject(project),
@@ -987,7 +987,7 @@ func (s *SchedulerV2) createActivityForTaskRunStatusUpdate(ctx context.Context,
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
Actor: s.store.GetSystemBotUser(ctx),
- Type: common.EventTypeTaskRunStatusUpdate,
+ Type: storepb.Activity_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE,
Comment: "",
Issue: webhook.NewIssue(issue),
Rollout: webhook.NewRollout(rollout),
diff --git a/backend/store/project_webhook.go b/backend/store/project_webhook.go
index d5b7e71b77..acf736102c 100644
--- a/backend/store/project_webhook.go
+++ b/backend/store/project_webhook.go
@@ -17,19 +17,19 @@ import (
// ProjectWebhookMessage is the store model for an project webhook.
type ProjectWebhookMessage struct {
// Type is the webhook type (e.g. SLACK, DISCORD, etc.).
- Type string
+ Type storepb.ProjectWebhook_Type
// Title is the webhook name.
Title string
// URL is the webhook URL.
URL string
// Events is the list of activities that the webhook is interested in.
- Events []string
+ Events []storepb.Activity_Type
// Output only fields.
//
// ID is the unique identifier of the project webhook.
ID int
ProjectID string
- Payload *storepb.ProjectWebhookPayload
+ Payload *storepb.ProjectWebhook
}
// UpdateProjectWebhookMessage is the message for updating project webhooks.
@@ -39,8 +39,8 @@ type UpdateProjectWebhookMessage struct {
// URL is the webhook URL.
URL *string
// Events is the list of activities that the webhook is interested in.
- Events []string
- Payload *storepb.ProjectWebhookPayload
+ Events []storepb.Activity_Type
+ Payload *storepb.ProjectWebhook
}
// FindProjectWebhookMessage is the message for finding project webhooks,
@@ -49,7 +49,7 @@ type FindProjectWebhookMessage struct {
ID *int
ProjectID *string
URL *string
- EventType *common.EventType
+ EventType *storepb.Activity_Type
}
// CreateProjectWebhookV2 creates an instance of ProjectWebhook.
@@ -75,6 +75,12 @@ func (s *Store) CreateProjectWebhookV2(ctx context.Context, projectID string, cr
payload = p
}
+ // Convert events to string array (enum names)
+ events := make([]string, len(create.Events))
+ for i, event := range create.Events {
+ events[i] = event.String()
+ }
+
projectWebhook := ProjectWebhookMessage{
Type: create.Type,
Title: create.Title,
@@ -91,10 +97,10 @@ func (s *Store) CreateProjectWebhookV2(ctx context.Context, projectID string, cr
if err := tx.QueryRowContext(ctx, query,
projectID,
- create.Type,
+ create.Type.String(),
create.Title,
create.URL,
- create.Events,
+ events,
payload,
).Scan(
&projectWebhook.ID,
@@ -170,7 +176,12 @@ func (s *Store) UpdateProjectWebhookV2(ctx context.Context, projectResourceID st
set, args = append(set, fmt.Sprintf("url = $%d", len(args)+1)), append(args, *v)
}
if v := update.Events; v != nil {
- set, args = append(set, fmt.Sprintf("event_list = $%d", len(args)+1)), append(args, v)
+ // Convert events to string array (enum names)
+ events := make([]string, len(v))
+ for i, event := range v {
+ events[i] = event.String()
+ }
+ set, args = append(set, fmt.Sprintf("event_list = $%d", len(args)+1)), append(args, events)
}
if v := update.Payload; v != nil {
p, err := protojson.Marshal(v)
@@ -183,9 +194,10 @@ func (s *Store) UpdateProjectWebhookV2(ctx context.Context, projectResourceID st
args = append(args, projectWebhookID)
projectWebhook := ProjectWebhookMessage{
- Payload: &storepb.ProjectWebhookPayload{},
+ Payload: &storepb.ProjectWebhook{},
}
var txtArray pgtype.TextArray
+ var webhookType string
var payload []byte
// Execute update query with RETURNING.
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
@@ -198,7 +210,7 @@ func (s *Store) UpdateProjectWebhookV2(ctx context.Context, projectResourceID st
).Scan(
&projectWebhook.ID,
&projectWebhook.ProjectID,
- &projectWebhook.Type,
+ &webhookType,
&projectWebhook.Title,
&projectWebhook.URL,
&txtArray,
@@ -209,9 +221,25 @@ func (s *Store) UpdateProjectWebhookV2(ctx context.Context, projectResourceID st
}
return nil, err
}
- if err := txtArray.AssignTo(&projectWebhook.Events); err != nil {
+ webhookTypeValue, ok := storepb.ProjectWebhook_Type_value[webhookType]
+ if !ok {
+ return nil, errors.Errorf("invalid webhook type in database: %s", webhookType)
+ }
+ projectWebhook.Type = storepb.ProjectWebhook_Type(webhookTypeValue)
+
+ var eventStrs []string
+ if err := txtArray.AssignTo(&eventStrs); err != nil {
return nil, err
}
+ projectWebhook.Events = make([]storepb.Activity_Type, len(eventStrs))
+ for i, eventStr := range eventStrs {
+ eventValue, ok := storepb.Activity_Type_value[eventStr]
+ if !ok {
+ return nil, errors.Errorf("invalid activity type in database: %s", eventStr)
+ }
+ projectWebhook.Events[i] = storepb.Activity_Type(eventValue)
+ }
+
if err := common.ProtojsonUnmarshaler.Unmarshal(payload, projectWebhook.Payload); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal")
}
@@ -276,14 +304,15 @@ func (*Store) findProjectWebhookImplV2(ctx context.Context, txn *sql.Tx, find *F
var projectWebhooks []*ProjectWebhookMessage
for rows.Next() {
projectWebhook := ProjectWebhookMessage{
- Payload: &storepb.ProjectWebhookPayload{},
+ Payload: &storepb.ProjectWebhook{},
}
var txtArray pgtype.TextArray
+ var webhookType string
var payload []byte
if err := rows.Scan(
&projectWebhook.ID,
- &projectWebhook.Type,
+ &webhookType,
&projectWebhook.Title,
&projectWebhook.URL,
&txtArray,
@@ -292,16 +321,32 @@ func (*Store) findProjectWebhookImplV2(ctx context.Context, txn *sql.Tx, find *F
return nil, err
}
- if err := txtArray.AssignTo(&projectWebhook.Events); err != nil {
+ webhookTypeValue, ok := storepb.ProjectWebhook_Type_value[webhookType]
+ if !ok {
+ return nil, errors.Errorf("invalid webhook type in database: %s", webhookType)
+ }
+ projectWebhook.Type = storepb.ProjectWebhook_Type(webhookTypeValue)
+
+ var eventStrs []string
+ if err := txtArray.AssignTo(&eventStrs); err != nil {
return nil, err
}
+ projectWebhook.Events = make([]storepb.Activity_Type, len(eventStrs))
+ for i, eventStr := range eventStrs {
+ eventValue, ok := storepb.Activity_Type_value[eventStr]
+ if !ok {
+ return nil, errors.Errorf("invalid activity type in database: %s", eventStr)
+ }
+ projectWebhook.Events[i] = storepb.Activity_Type(eventValue)
+ }
+
if err := common.ProtojsonUnmarshaler.Unmarshal(payload, projectWebhook.Payload); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal")
}
if v := find.EventType; v != nil {
for _, activity := range projectWebhook.Events {
- if common.EventType(activity) == *v {
+ if activity == *v {
projectWebhooks = append(projectWebhooks, &projectWebhook)
break
}
diff --git a/backend/tests/webhook_test.go b/backend/tests/webhook_test.go
index d9bdd41b1b..c033a6cd73 100644
--- a/backend/tests/webhook_test.go
+++ b/backend/tests/webhook_test.go
@@ -16,6 +16,7 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/require"
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
webhookplugin "github.com/bytebase/bytebase/backend/plugin/webhook"
)
@@ -101,10 +102,10 @@ func parseSlackWebhook(body []byte) (title, description string, err error) {
// TestWebhookIntegration tests webhook functionality.
func TestWebhookIntegration(t *testing.T) {
// Allow localhost for testing
- webhookplugin.TestOnlyAllowedDomains["bb.plugin.webhook.slack"] = []string{"127.0.0.1", "localhost", "[::1]"}
+ webhookplugin.TestOnlyAllowedDomains[storepb.ProjectWebhook_SLACK] = []string{"127.0.0.1", "localhost", "[::1]"}
defer func() {
// Clean up after test
- delete(webhookplugin.TestOnlyAllowedDomains, "bb.plugin.webhook.slack")
+ delete(webhookplugin.TestOnlyAllowedDomains, storepb.ProjectWebhook_SLACK)
}()
ctx := context.Background()
diff --git a/frontend/src/types/proto-es/v1/project_service_pb.d.ts b/frontend/src/types/proto-es/v1/project_service_pb.d.ts
index 3ae242fd80..fa010df760 100644
--- a/frontend/src/types/proto-es/v1/project_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/project_service_pb.d.ts
@@ -791,12 +791,15 @@ export declare type Webhook = Message<"bytebase.v1.Webhook"> & {
* notification_types is the list of activities types that the webhook is interested in.
* Bytebase will only send notifications to the webhook if the activity type is in the list.
* It should not be empty, and should be a subset of the following:
- * - TYPE_ISSUE_CREATED
- * - TYPE_ISSUE_STATUS_UPDATE
- * - TYPE_ISSUE_PIPELINE_STAGE_UPDATE
- * - TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE
- * - TYPE_ISSUE_FIELD_UPDATE
- * - TYPE_ISSUE_COMMENT_CREATE
+ * - ISSUE_CREATE
+ * - ISSUE_COMMENT_CREATE
+ * - ISSUE_FIELD_UPDATE
+ * - ISSUE_STATUS_UPDATE
+ * - ISSUE_APPROVAL_NOTIFY
+ * - ISSUE_PIPELINE_STAGE_STATUS_UPDATE
+ * - ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE
+ * - NOTIFY_ISSUE_APPROVED
+ * - NOTIFY_PIPELINE_ROLLOUT
*
* @generated from field: repeated bytebase.v1.Activity.Type notification_types = 5;
*/
@@ -879,7 +882,6 @@ export declare const Webhook_TypeSchema: GenEnum<Webhook_Type>;
/**
* Activity types for webhook notifications.
- * TODO(zp): move to activity later.
*
* @generated from message bytebase.v1.Activity
*/
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 0566285d04..67b0f9950e 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -15165,12 +15165,15 @@ components:
notification_types is the list of activities types that the webhook is interested in.
Bytebase will only send notifications to the webhook if the activity type is in the list.
It should not be empty, and should be a subset of the following:
- - TYPE_ISSUE_CREATED
- - TYPE_ISSUE_STATUS_UPDATE
- - TYPE_ISSUE_PIPELINE_STAGE_UPDATE
- - TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE
- - TYPE_ISSUE_FIELD_UPDATE
- - TYPE_ISSUE_COMMENT_CREATE
+ - ISSUE_CREATE
+ - ISSUE_COMMENT_CREATE
+ - ISSUE_FIELD_UPDATE
+ - ISSUE_STATUS_UPDATE
+ - ISSUE_APPROVAL_NOTIFY
+ - ISSUE_PIPELINE_STAGE_STATUS_UPDATE
+ - ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE
+ - NOTIFY_ISSUE_APPROVED
+ - NOTIFY_PIPELINE_ROLLOUT
Worksheet:
required:
- name
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index 2a78f67889..4663cf341f 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -234,7 +234,11 @@
- [Project.LabelsEntry](#bytebase-store-Project-LabelsEntry)
- [store/project_webhook.proto](#store_project_webhook-proto)
- - [ProjectWebhookPayload](#bytebase-store-ProjectWebhookPayload)
+ - [Activity](#bytebase-store-Activity)
+ - [ProjectWebhook](#bytebase-store-ProjectWebhook)
+
+ - [Activity.Type](#bytebase-store-Activity-Type)
+ - [ProjectWebhook.Type](#bytebase-store-ProjectWebhook-Type)
- [store/query_history.proto](#store_query_history-proto)
- [QueryHistoryPayload](#bytebase-store-QueryHistoryPayload)
@@ -3859,9 +3863,19 @@ ExecutionRetryPolicy defines retry behavior for failed task executions.
-<a name="bytebase-store-ProjectWebhookPayload"></a>
+<a name="bytebase-store-Activity"></a>
+
+### Activity
+Activity types for webhook notifications.
+
+
+
+
+
-### ProjectWebhookPayload
+<a name="bytebase-store-ProjectWebhook"></a>
+
+### ProjectWebhook
@@ -3875,6 +3889,48 @@ ExecutionRetryPolicy defines retry behavior for failed task executions.
+
+<a name="bytebase-store-Activity-Type"></a>
+
+### Activity.Type
+Activity type enumeration.
+
+| Name | Number | Description |
+| ---- | ------ | ----------- |
+| TYPE_UNSPECIFIED | 0 | Unspecified type. |
+| NOTIFY_ISSUE_APPROVED | 23 | Notifications via webhooks.
+
+NOTIFY_ISSUE_APPROVED represents the issue approved notification. |
+| NOTIFY_PIPELINE_ROLLOUT | 24 | NOTIFY_PIPELINE_ROLLOUT represents the pipeline rollout notification. |
+| ISSUE_CREATE | 1 | Issue related activity types.
+
+ISSUE_CREATE represents creating an issue. |
+| ISSUE_COMMENT_CREATE | 2 | ISSUE_COMMENT_CREATE represents commenting on an issue. |
+| ISSUE_FIELD_UPDATE | 3 | ISSUE_FIELD_UPDATE represents updating the issue field, likes title, description, etc. |
+| ISSUE_STATUS_UPDATE | 4 | ISSUE_STATUS_UPDATE represents the issue status change, including OPEN, CLOSE, CANCEL for now. |
+| ISSUE_APPROVAL_NOTIFY | 21 | ISSUE_APPROVAL_NOTIFY is the type for notifying issue approval. |
+| ISSUE_PIPELINE_STAGE_STATUS_UPDATE | 5 | ISSUE_PIPELINE_STAGE_STATUS_UPDATE represents the pipeline stage status change, including BEGIN, END for now. |
+| ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE | 22 | ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE represents the pipeline task run status change, including PENDING, RUNNING, DONE, FAILED, CANCELED. |
+
+
+
+<a name="bytebase-store-ProjectWebhook-Type"></a>
+
+### ProjectWebhook.Type
+
+
+| Name | Number | Description |
+| ---- | ------ | ----------- |
+| TYPE_UNSPECIFIED | 0 | Unspecified type. |
+| SLACK | 1 | Slack integration. |
+| DISCORD | 2 | Discord integration. |
+| TEAMS | 3 | Microsoft Teams integration. |
+| DINGTALK | 4 | DingTalk integration. |
+| FEISHU | 5 | Feishu integration. |
+| WECOM | 6 | WeCom (WeChat Work) integration. |
+| LARK | 8 | Lark integration. |
+
+
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index 97105865be..c51b7019f0 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -1100,9 +1100,21 @@
<ul>
<li>
- <a href="#bytebase.store.ProjectWebhookPayload"><span class="badge">M</span>ProjectWebhookPayload</a>
+ <a href="#bytebase.store.Activity"><span class="badge">M</span>Activity</a>
</li>
+ <li>
+ <a href="#bytebase.store.ProjectWebhook"><span class="badge">M</span>ProjectWebhook</a>
+ </li>
+
+
+ <li>
+ <a href="#bytebase.store.Activity.Type"><span class="badge">E</span>Activity.Type</a>
+ </li>
+
+ <li>
+ <a href="#bytebase.store.ProjectWebhook.Type"><span class="badge">E</span>ProjectWebhook.Type</a>
+ </li>
@@ -10491,7 +10503,14 @@ If enabled, issues cannot be created when SQL review finds errors. </p></td>
<p></p>
- <h3 id="bytebase.store.ProjectWebhookPayload">ProjectWebhookPayload</h3>
+ <h3 id="bytebase.store.Activity">Activity</h3>
+ <p>Activity types for webhook notifications.</p>
+
+
+
+
+
+ <h3 id="bytebase.store.ProjectWebhook">ProjectWebhook</h3>
<p></p>
@@ -10519,6 +10538,140 @@ IM integration setting should be set for this function to work. </p></td>
+ <h3 id="bytebase.store.Activity.Type">Activity.Type</h3>
+ <p>Activity type enumeration.</p>
+ <table class="enum-table">
+ <thead>
+ <tr><td>Name</td><td>Number</td><td>Description</td></tr>
+ </thead>
+ <tbody>
+
+ <tr>
+ <td>TYPE_UNSPECIFIED</td>
+ <td>0</td>
+ <td><p>Unspecified type.</p></td>
+ </tr>
+
+ <tr>
+ <td>NOTIFY_ISSUE_APPROVED</td>
+ <td>23</td>
+ <td><p>Notifications via webhooks.
+
+NOTIFY_ISSUE_APPROVED represents the issue approved notification.</p></td>
+ </tr>
+
+ <tr>
+ <td>NOTIFY_PIPELINE_ROLLOUT</td>
+ <td>24</td>
+ <td><p>NOTIFY_PIPELINE_ROLLOUT represents the pipeline rollout notification.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_CREATE</td>
+ <td>1</td>
+ <td><p>Issue related activity types.
+
+ISSUE_CREATE represents creating an issue.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_COMMENT_CREATE</td>
+ <td>2</td>
+ <td><p>ISSUE_COMMENT_CREATE represents commenting on an issue.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_FIELD_UPDATE</td>
+ <td>3</td>
+ <td><p>ISSUE_FIELD_UPDATE represents updating the issue field, likes title, description, etc.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_STATUS_UPDATE</td>
+ <td>4</td>
+ <td><p>ISSUE_STATUS_UPDATE represents the issue status change, including OPEN, CLOSE, CANCEL for now.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_APPROVAL_NOTIFY</td>
+ <td>21</td>
+ <td><p>ISSUE_APPROVAL_NOTIFY is the type for notifying issue approval.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_PIPELINE_STAGE_STATUS_UPDATE</td>
+ <td>5</td>
+ <td><p>ISSUE_PIPELINE_STAGE_STATUS_UPDATE represents the pipeline stage status change, including BEGIN, END for now.</p></td>
+ </tr>
+
+ <tr>
+ <td>ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE</td>
+ <td>22</td>
+ <td><p>ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE represents the pipeline task run status change, including PENDING, RUNNING, DONE, FAILED, CANCELED.</p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
+ <h3 id="bytebase.store.ProjectWebhook.Type">ProjectWebhook.Type</h3>
+ <p></p>
+ <table class="enum-table">
+ <thead>
+ <tr><td>Name</td><td>Number</td><td>Description</td></tr>
+ </thead>
+ <tbody>
+
+ <tr>
+ <td>TYPE_UNSPECIFIED</td>
+ <td>0</td>
+ <td><p>Unspecified type.</p></td>
+ </tr>
+
+ <tr>
+ <td>SLACK</td>
+ <td>1</td>
+ <td><p>Slack integration.</p></td>
+ </tr>
+
+ <tr>
+ <td>DISCORD</td>
+ <td>2</td>
+ <td><p>Discord integration.</p></td>
+ </tr>
+
+ <tr>
+ <td>TEAMS</td>
+ <td>3</td>
+ <td><p>Microsoft Teams integration.</p></td>
+ </tr>
+
+ <tr>
+ <td>DINGTALK</td>
+ <td>4</td>
+ <td><p>DingTalk integration.</p></td>
+ </tr>
+
+ <tr>
+ <td>FEISHU</td>
+ <td>5</td>
+ <td><p>Feishu integration.</p></td>
+ </tr>
+
+ <tr>
+ <td>WECOM</td>
+ <td>6</td>
+ <td><p>WeCom (WeChat Work) integration.</p></td>
+ </tr>
+
+ <tr>
+ <td>LARK</td>
+ <td>8</td>
+ <td><p>Lark integration.</p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 07c4940d0c..d892c1ffb0 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -8334,7 +8334,6 @@ PlanService manages deployment plans for database changes.
### Activity
Activity types for webhook notifications.
-TODO(zp): move to activity later.
@@ -8737,7 +8736,7 @@ The project&#39;s `name` field is used to identify the project to update. Format
| title | [string](#string) | | title is the title of the webhook. |
| url | [string](#string) | | url is the url of the webhook, should be unique within the project. |
| direct_message | [bool](#bool) | | if direct_message is set, the notification is sent directly to the persons and url will be ignored. IM integration setting should be set for this function to work. |
-| notification_types | [Activity.Type](#bytebase-v1-Activity-Type) | repeated | notification_types is the list of activities types that the webhook is interested in. Bytebase will only send notifications to the webhook if the activity type is in the list. It should not be empty, and should be a subset of the following: - TYPE_ISSUE_CREATED - TYPE_ISSUE_STATUS_UPDATE - TYPE_ISSUE_PIPELINE_STAGE_UPDATE - TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE - TYPE_ISSUE_FIELD_UPDATE - TYPE_ISSUE_COMMENT_CREATE |
+| notification_types | [Activity.Type](#bytebase-v1-Activity-Type) | repeated | notification_types is the list of activities types that the webhook is interested in. Bytebase will only send notifications to the webhook if the activity type is in the list. It should not be empty, and should be a subset of the following: - ISSUE_CREATE - ISSUE_COMMENT_CREATE - ISSUE_FIELD_UPDATE - ISSUE_STATUS_UPDATE - ISSUE_APPROVAL_NOTIFY - ISSUE_PIPELINE_STAGE_STATUS_UPDATE - ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE - NOTIFY_ISSUE_APPROVED - NOTIFY_PIPELINE_ROLLOUT |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index e661871da7..c4a999a455 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -23527,7 +23527,7 @@ Permissions required: bb.planCheckRuns.run</p></td>
<h3 id="bytebase.v1.Activity">Activity</h3>
- <p>Activity types for webhook notifications.</p><p>TODO(zp): move to activity later.</p>
+ <p>Activity types for webhook notifications.</p>
@@ -24473,12 +24473,15 @@ IM integration setting should be set for this function to work. </p></td>
<td><p>notification_types is the list of activities types that the webhook is interested in.
Bytebase will only send notifications to the webhook if the activity type is in the list.
It should not be empty, and should be a subset of the following:
-- TYPE_ISSUE_CREATED
-- TYPE_ISSUE_STATUS_UPDATE
-- TYPE_ISSUE_PIPELINE_STAGE_UPDATE
-- TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE
-- TYPE_ISSUE_FIELD_UPDATE
-- TYPE_ISSUE_COMMENT_CREATE </p></td>
+- ISSUE_CREATE
+- ISSUE_COMMENT_CREATE
+- ISSUE_FIELD_UPDATE
+- ISSUE_STATUS_UPDATE
+- ISSUE_APPROVAL_NOTIFY
+- ISSUE_PIPELINE_STAGE_STATUS_UPDATE
+- ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE
+- NOTIFY_ISSUE_APPROVED
+- NOTIFY_PIPELINE_ROLLOUT </p></td>
</tr>
</tbody>
diff --git a/proto/store/store/project_webhook.proto b/proto/store/store/project_webhook.proto
index 1c477c7dd7..01724842d2 100644
--- a/proto/store/store/project_webhook.proto
+++ b/proto/store/store/project_webhook.proto
@@ -4,7 +4,57 @@ package bytebase.store;
option go_package = "generated-go/store";
-message ProjectWebhookPayload {
+// Activity types for webhook notifications.
+message Activity {
+ // Activity type enumeration.
+ enum Type {
+ // Unspecified type.
+ TYPE_UNSPECIFIED = 0;
+ // Notifications via webhooks.
+ //
+ // NOTIFY_ISSUE_APPROVED represents the issue approved notification.
+ NOTIFY_ISSUE_APPROVED = 23;
+ // NOTIFY_PIPELINE_ROLLOUT represents the pipeline rollout notification.
+ NOTIFY_PIPELINE_ROLLOUT = 24;
+ // Issue related activity types.
+ //
+ // ISSUE_CREATE represents creating an issue.
+ ISSUE_CREATE = 1;
+ // ISSUE_COMMENT_CREATE represents commenting on an issue.
+ ISSUE_COMMENT_CREATE = 2;
+ // ISSUE_FIELD_UPDATE represents updating the issue field, likes title, description, etc.
+ ISSUE_FIELD_UPDATE = 3;
+ // ISSUE_STATUS_UPDATE represents the issue status change, including OPEN, CLOSE, CANCEL for now.
+ ISSUE_STATUS_UPDATE = 4;
+ // ISSUE_APPROVAL_NOTIFY is the type for notifying issue approval.
+ ISSUE_APPROVAL_NOTIFY = 21;
+ // ISSUE_PIPELINE_STAGE_STATUS_UPDATE represents the pipeline stage status change, including BEGIN, END for now.
+ ISSUE_PIPELINE_STAGE_STATUS_UPDATE = 5;
+ // ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE represents the pipeline task run status change, including PENDING, RUNNING, DONE, FAILED, CANCELED.
+ ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE = 22;
+ }
+}
+
+message ProjectWebhook {
+ enum Type {
+ // Unspecified type.
+ TYPE_UNSPECIFIED = 0;
+ // Slack integration.
+ SLACK = 1;
+ // Discord integration.
+ DISCORD = 2;
+ // Microsoft Teams integration.
+ TEAMS = 3;
+ // DingTalk integration.
+ DINGTALK = 4;
+ // Feishu integration.
+ FEISHU = 5;
+ // WeCom (WeChat Work) integration.
+ WECOM = 6;
+ // Lark integration.
+ LARK = 8;
+ }
+
// If direct_message is set, the notification is sent directly
// to the persons and url will be ignored.
// IM integration setting should be set for this function to work.
diff --git a/proto/v1/v1/project_service.proto b/proto/v1/v1/project_service.proto
index 8449e03d2f..d633d5a3f5 100644
--- a/proto/v1/v1/project_service.proto
+++ b/proto/v1/v1/project_service.proto
@@ -540,17 +540,19 @@ message Webhook {
// notification_types is the list of activities types that the webhook is interested in.
// Bytebase will only send notifications to the webhook if the activity type is in the list.
// It should not be empty, and should be a subset of the following:
- // - TYPE_ISSUE_CREATED
- // - TYPE_ISSUE_STATUS_UPDATE
- // - TYPE_ISSUE_PIPELINE_STAGE_UPDATE
- // - TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE
- // - TYPE_ISSUE_FIELD_UPDATE
- // - TYPE_ISSUE_COMMENT_CREATE
+ // - ISSUE_CREATE
+ // - ISSUE_COMMENT_CREATE
+ // - ISSUE_FIELD_UPDATE
+ // - ISSUE_STATUS_UPDATE
+ // - ISSUE_APPROVAL_NOTIFY
+ // - ISSUE_PIPELINE_STAGE_STATUS_UPDATE
+ // - ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE
+ // - NOTIFY_ISSUE_APPROVED
+ // - NOTIFY_PIPELINE_ROLLOUT
repeated Activity.Type notification_types = 5 [(google.api.field_behavior) = UNORDERED_LIST];
}
// Activity types for webhook notifications.
-// TODO(zp): move to activity later.
message Activity {
// Activity type enumeration.
enum Type {