@@ -211,6 +211,13 @@ var (
211211 Description : `{{ template "jira.default.description" . }}` ,
212212 Priority : `{{ template "jira.default.priority" . }}` ,
213213 }
214+
215+ DefaultMattermostConfig = MattermostConfig {
216+ NotifierConfig : NotifierConfig {
217+ VSendResolved : true ,
218+ },
219+ Text : `{{ template "mattermost.default.text" . }}` ,
220+ }
214221)
215222
216223// NotifierConfig contains base options common across all notifier configurations.
@@ -1072,3 +1079,98 @@ func (c *RocketchatConfig) UnmarshalYAML(unmarshal func(any) error) error {
10721079 }
10731080 return nil
10741081}
1082+
1083+ // MattermostPriority defines the priority for a mattermost notification.
1084+ type MattermostPriority struct {
1085+ Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
1086+ RequestedAck bool `yaml:"requested_ack,omitempty" json:"requested_ack,omitempty"`
1087+ PersistentNotifications bool `yaml:"persistent_notifications,omitempty" json:"persistent_notifications,omitempty"`
1088+ }
1089+
1090+ // MattermostProps defines additional properties for a mattermost notification.
1091+ // Only 'card' property takes effect now.
1092+ type MattermostProps struct {
1093+ Card string `yaml:"card,omitempty" json:"card,omitempty"`
1094+ }
1095+
1096+ // MattermostField configures a single Mattermost field for Slack compatibility.
1097+ // See https://developers.mattermost.com/integrate/reference/message-attachments/#fields for more information.
1098+ type MattermostField struct {
1099+ Title string `yaml:"title,omitempty" json:"title,omitempty"`
1100+ Value string `yaml:"value,omitempty" json:"value,omitempty"`
1101+ Short * bool `yaml:"short,omitempty" json:"short,omitempty"`
1102+ }
1103+
1104+ // UnmarshalYAML implements the yaml.Unmarshaler interface for MattermostField.
1105+ func (c * MattermostField ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
1106+ type plain MattermostField
1107+ if err := unmarshal ((* plain )(c )); err != nil {
1108+ return err
1109+ }
1110+ if c .Title == "" {
1111+ return errors .New ("missing title in Mattermost field configuration" )
1112+ }
1113+ if c .Value == "" {
1114+ return errors .New ("missing value in Mattermost field configuration" )
1115+ }
1116+ return nil
1117+ }
1118+
1119+ // MattermostAttachment defines an attachment for a Mattermost notification.
1120+ // See https://developers.mattermost.com/integrate/reference/message-attachments/#fields for more information.
1121+ type MattermostAttachment struct {
1122+ Fallback string `yaml:"fallback,omitempty" json:"fallback,omitempty"`
1123+ Color string `yaml:"color,omitempty" json:"color,omitempty"`
1124+ Pretext string `yaml:"pretext,omitempty" json:"pretext,omitempty"`
1125+ Text string `yaml:"text,omitempty" json:"text,omitempty"`
1126+ AuthorName string `yaml:"author_name,omitempty" json:"author_name,omitempty"`
1127+ AuthorLink string `yaml:"author_link,omitempty" json:"author_link,omitempty"`
1128+ AuthorIcon string `yaml:"author_icon,omitempty" json:"author_icon,omitempty"`
1129+ Title string `yaml:"title,omitempty" json:"title,omitempty"`
1130+ TitleLink string `yaml:"title_link,omitempty" json:"title_link,omitempty"`
1131+ Fields []* MattermostField `yaml:"fields,omitempty" json:"fields,omitempty"`
1132+ ThumbURL string `yaml:"thumb_url,omitempty" json:"thumb_url,omitempty"`
1133+ Footer string `yaml:"footer,omitempty" json:"footer,omitempty"`
1134+ FooterIcon string `yaml:"footer_icon,omitempty" json:"footer_icon,omitempty"`
1135+ ImageURL string `yaml:"image_url,omitempty" json:"image_url,omitempty"`
1136+ }
1137+
1138+ // MattermostConfig configures notifications via Mattermost.
1139+ // See https://developers.mattermost.com/integrate/webhooks/incoming/ for more information.
1140+ type MattermostConfig struct {
1141+ NotifierConfig `yaml:",inline" json:",inline"`
1142+
1143+ HTTPConfig * commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
1144+ WebhookURL * SecretURL `yaml:"webhook_url,omitempty" json:"webhook_url,omitempty"`
1145+ WebhookURLFile string `yaml:"webhook_url_file,omitempty" json:"webhook_url_file,omitempty"`
1146+
1147+ Channel string `yaml:"channel,omitempty" json:"channel,omitempty"`
1148+ Username string `yaml:"username,omitempty" json:"username,omitempty"`
1149+
1150+ Text string `yaml:"text,omitempty" json:"text,omitempty"`
1151+ IconURL string `yaml:"icon_url,omitempty" json:"icon_url,omitempty"`
1152+ IconEmoji string `yaml:"icon_emoji,omitempty" json:"icon_emoji,omitempty"`
1153+ Attachments []* MattermostAttachment `yaml:"attachments,omitempty" json:"attachments,omitempty"`
1154+ Type string `yaml:"type,omitempty" json:"type,omitempty"`
1155+ Props * MattermostProps `yaml:"props,omitempty" json:"props,omitempty"`
1156+ Priority * MattermostPriority `yaml:"priority,omitempty" json:"priority,omitempty"`
1157+ }
1158+
1159+ // UnmarshalYAML implements the yaml.Unmarshaler interface.
1160+ func (c * MattermostConfig ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
1161+ * c = DefaultMattermostConfig
1162+ type plain MattermostConfig
1163+ if err := unmarshal ((* plain )(c )); err != nil {
1164+ return err
1165+ }
1166+
1167+ if c .WebhookURL == nil && c .WebhookURLFile == "" {
1168+ return errors .New ("one of webhook_url or webhook_url_file must be configured" )
1169+ }
1170+
1171+ if c .WebhookURL != nil && len (c .WebhookURLFile ) > 0 {
1172+ return errors .New ("at most one of webhook_url & webhook_url_file must be configured" )
1173+ }
1174+
1175+ return nil
1176+ }
0 commit comments