Option to render fields (#480)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-09-04 18:41:42 +02:00
committed by GitHub
parent fe8482999c
commit fc64b132ff
19 changed files with 202 additions and 164 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -15,8 +15,8 @@ Allow to send notifications to your Discord channel.
- "<@124>" - "<@124>"
- "<@125>" - "<@125>"
- "<@&200>" - "<@&200>"
renderFields: true
timeout: 10s timeout: 10s
templateTitle: "{{ .Entry.Image }} released"
templateBody: | templateBody: |
Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released. 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) | | `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 | | `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 | | `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 | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body |
!!! abstract "Environment variables" !!! abstract "Environment variables"
* `DIUN_NOTIF_DISCORD_WEBHOOKURL` * `DIUN_NOTIF_DISCORD_WEBHOOKURL`
* `DIUN_NOTIF_DISCORD_MENTIONS` (comma separated) * `DIUN_NOTIF_DISCORD_MENTIONS` (comma separated)
* `DIUN_NOTIF_DISCORD_RENDERFIELDS`
* `DIUN_NOTIF_DISCORD_TIMEOUT` * `DIUN_NOTIF_DISCORD_TIMEOUT`
* `DIUN_NOTIF_DISCORD_TEMPLATETITLE`
* `DIUN_NOTIF_DISCORD_TEMPLATEBODY` * `DIUN_NOTIF_DISCORD_TEMPLATEBODY`
### Default `templateTitle`
```
[[ config.extra.template.defaultTitle ]]
```
### Default `templateBody` ### Default `templateBody`
``` ```

View File

@@ -12,6 +12,7 @@ Allow to send notifications to your Rocket.Chat channel.
channel: "#general" channel: "#general"
userID: abcdEFGH012345678 userID: abcdEFGH012345678
token: Token123456 token: Token123456
renderAttachment: true
timeout: 10s timeout: 10s
templateTitle: "{{ .Entry.Image }} released" templateTitle: "{{ .Entry.Image }} released"
templateBody: | templateBody: |
@@ -25,6 +26,7 @@ Allow to send notifications to your Rocket.Chat channel.
| `userID`[^1] | | User ID | | `userID`[^1] | | User ID |
| `token` | | Authentication token | | `token` | | Authentication token |
| `tokenFile` | | Use content of secret file as authentication token if `token` not defined | | `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 | | `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 | | `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 | | `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_USERID`
* `DIUN_NOTIF_ROCKETCHAT_TOKEN` * `DIUN_NOTIF_ROCKETCHAT_TOKEN`
* `DIUN_NOTIF_ROCKETCHAT_TOKENFILE` * `DIUN_NOTIF_ROCKETCHAT_TOKENFILE`
* `DIUN_NOTIF_ROCKETCHAT_RENDERATTACHMENT`
* `DIUN_NOTIF_ROCKETCHAT_TIMEOUT` * `DIUN_NOTIF_ROCKETCHAT_TIMEOUT`
* `DIUN_NOTIF_ROCKETCHAT_TEMPLATETITLE` * `DIUN_NOTIF_ROCKETCHAT_TEMPLATETITLE`
* `DIUN_NOTIF_ROCKETCHAT_TEMPLATEBODY` * `DIUN_NOTIF_ROCKETCHAT_TEMPLATEBODY`

View File

@@ -12,6 +12,7 @@ You can send notifications to your Slack channel using an [incoming webhook URL]
notif: notif:
slack: slack:
webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij
renderFields: true
templateBody: | templateBody: |
Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released. 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 | | Name | Default | Description |
|--------------------|--------------------------------------------|---------------| |--------------------|--------------------------------------------|---------------|
| `webhookURL`[^1] | | Slack [incoming webhook URL](https://api.slack.com/messaging/webhooks) | | `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 | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body |
!!! abstract "Environment variables" !!! abstract "Environment variables"
* `DIUN_NOTIF_SLACK_WEBHOOKURL` * `DIUN_NOTIF_SLACK_WEBHOOKURL`
* `DIUN_NOTIF_SLACK_RENDERFIELDS`
* `DIUN_NOTIF_SLACK_TEMPLATEBODY` * `DIUN_NOTIF_SLACK_TEMPLATEBODY`
### Default `templateBody` ### Default `templateBody`
``` ```
<!channel> Docker tag `{{ .Entry.Image }}` {{ if (eq .Entry.Status "new") }}newly added{{ else }}updated{{ end }}. <!channel> 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 ## Sample

View File

@@ -9,6 +9,7 @@ You can send notifications to your Teams team-channel using an [incoming webhook
notif: notif:
teams: teams:
webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij
renderFacts: true
templateBody: | templateBody: |
Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released. 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 | | 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) | | `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 | | `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body |
!!! abstract "Environment variables" !!! abstract "Environment variables"
* `DIUN_NOTIF_TEAMS_WEBHOOKURL` * `DIUN_NOTIF_TEAMS_WEBHOOKURL`
* `DIUN_NOTIF_TEAMS_RENDERFACTS`
* `DIUN_NOTIF_TEAMS_TEMPLATEBODY` * `DIUN_NOTIF_TEAMS_TEMPLATEBODY`
### Default `templateBody` ### Default `templateBody`

View File

@@ -76,8 +76,8 @@ func TestLoadFile(t *testing.T) {
"<@125>", "<@125>",
"<@&200>", "<@&200>",
}, },
RenderFields: utl.NewTrue(),
Timeout: utl.NewDuration(10 * time.Second), Timeout: utl.NewDuration(10 * time.Second),
TemplateTitle: model.NotifDefaultTemplateTitle,
TemplateBody: model.NotifDefaultTemplateBody, TemplateBody: model.NotifDefaultTemplateBody,
}, },
Gotify: &model.NotifGotify{ Gotify: &model.NotifGotify{
@@ -137,6 +137,7 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
Channel: "#general", Channel: "#general",
UserID: "abcdEFGH012345678", UserID: "abcdEFGH012345678",
Token: "Token123456", Token: "Token123456",
RenderAttachment: utl.NewTrue(),
Timeout: utl.NewDuration(10 * time.Second), Timeout: utl.NewDuration(10 * time.Second),
TemplateTitle: model.NotifDefaultTemplateTitle, TemplateTitle: model.NotifDefaultTemplateTitle,
TemplateBody: model.NotifRocketChatDefaultTemplateBody, TemplateBody: model.NotifRocketChatDefaultTemplateBody,
@@ -149,10 +150,12 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
}, },
Slack: &model.NotifSlack{ Slack: &model.NotifSlack{
WebhookURL: "https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij", WebhookURL: "https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij",
RenderFields: utl.NewFalse(),
TemplateBody: model.NotifSlackDefaultTemplateBody, TemplateBody: model.NotifSlackDefaultTemplateBody,
}, },
Teams: &model.NotifTeams{ Teams: &model.NotifTeams{
WebhookURL: "https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij", WebhookURL: "https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij",
RenderFacts: utl.NewFalse(),
TemplateBody: model.NotifTeamsDefaultTemplateBody, TemplateBody: model.NotifTeamsDefaultTemplateBody,
}, },
Telegram: &model.NotifTelegram{ Telegram: &model.NotifTelegram{

View File

@@ -25,6 +25,7 @@ notif:
- "<@124>" - "<@124>"
- "<@125>" - "<@125>"
- "<@&200>" - "<@&200>"
renderFields: true
timeout: 10s timeout: 10s
gotify: gotify:
endpoint: http://gotify.foo.com endpoint: http://gotify.foo.com
@@ -69,6 +70,7 @@ notif:
channel: "#general" channel: "#general"
userID: abcdEFGH012345678 userID: abcdEFGH012345678
token: Token123456 token: Token123456
renderAttachment: true
timeout: 10s timeout: 10s
script: script:
cmd: "uname" cmd: "uname"
@@ -76,8 +78,10 @@ notif:
- "-a" - "-a"
slack: slack:
webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij
renderFields: false
teams: teams:
webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij
renderFacts: false
telegram: telegram:
token: abcdef123456 token: abcdef123456
chatIDs: chatIDs:

View File

@@ -25,6 +25,7 @@ notif:
- "<@124>" - "<@124>"
- "<@125>" - "<@125>"
- "<@&200>" - "<@&200>"
renderFields: true
timeout: 10s timeout: 10s
gotify: gotify:
endpoint: http://gotify.foo.com endpoint: http://gotify.foo.com
@@ -67,6 +68,7 @@ notif:
channel: "#general" channel: "#general"
userID: abcdEFGH012345678 userID: abcdEFGH012345678
token: Token123456 token: Token123456
renderAttachment: false
timeout: 10s timeout: 10s
script: script:
cmd: "uname" cmd: "uname"
@@ -74,8 +76,10 @@ notif:
- "-a" - "-a"
slack: slack:
webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij webhookURL: https://hooks.slack.com/services/ABCD12EFG/HIJK34LMN/01234567890abcdefghij
renderFields: false
teams: teams:
webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij webhookURL: https://outlook.office.com/webhook/ABCD12EFG/HIJK34LMN/01234567890abcdefghij
renderFacts: true
telegram: telegram:
token: abcdef123456 token: abcdef123456
chatIDs: chatIDs:

View File

@@ -10,8 +10,8 @@ import (
type NotifDiscord struct { type NotifDiscord struct {
WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"`
Mentions []string `yaml:"mentions,omitempty" json:"mentions,omitempty"` 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"` 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"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
} }
@@ -24,7 +24,7 @@ func (s *NotifDiscord) GetDefaults() *NotifDiscord {
// SetDefaults sets the default values // SetDefaults sets the default values
func (s *NotifDiscord) SetDefaults() { func (s *NotifDiscord) SetDefaults() {
s.RenderFields = utl.NewTrue()
s.Timeout = utl.NewDuration(10 * time.Second) s.Timeout = utl.NewDuration(10 * time.Second)
s.TemplateTitle = NotifDefaultTemplateTitle
s.TemplateBody = NotifDefaultTemplateBody s.TemplateBody = NotifDefaultTemplateBody
} }

View File

@@ -16,6 +16,7 @@ type NotifRocketChat struct {
UserID string `yaml:"userID,omitempty" json:"userID,omitempty" validate:"required"` UserID string `yaml:"userID,omitempty" json:"userID,omitempty" validate:"required"`
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"` Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"`
TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"` 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"` Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"` TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"`
TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
@@ -30,6 +31,7 @@ func (s *NotifRocketChat) GetDefaults() *NotifRocketChat {
// SetDefaults sets the default values // SetDefaults sets the default values
func (s *NotifRocketChat) SetDefaults() { func (s *NotifRocketChat) SetDefaults() {
s.RenderAttachment = utl.NewTrue()
s.Timeout = utl.NewDuration(10 * time.Second) s.Timeout = utl.NewDuration(10 * time.Second)
s.TemplateTitle = NotifDefaultTemplateTitle s.TemplateTitle = NotifDefaultTemplateTitle
s.TemplateBody = NotifRocketChatDefaultTemplateBody s.TemplateBody = NotifRocketChatDefaultTemplateBody

View File

@@ -1,11 +1,14 @@
package model package model
import "github.com/crazy-max/diun/v4/pkg/utl"
// NotifSlackDefaultTemplateBody ... // NotifSlackDefaultTemplateBody ...
const NotifSlackDefaultTemplateBody = "<!channel> Docker tag `{{ .Entry.Image }}` {{ if (eq .Entry.Status \"new\") }}available{{ else }}updated{{ end }}." const NotifSlackDefaultTemplateBody = "<!channel> 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 // NotifSlack holds slack notification configuration details
type NotifSlack struct { type NotifSlack struct {
WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` 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"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
} }
@@ -18,5 +21,6 @@ func (s *NotifSlack) GetDefaults() *NotifSlack {
// SetDefaults sets the default values // SetDefaults sets the default values
func (s *NotifSlack) SetDefaults() { func (s *NotifSlack) SetDefaults() {
s.RenderFields = utl.NewTrue()
s.TemplateBody = NotifSlackDefaultTemplateBody s.TemplateBody = NotifSlackDefaultTemplateBody
} }

View File

@@ -1,11 +1,14 @@
package model package model
import "github.com/crazy-max/diun/v4/pkg/utl"
// NotifTeamsDefaultTemplateBody ... // 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 }}." 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 // NotifTeams holds Teams notification configuration details
type NotifTeams struct { type NotifTeams struct {
WebhookURL string `yaml:"webhookURL,omitempty" json:"webhookURL,omitempty" validate:"required"` 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"` TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
} }
@@ -18,5 +21,6 @@ func (s *NotifTeams) GetDefaults() *NotifTeams {
// SetDefaults sets the default values // SetDefaults sets the default values
func (s *NotifTeams) SetDefaults() { func (s *NotifTeams) SetDefaults() {
s.RenderFacts = utl.NewTrue()
s.TemplateBody = NotifTeamsDefaultTemplateBody s.TemplateBody = NotifTeamsDefaultTemplateBody
} }

View File

@@ -47,14 +47,13 @@ func (c *Client) Send(entry model.NotifEntry) error {
message, err := msg.New(msg.Options{ message, err := msg.New(msg.Options{
Meta: c.meta, Meta: c.meta,
Entry: entry, Entry: entry,
TemplateTitle: c.cfg.TemplateTitle,
TemplateBody: c.cfg.TemplateBody, TemplateBody: c.cfg.TemplateBody,
}) })
if err != nil { if err != nil {
return err return err
} }
title, body, err := message.RenderMarkdown() _, body, err := message.RenderMarkdown()
if err != nil { if err != nil {
return err return err
} }
@@ -64,9 +63,11 @@ func (c *Client) Send(entry model.NotifEntry) error {
content.WriteString(fmt.Sprintf("%s ", mention)) content.WriteString(fmt.Sprintf("%s ", mention))
} }
} }
content.WriteString(string(title)) content.WriteString(string(body))
fields := []EmbedField{ var fields []EmbedField
if *c.cfg.RenderFields {
fields = []EmbedField{
{ {
Name: "Hostname", Name: "Hostname",
Value: c.meta.Hostname, Value: c.meta.Hostname,
@@ -94,6 +95,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
Value: entry.Image.HubLink, Value: entry.Image.HubLink,
}) })
} }
}
dataBuf := new(bytes.Buffer) dataBuf := new(bytes.Buffer)
if err := json.NewEncoder(dataBuf).Encode(Message{ if err := json.NewEncoder(dataBuf).Encode(Message{
@@ -102,17 +104,15 @@ func (c *Client) Send(entry model.NotifEntry) error {
AvatarURL: c.meta.Logo, AvatarURL: c.meta.Logo,
Embeds: []Embed{ 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{ Author: EmbedAuthor{
Name: c.meta.Name, Name: c.meta.Name,
URL: c.meta.URL, URL: c.meta.URL,
IconURL: c.meta.Logo, IconURL: c.meta.Logo,
}, },
Fields: fields, 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 { }); err != nil {

View File

@@ -66,6 +66,8 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err return err
} }
var attachments []Attachment
if *c.cfg.RenderAttachment {
fields := []AttachmentField{ fields := []AttachmentField{
{ {
Title: "Hostname", Title: "Hostname",
@@ -100,6 +102,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
Short: false, Short: false,
}) })
} }
attachments = append(attachments, Attachment{
Text: string(body),
Ts: json.Number(strconv.FormatInt(time.Now().Unix(), 10)),
Fields: fields,
})
}
dataBuf := new(bytes.Buffer) dataBuf := new(bytes.Buffer)
if err := json.NewEncoder(dataBuf).Encode(Message{ if err := json.NewEncoder(dataBuf).Encode(Message{
@@ -107,13 +115,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
Avatar: c.meta.Logo, Avatar: c.meta.Logo,
Channel: c.cfg.Channel, Channel: c.cfg.Channel,
Text: string(title), Text: string(title),
Attachments: []Attachment{ Attachments: attachments,
{
Text: string(body),
Ts: json.Number(strconv.FormatInt(time.Now().Unix(), 10)),
Fields: fields,
},
},
}); err != nil { }); err != nil {
return err return err
} }

View File

@@ -50,12 +50,9 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err return err
} }
color := "#4caf50" var fields []slack.AttachmentField
if entry.Status == model.ImageStatusUpdate { if *c.cfg.RenderFields {
color = "#0054ca" fields = []slack.AttachmentField{
}
fields := []slack.AttachmentField{
{ {
Title: "Hostname", Title: "Hostname",
Value: c.meta.Hostname, Value: c.meta.Hostname,
@@ -89,6 +86,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
Short: false, Short: false,
}) })
} }
}
color := "#4caf50"
if entry.Status == model.ImageStatusUpdate {
color = "#0054ca"
}
return slack.PostWebhook(c.cfg.WebhookURL, &slack.WebhookMessage{ return slack.PostWebhook(c.cfg.WebhookURL, &slack.WebhookMessage{
Attachments: []slack.Attachment{ Attachments: []slack.Attachment{

View File

@@ -3,6 +3,7 @@ package teams
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"time" "time"
@@ -71,6 +72,17 @@ func (c *Client) Send(entry model.NotifEntry) error {
themeColor = "0076D7" 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 { jsonBody, err := json.Marshal(struct {
Type string `json:"@type"` Type string `json:"@type"`
Context string `json:"@context"` Context string `json:"@context"`
@@ -82,16 +94,13 @@ func (c *Client) Send(entry model.NotifEntry) error {
Context: "https://schema.org/extensions", Context: "https://schema.org/extensions",
ThemeColor: themeColor, ThemeColor: themeColor,
Summary: string(body), Summary: string(body),
Sections: []Sections{{ Sections: []Sections{
{
ActivityTitle: string(body), ActivityTitle: string(body),
ActivitySubtitle: "Provider: " + entry.Provider, ActivitySubtitle: fmt.Sprintf("%s © %d %s %s", c.meta.Author, time.Now().Year(), c.meta.Name, c.meta.Version),
Facts: []Fact{ Facts: facts,
{"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},
}}},
}) })
if err != nil { if err != nil {
return err return err

View File

@@ -24,11 +24,11 @@ extra:
domain: crazymax.dev/diun domain: crazymax.dev/diun
template: template:
defaultTitle: | 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: | defaultBody: |
Docker tag {{ if .Entry.Image.HubLink }}[**{{ .Entry.Image }}**]({{ .Entry.Image.HubLink }}){{ else }}**{{ .Entry.Image }}**{{ end }} 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 }} which you subscribed to through {{ .Entry.Provider }} provider {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ end }}
on {{ .Meta.Hostname }}. on {{ .Entry.Image.Domain }} registry (triggered by {{ .Meta.Hostname }} host).
theme: theme:
name: material name: material