From 132030bc04afca71075e4f7d6a63a8841c2ef86b Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Thu, 21 Jul 2022 17:18:43 +0800 Subject: [PATCH] #2479 update --- modules/auth/wechat/template.go | 7 ++----- modules/notification/wechat/wechat.go | 12 +++++++++--- modules/setting/setting.go | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/auth/wechat/template.go b/modules/auth/wechat/template.go index 7e5f7cd06..0620aa7b9 100644 --- a/modules/auth/wechat/template.go +++ b/modules/auth/wechat/template.go @@ -26,7 +26,7 @@ func GetJobOperateTypeFromCloudbrainStatus(cloudbrain *models.Cloudbrain) JobOpe return "" } -func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Cloudbrain, date time.Time) error { +func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Cloudbrain) error { defer func() { if err := recover(); err != nil { combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) @@ -42,9 +42,6 @@ func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Clou return nil } - if date.IsZero() { - date = time.Now() - } openId := models.GetUserWechatOpenId(cloudbrain.UserID) if openId == "" { return errors.New("Wechat openId not exist") @@ -53,7 +50,7 @@ func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Clou First: TemplateValue{Value: getCloudbrainTemplateTitle(operateType)}, Keyword1: TemplateValue{Value: cloudbrain.DisplayJobName}, Keyword2: TemplateValue{Value: getJobTypeDisplayName(cloudbrain.JobType)}, - Keyword3: TemplateValue{Value: date.Format("2006-01-02 15:04:05")}, + Keyword3: TemplateValue{Value: time.Unix(int64(cloudbrain.CreatedUnix), 0).Format("2006-01-02 15:04:05")}, Remark: TemplateValue{Value: getCloudbrainTemplateRemark(operateType)}, } req := TemplateMsgRequest{ diff --git a/modules/notification/wechat/wechat.go b/modules/notification/wechat/wechat.go index c995d9433..c20be8e9b 100644 --- a/modules/notification/wechat/wechat.go +++ b/modules/notification/wechat/wechat.go @@ -8,7 +8,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth/wechat" "code.gitea.io/gitea/modules/notification/base" - "time" + "code.gitea.io/gitea/modules/setting" ) type wechatNotifier struct { @@ -31,8 +31,14 @@ func (*wechatNotifier) NotifyChangeCloudbrainStatus(cloudbrain *models.Cloudbrai } switch operateType { case wechat.JobOperateTypeStart: - if cloudbrain.JobType == string(models.JobTypeDebug) { - go wechat.SendCloudbrainStartedMsg(operateType, *cloudbrain, time.Unix(int64(cloudbrain.StartTime), 0)) + if len(setting.CloudbrainStartedNotifyList) == 0 { + return + } + for _, v := range setting.CloudbrainStartedNotifyList { + if v == cloudbrain.JobType { + go wechat.SendCloudbrainStartedMsg(operateType, *cloudbrain) + return + } } } } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 35789c18b..609832e7e 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -584,6 +584,7 @@ var ( //wechat template msg config CloudbrainStartedTemplateId string + CloudbrainStartedNotifyList []string //nginx proxy PROXYURL string @@ -1444,6 +1445,7 @@ func NewContext() { TreePathOfAutoMsgReply = sec.Key("AUTO_REPLY_TREE_PATH").MustString("wechat/auto_reply.json") TreePathOfSubscribe = sec.Key("SUBSCRIBE_TREE_PATH").MustString("wechat/subscribe_reply.json") CloudbrainStartedTemplateId = sec.Key("CLOUDBRAIN_STARTED_TEMPLATE_ID").MustString("") + CloudbrainStartedNotifyList = strings.Split(sec.Key("CLOUDBRAIN_STARTED_NOTIFY_LIST").MustString("DEBUG"), ",") SetRadarMapConfig()