From b68d0022c92ad842c72202100df010f7ca6aea06 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Tue, 31 Dec 2024 15:44:46 +0800 Subject: [PATCH] show project display name in notification Signed-off-by: Patrick Zhao --- .../service/instantmessage/workflow_task.go | 22 +++++++++++++++---- .../common/service/webhooknotify/types.go | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/microservice/aslan/core/common/service/instantmessage/workflow_task.go b/pkg/microservice/aslan/core/common/service/instantmessage/workflow_task.go index 81afd01731..421858f628 100644 --- a/pkg/microservice/aslan/core/common/service/instantmessage/workflow_task.go +++ b/pkg/microservice/aslan/core/common/service/instantmessage/workflow_task.go @@ -35,6 +35,7 @@ import ( configbase "github.com/koderover/zadig/v2/pkg/config" "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" + templaterepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template" larkservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/lark" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/webhooknotify" "github.com/koderover/zadig/v2/pkg/setting" @@ -267,11 +268,18 @@ func (w *Service) getApproveNotificationContent(notify *models.NotifyCtl, task * WebHookType: notify.WebHookType, TotalTime: time.Now().Unix() - task.StartTime, } + + project, err := templaterepo.NewProductColl().Find(task.ProjectName) + if err != nil { + return "", "", nil, nil, fmt.Errorf("failed to find project %s, error: %v", task.ProjectName, err) + } + webhookNotify := &webhooknotify.WorkflowNotify{ TaskID: task.TaskID, WorkflowName: task.WorkflowName, WorkflowDisplayName: task.WorkflowDisplayName, ProjectName: task.ProjectName, + ProjectDisplayName: project.ProjectName, Status: task.Status, Remark: task.Remark, Error: task.Error, @@ -288,13 +296,13 @@ func (w *Service) getApproveNotificationContent(notify *models.NotifyCtl, task * mailTplTitle := "{{getIcon .Task.Status }}工作流 {{.Task.WorkflowDisplayName}} #{{.Task.TaskID}} 等待审批\n" tplBaseInfo := []string{"{{if eq .WebHookType \"dingding\"}}##### {{end}}**执行用户**:{{.Task.TaskCreator}} \n", - "{{if eq .WebHookType \"dingding\"}}##### {{end}}**项目名称**:{{.Task.ProjectName}} \n", + "{{if eq .WebHookType \"dingding\"}}##### {{end}}**项目名称**:{{.Task.ProjectDisplayName}} \n", "{{if eq .WebHookType \"dingding\"}}##### {{end}}**开始时间**:{{ getStartTime .Task.StartTime}} \n", "{{if eq .WebHookType \"dingding\"}}##### {{end}}**持续时间**:{{ getDuration .TotalTime}} \n", "{{if eq .WebHookType \"dingding\"}}##### {{end}}**备注**:{{.Task.Remark}} \n", } mailTplBaseInfo := []string{"执行用户:{{.Task.TaskCreator}} \n", - "项目名称:{{.Task.ProjectName}} \n", + "项目名称:{{.Task.ProjectDisplayName}} \n", "开始时间:{{ getStartTime .Task.StartTime}} \n", "持续时间:{{ getDuration .TotalTime}} \n", "备注:{{ .Task.Remark}} \n\n", @@ -390,11 +398,17 @@ func (w *Service) getNotificationContent(notify *models.NotifyCtl, task *models. workflowNotification.ScanningID = segs[len(segs)-1] } + project, err := templaterepo.NewProductColl().Find(task.ProjectName) + if err != nil { + return "", "", nil, nil, fmt.Errorf("failed to find project %s, error: %v", task.ProjectName, err) + } + webhookNotify := &webhooknotify.WorkflowNotify{ TaskID: task.TaskID, WorkflowName: task.WorkflowName, WorkflowDisplayName: task.WorkflowDisplayName, ProjectName: task.ProjectName, + ProjectDisplayName: project.ProjectName, Status: task.Status, Remark: task.Remark, Error: task.Error, @@ -412,13 +426,13 @@ func (w *Service) getNotificationContent(notify *models.NotifyCtl, task *models. mailTplTitle := "{{getIcon .Task.Status }} {{getTaskType .Task.Type}} {{.Task.WorkflowDisplayName}}#{{.Task.TaskID}} {{ taskStatus .Task.Status }}" tplBaseInfo := []string{"{{if eq .WebHookType \"dingding\"}}##### {{end}}**执行用户**:{{.Task.TaskCreator}} \n", - "{{if eq .WebHookType \"dingding\"}}##### {{end}}**项目名称**:{{.Task.ProjectName}} \n", + "{{if eq .WebHookType \"dingding\"}}##### {{end}}**项目名称**:{{.Task.ProjectDisplayName}} \n", "{{if eq .WebHookType \"dingding\"}}##### {{end}}**开始时间**:{{ getStartTime .Task.StartTime}} \n", "{{if eq .WebHookType \"dingding\"}}##### {{end}}**持续时间**:{{ getDuration .TotalTime}} \n", "{{if eq .WebHookType \"dingding\"}}##### {{end}}**备注**:{{.Task.Remark}} \n", } mailTplBaseInfo := []string{"执行用户:{{.Task.TaskCreator}} \n", - "项目名称:{{.Task.ProjectName}} \n", + "项目名称:{{.Task.ProjectDisplayName}} \n", "开始时间:{{ getStartTime .Task.StartTime}} \n", "持续时间:{{ getDuration .TotalTime}} \n", "备注:{{ .Task.Remark}} \n", diff --git a/pkg/microservice/aslan/core/common/service/webhooknotify/types.go b/pkg/microservice/aslan/core/common/service/webhooknotify/types.go index 7a618e97aa..4d425d53eb 100644 --- a/pkg/microservice/aslan/core/common/service/webhooknotify/types.go +++ b/pkg/microservice/aslan/core/common/service/webhooknotify/types.go @@ -51,6 +51,7 @@ type WebHookNotify struct { type WorkflowNotify struct { TaskID int64 `json:"task_id"` ProjectName string `json:"project_name"` + ProjectDisplayName string `json:"project_display_name"` WorkflowName string `json:"workflow_name"` WorkflowDisplayName string `json:"workflow_display_name"` Status config.Status `json:"status"`