diff --git a/.res/screenshot.png b/.res/screenshot.png index 09b8d6dd..791a5ce8 100644 Binary files a/.res/screenshot.png and b/.res/screenshot.png differ diff --git a/docs/assets/notif/discord-2.png b/docs/assets/notif/discord-2.png index 3420deb5..f79ea891 100644 Binary files a/docs/assets/notif/discord-2.png and b/docs/assets/notif/discord-2.png differ diff --git a/docs/assets/notif/slack.png b/docs/assets/notif/slack.png index 8e0f1a86..791a5ce8 100644 Binary files a/docs/assets/notif/slack.png and b/docs/assets/notif/slack.png differ diff --git a/docs/notif/discord.md b/docs/notif/discord.md index e08629a1..4f4047fb 100644 --- a/docs/notif/discord.md +++ b/docs/notif/discord.md @@ -15,8 +15,8 @@ Allow to send notifications to your Discord channel. - "<@124>" - "<@125>" - "<@&200>" + renderFields: true timeout: 10s - templateTitle: "{{ .Entry.Image }} released" templateBody: | Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released. ``` @@ -25,23 +25,17 @@ Allow to send notifications to your Discord channel. |---------------------|---------------------------------------|---------------| | `webhookURL`[^1] | | Discord [incoming webhook URL](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) | | `mentions` | | List of users or roles to notify | +| `renderFields` | `true` | Render [field objects](https://discordjs.guide/popular-topics/embeds.html) | | `timeout` | `10s` | Timeout specifies a time limit for the request to be made | -| `templateTitle`[^1] | See [below](#default-templatetitle) | [Notification template](../faq.md#notification-template) for message title | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body | !!! abstract "Environment variables" * `DIUN_NOTIF_DISCORD_WEBHOOKURL` * `DIUN_NOTIF_DISCORD_MENTIONS` (comma separated) + * `DIUN_NOTIF_DISCORD_RENDERFIELDS` * `DIUN_NOTIF_DISCORD_TIMEOUT` - * `DIUN_NOTIF_DISCORD_TEMPLATETITLE` * `DIUN_NOTIF_DISCORD_TEMPLATEBODY` -### Default `templateTitle` - -``` -[[ config.extra.template.defaultTitle ]] -``` - ### Default `templateBody` ``` diff --git a/docs/notif/rocketchat.md b/docs/notif/rocketchat.md index 591d3908..a328a8eb 100644 --- a/docs/notif/rocketchat.md +++ b/docs/notif/rocketchat.md @@ -12,6 +12,7 @@ Allow to send notifications to your Rocket.Chat channel. channel: "#general" userID: abcdEFGH012345678 token: Token123456 + renderAttachment: true timeout: 10s templateTitle: "{{ .Entry.Image }} released" templateBody: | @@ -25,6 +26,7 @@ Allow to send notifications to your Rocket.Chat channel. | `userID`[^1] | | User ID | | `token` | | Authentication token | | `tokenFile` | | Use content of secret file as authentication token if `token` not defined | +| `renderAttachment` | `true` | Render [attachment object](https://docs.rocket.chat/guides/user-guides/messaging#send-attachments) | | `timeout` | `10s` | Timeout specifies a time limit for the request to be made | | `templateTitle`[^1] | See [below](#default-templatetitle) | [Notification template](../faq.md#notification-template) for message title | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body | @@ -38,6 +40,7 @@ Allow to send notifications to your Rocket.Chat channel. * `DIUN_NOTIF_ROCKETCHAT_USERID` * `DIUN_NOTIF_ROCKETCHAT_TOKEN` * `DIUN_NOTIF_ROCKETCHAT_TOKENFILE` + * `DIUN_NOTIF_ROCKETCHAT_RENDERATTACHMENT` * `DIUN_NOTIF_ROCKETCHAT_TIMEOUT` * `DIUN_NOTIF_ROCKETCHAT_TEMPLATETITLE` * `DIUN_NOTIF_ROCKETCHAT_TEMPLATEBODY` diff --git a/docs/notif/slack.md b/docs/notif/slack.md index f76fdabc..9dd2fffe 100644 --- a/docs/notif/slack.md +++ b/docs/notif/slack.md @@ -12,6 +12,7 @@ You can send notifications to your Slack channel using an [incoming webhook URL] notif: slack: webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij + renderFields: true templateBody: | Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released. ``` @@ -19,16 +20,18 @@ You can send notifications to your Slack channel using an [incoming webhook URL] | Name | Default | Description | |--------------------|--------------------------------------------|---------------| | `webhookURL`[^1] | | Slack [incoming webhook URL](https://api.slack.com/messaging/webhooks) | +| `renderFields` | `true` | Render [field objects](https://api.slack.com/messaging/composing/layouts#stack_of_blocks) | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body | !!! abstract "Environment variables" * `DIUN_NOTIF_SLACK_WEBHOOKURL` + * `DIUN_NOTIF_SLACK_RENDERFIELDS` * `DIUN_NOTIF_SLACK_TEMPLATEBODY` ### Default `templateBody` ``` - Docker tag `{{ .Entry.Image }}` {{ if (eq .Entry.Status "new") }}newly added{{ else }}updated{{ end }}. + Docker tag {{ if .Entry.Image.HubLink }}<{{ .Entry.Image.HubLink }}|`{{ .Entry.Image }}`>{{ else }}`{{ .Entry.Image }}`{{ end }} {{ if (eq .Entry.Status "new") }}available{{ else }}updated{{ end }}. ``` ## Sample diff --git a/docs/notif/teams.md b/docs/notif/teams.md index 089c473c..44df390e 100644 --- a/docs/notif/teams.md +++ b/docs/notif/teams.md @@ -9,6 +9,7 @@ You can send notifications to your Teams team-channel using an [incoming webhook notif: teams: webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij + renderFacts: true templateBody: | Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released. ``` @@ -16,10 +17,12 @@ You can send notifications to your Teams team-channel using an [incoming webhook | Name | Default | Description | |--------------------|--------------------------------------------|---------------| | `webhookURL`[^1] | | Teams [incoming webhook URL](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors) | +| `renderFacts` | `true` | Render fact objects | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body | !!! abstract "Environment variables" * `DIUN_NOTIF_TEAMS_WEBHOOKURL` + * `DIUN_NOTIF_TEAMS_RENDERFACTS` * `DIUN_NOTIF_TEAMS_TEMPLATEBODY` ### Default `templateBody` diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 5dec6d84..aac1ec02 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -76,9 +76,9 @@ func TestLoadFile(t *testing.T) { "<@125>", "<@&200>", }, - Timeout: utl.NewDuration(10 * time.Second), - TemplateTitle: model.NotifDefaultTemplateTitle, - TemplateBody: model.NotifDefaultTemplateBody, + RenderFields: utl.NewTrue(), + Timeout: utl.NewDuration(10 * time.Second), + TemplateBody: model.NotifDefaultTemplateBody, }, Gotify: &model.NotifGotify{ Endpoint: "http://gotify.foo.com", @@ -133,13 +133,14 @@ for {{ .Entry.Manifest.Platform }} platform. TemplateBody: model.NotifDefaultTemplateBody, }, RocketChat: &model.NotifRocketChat{ - Endpoint: "http://rocket.foo.com:3000", - Channel: "#general", - UserID: "abcdEFGH012345678", - Token: "Token123456", - Timeout: utl.NewDuration(10 * time.Second), - TemplateTitle: model.NotifDefaultTemplateTitle, - TemplateBody: model.NotifRocketChatDefaultTemplateBody, + Endpoint: "http://rocket.foo.com:3000", + Channel: "#general", + UserID: "abcdEFGH012345678", + Token: "Token123456", + RenderAttachment: utl.NewTrue(), + Timeout: utl.NewDuration(10 * time.Second), + TemplateTitle: model.NotifDefaultTemplateTitle, + TemplateBody: model.NotifRocketChatDefaultTemplateBody, }, Script: &model.NotifScript{ Cmd: "uname", @@ -149,10 +150,12 @@ for {{ .Entry.Manifest.Platform }} platform. }, Slack: &model.NotifSlack{ WebhookURL: "https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij", + RenderFields: utl.NewFalse(), TemplateBody: model.NotifSlackDefaultTemplateBody, }, Teams: &model.NotifTeams{ WebhookURL: "https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij", + RenderFacts: utl.NewFalse(), TemplateBody: model.NotifTeamsDefaultTemplateBody, }, Telegram: &model.NotifTelegram{ diff --git a/internal/config/fixtures/config.test.yml b/internal/config/fixtures/config.test.yml index e37de56c..149b4949 100644 --- a/internal/config/fixtures/config.test.yml +++ b/internal/config/fixtures/config.test.yml @@ -25,6 +25,7 @@ notif: - "<@124>" - "<@125>" - "<@&200>" + renderFields: true timeout: 10s gotify: endpoint: http://gotify.foo.com @@ -69,6 +70,7 @@ notif: channel: "#general" userID: abcdEFGH012345678 token: Token123456 + renderAttachment: true timeout: 10s script: cmd: "uname" @@ -76,8 +78,10 @@ notif: - "-a" slack: webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij + renderFields: false teams: webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij + renderFacts: false telegram: token: abcdef123456 chatIDs: diff --git a/internal/config/fixtures/config.validate.yml b/internal/config/fixtures/config.validate.yml index f7bbe2b5..b8dbd305 100644 --- a/internal/config/fixtures/config.validate.yml +++ b/internal/config/fixtures/config.validate.yml @@ -25,6 +25,7 @@ notif: - "<@124>" - "<@125>" - "<@&200>" + renderFields: true timeout: 10s gotify: endpoint: http://gotify.foo.com @@ -67,6 +68,7 @@ notif: channel: "#general" userID: abcdEFGH012345678 token: Token123456 + renderAttachment: false timeout: 10s script: cmd: "uname" @@ -74,8 +76,10 @@ notif: - "-a" slack: webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij + renderFields: false teams: webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij + renderFacts: true telegram: token: abcdef123456 chatIDs: diff --git a/internal/model/notif_discord.go b/internal/model/notif_discord.go index b2e18dfd..81627eef 100644 --- a/internal/model/notif_discord.go +++ b/internal/model/notif_discord.go @@ -8,11 +8,11 @@ import ( // NotifDiscord holds Discord notification configuration details type NotifDiscord struct { - WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` - Mentions []string `yaml:"mentions,omitempty" json:"mentions,omitempty"` - Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"` - TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"` - TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` + WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` + Mentions []string `yaml:"mentions,omitempty" json:"mentions,omitempty"` + RenderFields *bool `yaml:"renderFields,omitempty" json:"renderFields,omitempty" validate:"required"` + Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"` + TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` } // GetDefaults gets the default values @@ -24,7 +24,7 @@ func (s *NotifDiscord) GetDefaults() *NotifDiscord { // SetDefaults sets the default values func (s *NotifDiscord) SetDefaults() { + s.RenderFields = utl.NewTrue() s.Timeout = utl.NewDuration(10 * time.Second) - s.TemplateTitle = NotifDefaultTemplateTitle s.TemplateBody = NotifDefaultTemplateBody } diff --git a/internal/model/notif_rocketchat.go b/internal/model/notif_rocketchat.go index 8031c83f..a82d0a51 100644 --- a/internal/model/notif_rocketchat.go +++ b/internal/model/notif_rocketchat.go @@ -11,14 +11,15 @@ const NotifRocketChatDefaultTemplateBody = `Docker tag {{ .Entry.Image }} which // NotifRocketChat holds Rocket.Chat notification configuration details type NotifRocketChat struct { - Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"` - Channel string `yaml:"channel,omitempty" json:"channel,omitempty" validate:"required"` - UserID string `yaml:"userID,omitempty" json:"userID,omitempty" validate:"required"` - Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` - TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` - Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"` - TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"` - TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` + Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"` + Channel string `yaml:"channel,omitempty" json:"channel,omitempty" validate:"required"` + UserID string `yaml:"userID,omitempty" json:"userID,omitempty" validate:"required"` + Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` + TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` + RenderAttachment *bool `yaml:"renderAttachment,omitempty" json:"renderAttachment,omitempty" validate:"required"` + Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"` + TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"` + TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` } // GetDefaults gets the default values @@ -30,6 +31,7 @@ func (s *NotifRocketChat) GetDefaults() *NotifRocketChat { // SetDefaults sets the default values func (s *NotifRocketChat) SetDefaults() { + s.RenderAttachment = utl.NewTrue() s.Timeout = utl.NewDuration(10 * time.Second) s.TemplateTitle = NotifDefaultTemplateTitle s.TemplateBody = NotifRocketChatDefaultTemplateBody diff --git a/internal/model/notif_slack.go b/internal/model/notif_slack.go index 83e4135a..958f5c20 100644 --- a/internal/model/notif_slack.go +++ b/internal/model/notif_slack.go @@ -1,11 +1,14 @@ package model +import "github.com/crazy-max/diun/v4/pkg/utl" + // NotifSlackDefaultTemplateBody ... -const NotifSlackDefaultTemplateBody = " Docker tag `{{ .Entry.Image }}` {{ if (eq .Entry.Status \"new\") }}available{{ else }}updated{{ end }}." +const NotifSlackDefaultTemplateBody = " Docker tag {{ if .Entry.Image.HubLink }}<{{ .Entry.Image.HubLink }}|`{{ .Entry.Image }}`>{{ else }}`{{ .Entry.Image }}`{{ end }} {{ if (eq .Entry.Status \"new\") }}available{{ else }}updated{{ end }}." // NotifSlack holds slack notification configuration details type NotifSlack struct { WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` + RenderFields *bool `yaml:"renderFields,omitempty" json:"renderFields,omitempty" validate:"required"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` } @@ -18,5 +21,6 @@ func (s *NotifSlack) GetDefaults() *NotifSlack { // SetDefaults sets the default values func (s *NotifSlack) SetDefaults() { + s.RenderFields = utl.NewTrue() s.TemplateBody = NotifSlackDefaultTemplateBody } diff --git a/internal/model/notif_teams.go b/internal/model/notif_teams.go index d7b9c3a6..1a047eb8 100644 --- a/internal/model/notif_teams.go +++ b/internal/model/notif_teams.go @@ -1,11 +1,14 @@ package model +import "github.com/crazy-max/diun/v4/pkg/utl" + // NotifTeamsDefaultTemplateBody ... const NotifTeamsDefaultTemplateBody = "Docker tag {{ if .Entry.Image.HubLink }}[`{{ .Entry.Image }}`]({{ .Entry.Image.HubLink }}){{ else }}`{{ .Entry.Image }}`{{ end }} {{ if (eq .Entry.Status \"new\") }}available{{ else }}updated{{ end }}." // NotifTeams holds Teams notification configuration details type NotifTeams struct { WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` + RenderFacts *bool `yaml:"renderFacts,omitempty" json:"renderFacts,omitempty" validate:"required"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` } @@ -18,5 +21,6 @@ func (s *NotifTeams) GetDefaults() *NotifTeams { // SetDefaults sets the default values func (s *NotifTeams) SetDefaults() { + s.RenderFacts = utl.NewTrue() s.TemplateBody = NotifTeamsDefaultTemplateBody } diff --git a/internal/notif/discord/client.go b/internal/notif/discord/client.go index 0e777d77..3c895493 100644 --- a/internal/notif/discord/client.go +++ b/internal/notif/discord/client.go @@ -45,16 +45,15 @@ func (c *Client) Send(entry model.NotifEntry) error { } message, err := msg.New(msg.Options{ - Meta: c.meta, - Entry: entry, - TemplateTitle: c.cfg.TemplateTitle, - TemplateBody: c.cfg.TemplateBody, + Meta: c.meta, + Entry: entry, + TemplateBody: c.cfg.TemplateBody, }) if err != nil { return err } - title, body, err := message.RenderMarkdown() + _, body, err := message.RenderMarkdown() if err != nil { return err } @@ -64,35 +63,38 @@ func (c *Client) Send(entry model.NotifEntry) error { content.WriteString(fmt.Sprintf("%s ", mention)) } } - content.WriteString(string(title)) + content.WriteString(string(body)) - fields := []EmbedField{ - { - Name: "Hostname", - Value: c.meta.Hostname, - }, - { - Name: "Provider", - Value: entry.Provider, - }, - { - Name: "Created", - Value: entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC"), - }, - { - Name: "Digest", - Value: entry.Manifest.Digest.String(), - }, - { - Name: "Platform", - Value: entry.Manifest.Platform, - }, - } - if len(entry.Image.HubLink) > 0 { - fields = append(fields, EmbedField{ - Name: "HubLink", - Value: entry.Image.HubLink, - }) + var fields []EmbedField + if *c.cfg.RenderFields { + fields = []EmbedField{ + { + Name: "Hostname", + Value: c.meta.Hostname, + }, + { + Name: "Provider", + Value: entry.Provider, + }, + { + Name: "Created", + Value: entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC"), + }, + { + Name: "Digest", + Value: entry.Manifest.Digest.String(), + }, + { + Name: "Platform", + Value: entry.Manifest.Platform, + }, + } + if len(entry.Image.HubLink) > 0 { + fields = append(fields, EmbedField{ + Name: "HubLink", + Value: entry.Image.HubLink, + }) + } } dataBuf := new(bytes.Buffer) @@ -102,17 +104,15 @@ func (c *Client) Send(entry model.NotifEntry) error { AvatarURL: c.meta.Logo, Embeds: []Embed{ { - Description: string(body), - Footer: EmbedFooter{ - Text: fmt.Sprintf("%s © %d %s %s", c.meta.Author, time.Now().Year(), c.meta.Name, c.meta.Version), - IconURL: c.meta.Logo, - }, Author: EmbedAuthor{ Name: c.meta.Name, URL: c.meta.URL, IconURL: c.meta.Logo, }, Fields: fields, + Footer: EmbedFooter{ + Text: fmt.Sprintf("%s © %d %s %s", c.meta.Author, time.Now().Year(), c.meta.Name, c.meta.Version), + }, }, }, }); err != nil { diff --git a/internal/notif/rocketchat/client.go b/internal/notif/rocketchat/client.go index d7beb63a..bf2704e0 100644 --- a/internal/notif/rocketchat/client.go +++ b/internal/notif/rocketchat/client.go @@ -66,54 +66,56 @@ func (c *Client) Send(entry model.NotifEntry) error { return err } - fields := []AttachmentField{ - { - Title: "Hostname", - Value: c.meta.Hostname, - Short: false, - }, - { - Title: "Provider", - Value: entry.Provider, - Short: false, - }, - { - Title: "Created", - Value: entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC"), - Short: false, - }, - { - Title: "Digest", - Value: entry.Manifest.Digest.String(), - Short: false, - }, - { - Title: "Platform", - Value: entry.Manifest.Platform, - Short: false, - }, - } - if len(entry.Image.HubLink) > 0 { - fields = append(fields, AttachmentField{ - Title: "HubLink", - Value: entry.Image.HubLink, - Short: false, + var attachments []Attachment + if *c.cfg.RenderAttachment { + fields := []AttachmentField{ + { + Title: "Hostname", + Value: c.meta.Hostname, + Short: false, + }, + { + Title: "Provider", + Value: entry.Provider, + Short: false, + }, + { + Title: "Created", + Value: entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC"), + Short: false, + }, + { + Title: "Digest", + Value: entry.Manifest.Digest.String(), + Short: false, + }, + { + Title: "Platform", + Value: entry.Manifest.Platform, + Short: false, + }, + } + if len(entry.Image.HubLink) > 0 { + fields = append(fields, AttachmentField{ + Title: "HubLink", + Value: entry.Image.HubLink, + Short: false, + }) + } + attachments = append(attachments, Attachment{ + Text: string(body), + Ts: json.Number(strconv.FormatInt(time.Now().Unix(), 10)), + Fields: fields, }) } dataBuf := new(bytes.Buffer) if err := json.NewEncoder(dataBuf).Encode(Message{ - Alias: c.meta.Name, - Avatar: c.meta.Logo, - Channel: c.cfg.Channel, - Text: string(title), - Attachments: []Attachment{ - { - Text: string(body), - Ts: json.Number(strconv.FormatInt(time.Now().Unix(), 10)), - Fields: fields, - }, - }, + Alias: c.meta.Name, + Avatar: c.meta.Logo, + Channel: c.cfg.Channel, + Text: string(title), + Attachments: attachments, }); err != nil { return err } diff --git a/internal/notif/slack/client.go b/internal/notif/slack/client.go index 7fcd1a17..31e22a53 100644 --- a/internal/notif/slack/client.go +++ b/internal/notif/slack/client.go @@ -50,46 +50,49 @@ func (c *Client) Send(entry model.NotifEntry) error { return err } + var fields []slack.AttachmentField + if *c.cfg.RenderFields { + fields = []slack.AttachmentField{ + { + Title: "Hostname", + Value: c.meta.Hostname, + Short: false, + }, + { + Title: "Provider", + Value: entry.Provider, + Short: false, + }, + { + Title: "Created", + Value: entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC"), + Short: false, + }, + { + Title: "Digest", + Value: entry.Manifest.Digest.String(), + Short: false, + }, + { + Title: "Platform", + Value: entry.Manifest.Platform, + Short: false, + }, + } + if len(entry.Image.HubLink) > 0 { + fields = append(fields, slack.AttachmentField{ + Title: "HubLink", + Value: entry.Image.HubLink, + Short: false, + }) + } + } + color := "#4caf50" if entry.Status == model.ImageStatusUpdate { color = "#0054ca" } - fields := []slack.AttachmentField{ - { - Title: "Hostname", - Value: c.meta.Hostname, - Short: false, - }, - { - Title: "Provider", - Value: entry.Provider, - Short: false, - }, - { - Title: "Created", - Value: entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC"), - Short: false, - }, - { - Title: "Digest", - Value: entry.Manifest.Digest.String(), - Short: false, - }, - { - Title: "Platform", - Value: entry.Manifest.Platform, - Short: false, - }, - } - if len(entry.Image.HubLink) > 0 { - fields = append(fields, slack.AttachmentField{ - Title: "HubLink", - Value: entry.Image.HubLink, - Short: false, - }) - } - return slack.PostWebhook(c.cfg.WebhookURL, &slack.WebhookMessage{ Attachments: []slack.Attachment{ { diff --git a/internal/notif/teams/client.go b/internal/notif/teams/client.go index a25fb53b..0f18c8f6 100644 --- a/internal/notif/teams/client.go +++ b/internal/notif/teams/client.go @@ -3,6 +3,7 @@ package teams import ( "bytes" "encoding/json" + "fmt" "net/http" "time" @@ -71,6 +72,17 @@ func (c *Client) Send(entry model.NotifEntry) error { themeColor = "0076D7" } + var facts []Fact + if *c.cfg.RenderFacts { + facts = []Fact{ + {"Hostname", c.meta.Hostname}, + {"Provider", entry.Provider}, + {"Created", entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC")}, + {"Digest", entry.Manifest.Digest.String()}, + {"Platform", entry.Manifest.Platform}, + } + } + jsonBody, err := json.Marshal(struct { Type string `json:"@type"` Context string `json:"@context"` @@ -82,16 +94,13 @@ func (c *Client) Send(entry model.NotifEntry) error { Context: "https://schema.org/extensions", ThemeColor: themeColor, Summary: string(body), - Sections: []Sections{{ - ActivityTitle: string(body), - ActivitySubtitle: "Provider: " + entry.Provider, - Facts: []Fact{ - {"Hostname", c.meta.Hostname}, - {"Provider", entry.Provider}, - {"Created", entry.Manifest.Created.Format("Jan 02, 2006 15:04:05 UTC")}, - {"Digest", entry.Manifest.Digest.String()}, - {"Platform", entry.Manifest.Platform}, - }}}, + Sections: []Sections{ + { + ActivityTitle: string(body), + ActivitySubtitle: fmt.Sprintf("%s © %d %s %s", c.meta.Author, time.Now().Year(), c.meta.Name, c.meta.Version), + Facts: facts, + }, + }, }) if err != nil { return err diff --git a/mkdocs.yml b/mkdocs.yml index 9e2ad73b..93bbb0e0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,11 +24,11 @@ extra: domain: crazymax.dev/diun template: defaultTitle: | - {{ if (eq .Entry.Status "new") }}New image {{ .Entry.Image }} has been added{{ else }}Image update for {{ .Entry.Image }}{{ end }} + {{ .Entry.Image }} {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ .Entry.Image }}{{ end }} defaultBody: | Docker tag {{ if .Entry.Image.HubLink }}[**{{ .Entry.Image }}**]({{ .Entry.Image.HubLink }}){{ else }}**{{ .Entry.Image }}**{{ end }} - which you subscribed to through {{ .Entry.Provider }} provider has been {{ if (eq .Entry.Status "new") }}newly added{{ else }}updated{{ end }} - on {{ .Meta.Hostname }}. + which you subscribed to through {{ .Entry.Provider }} provider {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ end }} + on {{ .Entry.Image.Domain }} registry (triggered by {{ .Meta.Hostname }} host). theme: name: material