Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: remove unnecessary activity types (#16264)
p0ny7f5a330190be
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.goindex 145957571b..06a1f54d04 100644--- a/backend/api/v1/project_service.go+++ b/backend/api/v1/project_service.go@@ -950,7 +950,7 @@ func (s *ProjectService) TestWebhook(ctx context.Context, request *v1pb.TestWebhwebhookplugin.Context{URL: webhook.URL,Level: webhookplugin.WebhookInfo,- ActivityType: string(base.ActivityIssueCreate),+ ActivityType: string(base.EventTypeIssueCreate),Title: fmt.Sprintf("Test webhook %q", webhook.Title),TitleZh: fmt.Sprintf("测试 webhook %q", webhook.Title),Description: "This is a test",@@ -1008,23 +1008,23 @@ func convertToActivityTypeStrings(types []v1pb.Activity_Type) ([]string, error)case v1pb.Activity_TYPE_UNSPECIFIED:return nil, common.Errorf(common.Invalid, "activity type must not be unspecified")case v1pb.Activity_TYPE_ISSUE_CREATE:- result = append(result, string(base.ActivityIssueCreate))+ result = append(result, string(base.EventTypeIssueCreate))case v1pb.Activity_TYPE_ISSUE_COMMENT_CREATE:- result = append(result, string(base.ActivityIssueCommentCreate))+ result = append(result, string(base.EventTypeIssueCommentCreate))case v1pb.Activity_TYPE_ISSUE_FIELD_UPDATE:- result = append(result, string(base.ActivityIssueFieldUpdate))+ result = append(result, string(base.EventTypeIssueUpdate))case v1pb.Activity_TYPE_ISSUE_STATUS_UPDATE:- result = append(result, string(base.ActivityIssueStatusUpdate))+ result = append(result, string(base.EventTypeIssueStatusUpdate))case v1pb.Activity_TYPE_ISSUE_APPROVAL_NOTIFY:- result = append(result, string(base.ActivityIssueApprovalNotify))+ result = append(result, string(base.EventTypeIssueApprovalCreate))case v1pb.Activity_TYPE_ISSUE_PIPELINE_STAGE_STATUS_UPDATE:- result = append(result, string(base.ActivityPipelineStageStatusUpdate))+ result = append(result, string(base.EventTypeStageStatusUpdate))case v1pb.Activity_TYPE_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE:- result = append(result, string(base.ActivityPipelineTaskRunStatusUpdate))+ result = append(result, string(base.EventTypeTaskRunStatusUpdate))case v1pb.Activity_TYPE_NOTIFY_ISSUE_APPROVED:- result = append(result, string(base.ActivityNotifyIssueApproved))+ result = append(result, string(base.EventTypeIssueApprovalPass))case v1pb.Activity_TYPE_NOTIFY_PIPELINE_ROLLOUT:- result = append(result, string(base.ActivityNotifyPipelineRollout))+ result = append(result, string(base.EventTypeIssueRolloutReady))default:return nil, common.Errorf(common.Invalid, "unsupported activity type: %v", tp)}@@ -1036,23 +1036,23 @@ func convertNotificationTypeStrings(types []string) []v1pb.Activity_Type {var result []v1pb.Activity_Typefor _, tp := range types {switch tp {- case string(base.ActivityIssueCreate):+ case string(base.EventTypeIssueCreate):result = append(result, v1pb.Activity_TYPE_ISSUE_CREATE)- case string(base.ActivityIssueCommentCreate):+ case string(base.EventTypeIssueCommentCreate):result = append(result, v1pb.Activity_TYPE_ISSUE_COMMENT_CREATE)- case string(base.ActivityIssueFieldUpdate):+ case string(base.EventTypeIssueUpdate):result = append(result, v1pb.Activity_TYPE_ISSUE_FIELD_UPDATE)- case string(base.ActivityIssueStatusUpdate):+ case string(base.EventTypeIssueStatusUpdate):result = append(result, v1pb.Activity_TYPE_ISSUE_STATUS_UPDATE)- case string(base.ActivityIssueApprovalNotify):+ case string(base.EventTypeIssueApprovalCreate):result = append(result, v1pb.Activity_TYPE_ISSUE_APPROVAL_NOTIFY)- case string(base.ActivityPipelineStageStatusUpdate):+ case string(base.EventTypeStageStatusUpdate):result = append(result, v1pb.Activity_TYPE_ISSUE_PIPELINE_STAGE_STATUS_UPDATE)- case string(base.ActivityPipelineTaskRunStatusUpdate):+ case string(base.EventTypeTaskRunStatusUpdate):result = append(result, v1pb.Activity_TYPE_ISSUE_PIPELINE_TASK_RUN_STATUS_UPDATE)- case string(base.ActivityNotifyIssueApproved):+ case string(base.EventTypeIssueApprovalPass):result = append(result, v1pb.Activity_TYPE_NOTIFY_ISSUE_APPROVED)- case string(base.ActivityNotifyPipelineRollout):+ case string(base.EventTypeIssueRolloutReady):result = append(result, v1pb.Activity_TYPE_NOTIFY_PIPELINE_ROLLOUT)default:result = append(result, v1pb.Activity_TYPE_UNSPECIFIED)diff --git a/backend/base/activity.go b/backend/base/activity.godeleted file mode 100644index acd7cb5cd4..0000000000--- a/backend/base/activity.go+++ /dev/null@@ -1,79 +0,0 @@-package base--// ActivityType is the type for an activity.-type ActivityType string--const (- // Notifications via webhooks.- // ActivityNotifyIssueApproved is the type for notifying the creator when the issue approval passes.- // Will not be stored. Only used for notification.- ActivityNotifyIssueApproved ActivityType = "bb.notify.issue.approved"- // ActivityPipelineRollout is the type for notifying releasers to rollout.- // Will not be stored. Only used for notification.- ActivityNotifyPipelineRollout ActivityType = "bb.notify.pipeline.rollout"-- // Issue related.-- // ActivityIssueCreate is the type for creating issues.- // Used for notification only.- ActivityIssueCreate ActivityType = "bb.issue.create"- // ActivityIssueCommentCreate is the type for creating issue comments.- // Used for notification only.- ActivityIssueCommentCreate ActivityType = "bb.issue.comment.create"- // ActivityIssueFieldUpdate is the type for updating issue fields.- // Used for notification only.- ActivityIssueFieldUpdate ActivityType = "bb.issue.field.update"- // ActivityIssueStatusUpdate is the type for updating issue status.- // Used for notification only.- ActivityIssueStatusUpdate ActivityType = "bb.issue.status.update"- // ActivityIssueApprovalNotify is the type for notifying issue approval.- // Used for notification only.- ActivityIssueApprovalNotify ActivityType = "bb.issue.approval.notify"- // ActivityPipelineStageStatusUpdate is the type for stage begins or ends.- // Used for notification only.- ActivityPipelineStageStatusUpdate ActivityType = "bb.pipeline.stage.status.update"- // ActivityPipelineTaskStatusUpdate is the type for updating pipeline task status.- // Deprecated: use `ActivityPipelineTaskRunStatusUpdate` instead.- ActivityPipelineTaskStatusUpdate ActivityType = "bb.pipeline.task.status.update"- // ActivityPipelineTaskRunStatusUpdate is the type for updating pipeline task run status.- // Used for notification only.- ActivityPipelineTaskRunStatusUpdate ActivityType = "bb.pipeline.taskrun.status.update"- // ActivityPipelineTaskStatementUpdate is the type for updating pipeline task SQL statement.- // Deprecated.- ActivityPipelineTaskStatementUpdate ActivityType = "bb.pipeline.task.statement.update"- // ActivityPipelineTaskEarliestAllowedTimeUpdate is the type for updating pipeline task the earliest allowed time.- // Deprecated.- ActivityPipelineTaskEarliestAllowedTimeUpdate ActivityType = "bb.pipeline.task.general.earliest-allowed-time.update"- // ActivityPipelineTaskStatementUpdate is the type for updating pipeline task SQL statement.- // Deprecated.- ActivityPipelineTaskPriorBackup ActivityType = "bb.pipeline.task.prior-backup"-- // Member related.-- // ActivityMemberCreate is the type for creating members.- ActivityMemberCreate ActivityType = "bb.member.create"- // ActivityMemberRoleUpdate is the type for updating member roles.- ActivityMemberRoleUpdate ActivityType = "bb.member.role.update"- // ActivityMemberActivate is the type for activating members.- ActivityMemberActivate ActivityType = "bb.member.activate"- // ActivityMemberDeactivate is the type for deactivating members.- ActivityMemberDeactivate ActivityType = "bb.member.deactivate"-- // Project related.-- // ActivityProjectRepositoryPush is the type for pushing repositories.- ActivityProjectRepositoryPush ActivityType = "bb.project.repository.push"- // ActivityProjectDatabaseTransfer is the type for transferring databases.- ActivityProjectDatabaseTransfer ActivityType = "bb.project.database.transfer"- // ActivityProjectMemberCreate is the type for creating project members.- ActivityProjectMemberCreate ActivityType = "bb.project.member.create"- // ActivityProjectMemberDelete is the type for deleting project members.- ActivityProjectMemberDelete ActivityType = "bb.project.member.delete"-- // SQL Editor related.-- // ActivitySQLQuery is the type for executing query.- ActivitySQLQuery ActivityType = "bb.sql.query"- // ActivitySQLExport is the type for exporting SQL.- ActivitySQLExport ActivityType = "bb.sql.export"-)diff --git a/backend/component/webhook/manager.go b/backend/component/webhook/manager.goindex bce50d4e7d..499a496ab9 100644--- a/backend/component/webhook/manager.go+++ b/backend/component/webhook/manager.go@@ -43,33 +43,9 @@ func NewManager(store *store.Store, iamManager *iam.Manager) *Manager {}func (m *Manager) CreateEvent(ctx context.Context, e *Event) {- var activityType base.ActivityType- //exhaustive:enforce- switch e.Type {- case base.EventTypeIssueCreate:- activityType = base.ActivityIssueCreate- case base.EventTypeIssueUpdate:- activityType = base.ActivityIssueFieldUpdate- case base.EventTypeIssueStatusUpdate:- activityType = base.ActivityIssueStatusUpdate- case base.EventTypeIssueCommentCreate:- activityType = base.ActivityIssueCommentCreate- case base.EventTypeIssueApprovalCreate:- activityType = base.ActivityIssueApprovalNotify- case base.EventTypeIssueApprovalPass:- activityType = base.ActivityNotifyIssueApproved- case base.EventTypeIssueRolloutReady:- activityType = base.ActivityNotifyPipelineRollout- case base.EventTypeStageStatusUpdate:- activityType = base.ActivityPipelineStageStatusUpdate- case base.EventTypeTaskRunStatusUpdate:- activityType = base.ActivityPipelineTaskRunStatusUpdate- default:- return- }webhookList, err := m.store.FindProjectWebhookV2(ctx, &store.FindProjectWebhookMessage{- ProjectID: &e.Project.ResourceID,- ActivityType: &activityType,+ ProjectID: &e.Project.ResourceID,+ EventType: &e.Type,})if err != nil {slog.Warn("failed to find project webhook", "issue_name", e.Issue.Title, log.BBError(err))@@ -80,7 +56,7 @@ func (m *Manager) CreateEvent(ctx context.Context, e *Event) {return}- webhookCtx, err := m.getWebhookContextFromEvent(ctx, e, activityType)+ webhookCtx, err := m.getWebhookContextFromEvent(ctx, e, e.Type)if err != nil {slog.Warn("failed to get webhook context",slog.String("issue_name", e.Issue.Title),@@ -91,7 +67,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, activityType base.ActivityType) (*webhook.Context, error) {+func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, eventType base.EventType) (*webhook.Context, error) {var webhookCtx webhook.Contextvar mentions []stringvar mentionUsers []*store.UserMessage@@ -296,7 +272,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, actiwebhookCtx = webhook.Context{Level: level,- ActivityType: string(activityType),+ ActivityType: string(eventType),Title: title,TitleZh: titleZh,Issue: nil,diff --git a/backend/migrator/migration/3.7/0009##migrate_webhook_activity_to_event_type.sql b/backend/migrator/migration/3.7/0009##migrate_webhook_activity_to_event_type.sqlnew file mode 100644index 0000000000..d643c45f09--- /dev/null+++ b/backend/migrator/migration/3.7/0009##migrate_webhook_activity_to_event_type.sql@@ -0,0 +1,28 @@+-- Migrate project_webhook.activity_list from base.ActivityXXX to base.EventTypeXXX+UPDATE project_webhook+SET activity_list = ARRAY(+ SELECT CASE+ WHEN unnest = 'bb.issue.create' THEN 'bb.webhook.event.issue.create'+ WHEN unnest = 'bb.issue.field.update' THEN 'bb.webhook.event.issue.update'+ WHEN unnest = 'bb.issue.status.update' THEN 'bb.webhook.event.issue.status.update'+ WHEN unnest = 'bb.issue.comment.create' THEN 'bb.webhook.event.issue.comment.create'+ WHEN unnest = 'bb.issue.approval.notify' THEN 'bb.webhook.event.issue.approval.create'+ WHEN unnest = 'bb.notify.issue.approved' THEN 'bb.webhook.event.issue.approval.pass'+ WHEN unnest = 'bb.notify.pipeline.rollout' THEN 'bb.webhook.event.issue.rollout.ready'+ WHEN unnest = 'bb.pipeline.stage.status.update' THEN 'bb.webhook.event.stage.status.update'+ WHEN unnest = 'bb.pipeline.taskrun.status.update' THEN 'bb.webhook.event.taskRun.status.update'+ ELSE unnest+ END+ FROM unnest(activity_list)+)+WHERE activity_list && ARRAY[+ 'bb.issue.create',+ 'bb.issue.field.update',+ 'bb.issue.status.update',+ 'bb.issue.comment.create',+ 'bb.issue.approval.notify',+ 'bb.notify.issue.approved',+ 'bb.notify.pipeline.rollout',+ 'bb.pipeline.stage.status.update',+ 'bb.pipeline.taskrun.status.update'+];\ No newline at end of filediff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex dffd2fdd37..b37f792948 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.7.8"), *files[len(files)-1].version)+ require.Equal(t, semver.MustParse("3.7.9"), *files[len(files)-1].version)}func TestVersionUnique(t *testing.T) {diff --git a/backend/store/project_webhook.go b/backend/store/project_webhook.goindex f5bec609f3..736d42ce1a 100644--- a/backend/store/project_webhook.go+++ b/backend/store/project_webhook.go@@ -47,10 +47,10 @@ type UpdateProjectWebhookMessage struct {// FindProjectWebhookMessage is the message for finding project webhooks,// if all fields are nil, it will list all project webhooks.type FindProjectWebhookMessage struct {- ID *int- ProjectID *string- URL *string- ActivityType *base.ActivityType+ ID *int+ ProjectID *string+ URL *string+ EventType *base.EventType}// CreateProjectWebhookV2 creates an instance of ProjectWebhook.@@ -300,9 +300,9 @@ func (*Store) findProjectWebhookImplV2(ctx context.Context, txn *sql.Tx, find *Freturn nil, errors.Wrapf(err, "failed to unmarshal")}- if v := find.ActivityType; v != nil {+ if v := find.EventType; v != nil {for _, activity := range projectWebhook.ActivityList {- if base.ActivityType(activity) == *v {+ if base.EventType(activity) == *v {projectWebhooks = append(projectWebhooks, &projectWebhook)break}