Skip to content

Commit

Permalink
show project display name in notification
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ committed Dec 31, 2024
1 parent c9a3ec7 commit b68d002
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit b68d002

Please sign in to comment.