Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: remove Meta field in webhook.Context (#1298)
h3n4lf98a5d0b6fe6
diff --git a/plugin/webhook/custom.go b/plugin/webhook/custom.goindex 43c98bcb34..77834e414d 100644--- a/plugin/webhook/custom.go+++ b/plugin/webhook/custom.go@@ -16,16 +16,16 @@ type CustomWebhookResponse struct {// CustomWebhookRequest is the API message for Custom webhook request.type CustomWebhookRequest struct {- Level Level `json:"level"`- ActivityType string `json:"activity_type"`- Title string `json:"title"`- Description string `json:"description"`- Link string `json:"link"`- CreatorID int `json:"creator_id"`- CreatorName string `json:"creator_name"`- CreatedTS int64 `json:"created_ts"`- Issue Issue `json:"issue"`- Project Project `json:"project"`+ Level Level `json:"level"`+ ActivityType string `json:"activity_type"`+ Title string `json:"title"`+ Description string `json:"description"`+ Link string `json:"link"`+ CreatorID int `json:"creator_id"`+ CreatorName string `json:"creator_name"`+ CreatedTS int64 `json:"created_ts"`+ Issue *Issue `json:"issue"`+ Project *Project `json:"project"`}func init() {@@ -85,7 +85,7 @@ func (receiver *CustomReceiver) post(context Context) error {}if webhookResponse.Code != 0 {- return fmt.Errorf("%s", webhookResponse.Message)+ return fmt.Errorf("receive error code sent by webhook server, code %d, msg: %s", webhookResponse.Code, webhookResponse.Message)}return nildiff --git a/plugin/webhook/dingtalk.go b/plugin/webhook/dingtalk.goindex 23efe1980b..6ca40d787b 100644--- a/plugin/webhook/dingtalk.go+++ b/plugin/webhook/dingtalk.go@@ -38,7 +38,7 @@ type DingTalkReceiver struct {func (receiver *DingTalkReceiver) post(context Context) error {metaStrList := []string{}- for _, meta := range context.MetaList {+ for _, meta := range context.getMetaList() {metaStrList = append(metaStrList, fmt.Sprintf("##### **%s:** %s", meta.Name, meta.Value))}metaStrList = append(metaStrList, fmt.Sprintf("##### **By:** %s (%s)", context.CreatorName, context.CreatorEmail))diff --git a/plugin/webhook/discord.go b/plugin/webhook/discord.goindex 25d9d5c25a..a60d961dce 100644--- a/plugin/webhook/discord.go+++ b/plugin/webhook/discord.go@@ -54,7 +54,7 @@ func (receiver *DiscordReceiver) post(context Context) error {embedList := []DiscordWebhookEmbed{}fieldList := []DiscordWebhookEmbedField{}- for _, meta := range context.MetaList {+ for _, meta := range context.getMetaList() {fieldList = append(fieldList, DiscordWebhookEmbedField(meta))}diff --git a/plugin/webhook/feishu.go b/plugin/webhook/feishu.goindex ae72be8fef..7503ca557f 100644--- a/plugin/webhook/feishu.go+++ b/plugin/webhook/feishu.go@@ -75,7 +75,7 @@ func (receiver *FeishuReceiver) post(context Context) error {contentList = append(contentList, sectionList)}- for _, meta := range context.MetaList {+ for _, meta := range context.getMetaList() {sectionList := []FeishuWebhookPostSection{}sectionList = append(sectionList, FeishuWebhookPostSection{Tag: "text",diff --git a/plugin/webhook/slack.go b/plugin/webhook/slack.goindex c3f0260649..d78bf656e6 100644--- a/plugin/webhook/slack.go+++ b/plugin/webhook/slack.go@@ -79,7 +79,7 @@ func (receiver *SlackReceiver) post(context Context) error {})}- for _, meta := range context.MetaList {+ for _, meta := range context.getMetaList() {blockList = append(blockList, SlackWebhookBlock{Type: "section",Text: &SlackWebhookBlockMarkdown{diff --git a/plugin/webhook/teams.go b/plugin/webhook/teams.goindex c2bbd0e837..7d4be14e53 100644--- a/plugin/webhook/teams.go+++ b/plugin/webhook/teams.go@@ -59,7 +59,7 @@ type TeamsReceiver struct {func (receiver *TeamsReceiver) post(context Context) error {factList := []TeamsWebhookSectionFact{}- for _, meta := range context.MetaList {+ for _, meta := range context.getMetaList() {factList = append(factList, TeamsWebhookSectionFact(meta))}diff --git a/plugin/webhook/webhook.go b/plugin/webhook/webhook.goindex 1c8bf6721d..0521984f1a 100644--- a/plugin/webhook/webhook.go+++ b/plugin/webhook/webhook.go@@ -14,8 +14,8 @@ var (timeFormat = "2006-01-02 15:04:05")-// Meta is the webhook metadata.-type Meta struct {+// meta is the webhook metadata.+type meta struct {Name stringValue string}@@ -61,9 +61,8 @@ type Context struct {CreatorName stringCreatorEmail stringCreatedTs int64- MetaList []Meta- Issue Issue- Project Project+ Issue *Issue+ Project *Project}// Receiver is the webhook receiver.@@ -71,6 +70,26 @@ type Receiver interface {post(context Context) error}+func (c *Context) getMetaList() []meta {+ m := []meta{}++ if c.Project != nil {+ m = append(m, meta{+ Name: "Project",+ Value: c.Project.Name,+ })+ }++ if c.Issue != nil {+ m = append(m, meta{+ Name: "Isuue",+ Value: c.Issue.Name,+ })+ }++ 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,// it panics.diff --git a/plugin/webhook/wecom.go b/plugin/webhook/wecom.goindex 91ed0c1779..7d9f3b0e69 100644--- a/plugin/webhook/wecom.go+++ b/plugin/webhook/wecom.go@@ -37,7 +37,7 @@ type WeComReceiver struct {func (receiver *WeComReceiver) post(context Context) error {metaStrList := []string{}- for _, meta := range context.MetaList {+ for _, meta := range context.getMetaList() {metaStrList = append(metaStrList, fmt.Sprintf("%s: <font color=\"comment\">%s</font>", meta.Name, meta.Value))}metaStrList = append(metaStrList, fmt.Sprintf("By: <font color=\"comment\">%s (%s)</font>", context.CreatorName, context.CreatorEmail))diff --git a/server/activity_manager.go b/server/activity_manager.goindex c1d524be03..a55028810f 100644--- a/server/activity_manager.go+++ b/server/activity_manager.go@@ -247,28 +247,18 @@ func (m *ActivityManager) getWebhookContext(ctx context.Context, activity *api.A}}- metaList := []webhook.Meta{- {- Name: "Issue",- Value: meta.issue.Name,- },- {- Name: "Project",- Value: meta.issue.Project.Name,- },- }webhookCtx = webhook.Context{Level: level,ActivityType: string(activity.Type),Title: title,- Issue: webhook.Issue{+ Issue: &webhook.Issue{ID: meta.issue.ID,Name: meta.issue.Name,Status: string(meta.issue.Status),Type: string(meta.issue.Type),Description: meta.issue.Description,},- Project: webhook.Project{+ Project: &webhook.Project{ID: meta.issue.ProjectID,Name: meta.issue.Project.Name,},@@ -277,7 +267,6 @@ func (m *ActivityManager) getWebhookContext(ctx context.Context, activity *api.ACreatorID: updater.ID,CreatorName: updater.Name,CreatorEmail: updater.Email,- MetaList: metaList,}return webhookCtx, nil}diff --git a/server/project_webhook.go b/server/project_webhook.goindex 63e1aba479..610fe68097 100644--- a/server/project_webhook.go+++ b/server/project_webhook.go@@ -198,13 +198,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {CreatorName: "Bytebase",CreatorEmail: "[email protected]",CreatedTs: time.Now().Unix(),- MetaList: []webhookPlugin.Meta{- {- Name: "Project",- Value: project.Name,- },- },- Project: webhookPlugin.Project{Name: project.Name},+ Project: &webhookPlugin.Project{Name: project.Name},},)