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: in IM webhook show mark-as-done task as skipped (#3969)
p0nyb4de4764749d
diff --git a/plugin/webhook/webhook.go b/plugin/webhook/webhook.goindex c46b7172d6..069c9ac76a 100644--- a/plugin/webhook/webhook.go+++ b/plugin/webhook/webhook.go@@ -48,10 +48,12 @@ type Issue struct {// TaskResult is the latest result of a task.// The `detail` field is only present if the status is TaskFailed.+// The `SkippedReason` field is only present if the task is skipped.type TaskResult struct {- Name string `json:"name"`- Status string `json:"status"`- Detail string `json:"detail"`+ Name string `json:"name"`+ Status string `json:"status"`+ Detail string `json:"detail"`+ SkippedReason string `json:"skippedReason"`}// Project object of project.@@ -122,6 +124,12 @@ func (c *Context) getMetaList() []meta {Value: common.TruncateStringWithDescription(c.TaskResult.Detail),})}+ if c.TaskResult.SkippedReason != "" {+ m = append(m, meta{+ Name: "Skipped Reason",+ Value: c.TaskResult.SkippedReason,+ })+ }}return mdiff --git a/server/component/activity/manager.go b/server/component/activity/manager.goindex ed78946d89..c5f1e15139 100644--- a/server/component/activity/manager.go+++ b/server/component/activity/manager.go@@ -13,6 +13,7 @@ import ("github.com/bytebase/bytebase/common/log""github.com/bytebase/bytebase/plugin/webhook""github.com/bytebase/bytebase/server/component/config"+ "github.com/bytebase/bytebase/server/utils""github.com/bytebase/bytebase/store""github.com/pkg/errors"@@ -333,6 +334,18 @@ func (m *Manager) getWebhookContext(ctx context.Context, activity *api.Activity,case api.TaskDone:level = webhook.WebhookSuccesstitle = "Task completed - " + task.Name++ skipped, skippedReason, err := utils.GetTaskSkippedAndReason(task)+ if err != nil {+ err := errors.Wrap(err, "failed to get skipped and skippedReason from the task")+ log.Warn(err.Error(), zap.String("task.Payload", task.Payload), zap.Error(err))+ return webhookCtx, err+ }+ if skipped {+ title = "Task skipped - " + task.Name+ webhookTaskResult.Status = "SKIPPED"+ webhookTaskResult.SkippedReason = skippedReason+ }case api.TaskFailed:level = webhook.WebhookErrortitle = "Task failed - " + task.Name@@ -352,7 +365,7 @@ func (m *Manager) getWebhookContext(ctx context.Context, activity *api.Activity,var result api.TaskRunResultPayloadif err := json.Unmarshal([]byte(task.TaskRunList[0].Result), &result); err != nil {- err := errors.Wrapf(err, "failed to unmarshal TaskRun Result")+ err := errors.Wrap(err, "failed to unmarshal TaskRun Result")log.Warn(err.Error(),zap.Any("TaskRun", task.TaskRunList[0]),zap.Error(err))diff --git a/server/utils/utils.go b/server/utils/utils.goindex ef6a9217e2..1c46ee4c29 100644--- a/server/utils/utils.go+++ b/server/utils/utils.go@@ -395,6 +395,18 @@ func GetTaskStatement(task *api.Task) (string, error) {return taskStatement.Statement, nil}+// GetTaskSkippedAndReason gets skipped and skippedReason from a task.+func GetTaskSkippedAndReason(task *api.Task) (bool, string, error) {+ var payload struct {+ Skipped bool `json:"skipped,omitempty"`+ SkippedReason string `json:"skippedReason,omitempty"`+ }+ if err := json.Unmarshal([]byte(task.Payload), &payload); err != nil {+ return false, "", err+ }+ return payload.Skipped, payload.SkippedReason, nil+}+// MergeTaskCreateLists merges a matrix of taskCreate and taskIndexDAG to a list of taskCreate and taskIndexDAG.// The index of returned taskIndexDAG list is set regarding the merged taskCreate.func MergeTaskCreateLists(taskCreateLists [][]api.TaskCreate, taskIndexDAGLists [][]api.TaskIndexDAG) ([]api.TaskCreate, []api.TaskIndexDAG, error) {