Browse Source

#2479

update
tags/v1.22.7.2^2
chenyifan01 3 years ago
parent
commit
132030bc04
3 changed files with 13 additions and 8 deletions
  1. +2
    -5
      modules/auth/wechat/template.go
  2. +9
    -3
      modules/notification/wechat/wechat.go
  3. +2
    -0
      modules/setting/setting.go

+ 2
- 5
modules/auth/wechat/template.go View File

@@ -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{


+ 9
- 3
modules/notification/wechat/wechat.go View File

@@ -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
}
}
}
}

+ 2
- 0
modules/setting/setting.go View File

@@ -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()



Loading…
Cancel
Save