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>"
- "<@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`
```

View File

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

View File

@@ -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`
```
<!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

View File

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

View File

@@ -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 <code>{{ .Entry.Manifest.Platform }}</code> 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 <code>{{ .Entry.Manifest.Platform }}</code> 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{

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,11 +1,14 @@
package model
import "github.com/crazy-max/diun/v4/pkg/utl"
// 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
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
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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