Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ type LarkChat struct {
type JobTaskNotificationSpec struct {
WebHookType setting.NotifyWebHookType `bson:"webhook_type" yaml:"webhook_type" json:"webhook_type"`

LarkHookNotificationConfig *LarkHookNotificationConfig `bson:"lark_hook_notification_config,omitempty" yaml:"lark_hook_notification_config,omitempty" json:"lark_hook_notification_config,omitempty"`
LarkGroupNotificationConfig *LarkGroupNotificationConfig `bson:"lark_group_notification_config,omitempty" yaml:"lark_group_notification_config,omitempty" json:"lark_group_notification_config,omitempty"`
LarkPersonNotificationConfig *LarkPersonNotificationConfig `bson:"lark_person_notification_config,omitempty" yaml:"lark_person_notification_config,omitempty" json:"lark_person_notification_config,omitempty"`
WechatNotificationConfig *WechatNotificationConfig `bson:"wechat_notification_config,omitempty" yaml:"wechat_notification_config,omitempty" json:"wechat_notification_config,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ type HookPayload struct {
DeliveryID string `bson:"delivery_id" json:"delivery_id,omitempty"`
CodehostID int `bson:"codehost_id" json:"codehost_id"`
EventType string `bson:"event_type" json:"event_type"`
RawPayload string `bson:"raw_payload" json:"raw_payload,omitempty"`
}

type TargetArgs struct {
Expand Down
64 changes: 40 additions & 24 deletions pkg/microservice/aslan/core/common/repository/models/workflow_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,12 +1158,12 @@ type NotificationJobSpec struct {

LarkGroupNotificationConfig *LarkGroupNotificationConfig `bson:"lark_group_notification_config,omitempty" yaml:"lark_group_notification_config,omitempty" json:"lark_group_notification_config,omitempty"`
LarkPersonNotificationConfig *LarkPersonNotificationConfig `bson:"lark_person_notification_config,omitempty" yaml:"lark_person_notification_config,omitempty" json:"lark_person_notification_config,omitempty"`
//LarkHookNotificationConfig *LarkHookNotificationConfig `bson:"lark_hook_notification_config,omitempty" yaml:"lark_hook_notification_config,omitempty" json:"lark_hook_notification_config,omitempty"`
WechatNotificationConfig *WechatNotificationConfig `bson:"wechat_notification_config,omitempty" yaml:"wechat_notification_config,omitempty" json:"wechat_notification_config,omitempty"`
DingDingNotificationConfig *DingDingNotificationConfig `bson:"dingding_notification_config,omitempty" yaml:"dingding_notification_config,omitempty" json:"dingding_notification_config,omitempty"`
MSTeamsNotificationConfig *MSTeamsNotificationConfig `bson:"msteams_notification_config,omitempty" yaml:"msteams_notification_config,omitempty" json:"msteams_notification_config,omitempty"`
MailNotificationConfig *MailNotificationConfig `bson:"mail_notification_config,omitempty" yaml:"mail_notification_config,omitempty" json:"mail_notification_config,omitempty"`
WebhookNotificationConfig *WebhookNotificationConfig `bson:"webhook_notification_config,omitempty" yaml:"webhook_notification_config,omitempty" json:"webhook_notification_config,omitempty"`
LarkHookNotificationConfig *LarkHookNotificationConfig `bson:"lark_hook_notification_config,omitempty" yaml:"lark_hook_notification_config,omitempty" json:"lark_hook_notification_config,omitempty"`
WechatNotificationConfig *WechatNotificationConfig `bson:"wechat_notification_config,omitempty" yaml:"wechat_notification_config,omitempty" json:"wechat_notification_config,omitempty"`
DingDingNotificationConfig *DingDingNotificationConfig `bson:"dingding_notification_config,omitempty" yaml:"dingding_notification_config,omitempty" json:"dingding_notification_config,omitempty"`
MSTeamsNotificationConfig *MSTeamsNotificationConfig `bson:"msteams_notification_config,omitempty" yaml:"msteams_notification_config,omitempty" json:"msteams_notification_config,omitempty"`
MailNotificationConfig *MailNotificationConfig `bson:"mail_notification_config,omitempty" yaml:"mail_notification_config,omitempty" json:"mail_notification_config,omitempty"`
WebhookNotificationConfig *WebhookNotificationConfig `bson:"webhook_notification_config,omitempty" yaml:"webhook_notification_config,omitempty" json:"webhook_notification_config,omitempty"`

Content string `bson:"content" yaml:"content" json:"content"`
Title string `bson:"title" yaml:"title" json:"title"`
Expand Down Expand Up @@ -1247,6 +1247,10 @@ func (n *NotificationJobSpec) GenerateNewNotifyConfigWithOldData() error {
if n.LarkPersonNotificationConfig == nil {
return fmt.Errorf("lark_person_notification_config cannot be empty for type feishu_person notification")
}
case setting.NotifyWebHookTypeFeishu:
if n.LarkHookNotificationConfig == nil {
return fmt.Errorf("lark_hook_notification_config cannot be empty for type feishu notification")
}
default:
// TODO: this code is commented because of chagee old data. uncomment it if possible
//return fmt.Errorf("unsupported notification type: %s", n.WebHookType)
Expand All @@ -1255,44 +1259,56 @@ func (n *NotificationJobSpec) GenerateNewNotifyConfigWithOldData() error {
return nil
}

type DynamicRecipient struct {
Value string `bson:"value" json:"value" yaml:"value"`
IdentityType string `bson:"identity_type" json:"identity_type" yaml:"identity_type"`
}

// TODO: why is_at_all? it could be done in backend
type LarkGroupNotificationConfig struct {
AppID string `bson:"app_id" json:"app_id" yaml:"app_id"`
Chat *LarkChat `bson:"chat" json:"chat" yaml:"chat"`
AtUsers []*lark.UserInfo `bson:"at_users" json:"at_users" yaml:"at_users"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
AppID string `bson:"app_id" json:"app_id" yaml:"app_id"`
Chat *LarkChat `bson:"chat" json:"chat" yaml:"chat"`
AtUsers []*lark.UserInfo `bson:"at_users" json:"at_users" yaml:"at_users"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
}

type LarkPersonNotificationConfig struct {
AppID string `bson:"app_id" json:"app_id" yaml:"app_id"`
TargetUsers []*lark.UserInfo `bson:"target_users" json:"target_users" yaml:"target_users"`
AppID string `bson:"app_id" json:"app_id" yaml:"app_id"`
TargetUsers []*lark.UserInfo `bson:"target_users" json:"target_users" yaml:"target_users"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
}

type LarkHookNotificationConfig struct {
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtUsers []string `bson:"at_users" json:"at_users" yaml:"at_users"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtUsers []string `bson:"at_users" json:"at_users" yaml:"at_users"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
}

type WechatNotificationConfig struct {
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtUsers []string `bson:"at_users" json:"at_users" yaml:"at_users"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtUsers []string `bson:"at_users" json:"at_users" yaml:"at_users"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
}

type DingDingNotificationConfig struct {
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtMobiles []string `bson:"at_mobiles" json:"at_mobiles" yaml:"at_mobiles"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtMobiles []string `bson:"at_mobiles" json:"at_mobiles" yaml:"at_mobiles"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
IsAtAll bool `bson:"is_at_all" json:"is_at_all" yaml:"is_at_all"`
}

type MSTeamsNotificationConfig struct {
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtEmails []string `bson:"at_emails" json:"at_emails" yaml:"at_emails"`
HookAddress string `bson:"hook_address" json:"hook_address" yaml:"hook_address"`
AtEmails []string `bson:"at_emails" json:"at_emails" yaml:"at_emails"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
}

type MailNotificationConfig struct {
TargetUsers []*User `bson:"target_users" json:"target_users" yaml:"target_users"`
TargetUsers []*User `bson:"target_users" json:"target_users" yaml:"target_users"`
DynamicRecipients []*DynamicRecipient `bson:"dynamic_recipients" json:"dynamic_recipients" yaml:"dynamic_recipients"`
}

type WebhookNotificationConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func (w *Service) sendFeishuMessage(uri string, lcMsg *LarkCard) error {
return err
}

func (w *Service) SendFeishuHookCard(uri string, lcMsg *LarkCard) error {
return w.sendFeishuMessage(uri, lcMsg)
}

func (w *Service) sendFeishuMessageFromClient(client *lark.Client, receiverType, receiverID, messageType, messageBody string) error {
err := client.SendMessage(receiverType, messageType, receiverID, messageBody)

Expand Down Expand Up @@ -228,6 +232,10 @@ func (w *Service) sendFeishuMessageOfSingleType(title, uri, content string) erro
return err
}

func (w *Service) SendFeishuHookText(uri, content string) error {
return w.sendFeishuMessageOfSingleType("", uri, content)
}

func getColorTemplateWithStatus(status config.Status) string {
if status == config.StatusPassed || status == config.StatusCreated {
return feishuHeaderTemplateGreen
Expand Down
Loading
Loading