Skip to content

Commit

Permalink
Add param for sendReleaseDescription
Browse files Browse the repository at this point in the history
Signed-off-by: zvlb <[email protected]>
  • Loading branch information
zvlb committed May 29, 2024
1 parent 14a596d commit 49c57d2
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
4 changes: 2 additions & 2 deletions helm/charts/release-watcher/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: release-watcher
description: A Helm chart to install Release Watcher
type: application
version: 0.0.8
appVersion: "v0.0.8"
version: 0.0.9
appVersion: "v0.0.9"

home: https://github.com/zvlb/release-watcher
sources:
Expand Down
2 changes: 2 additions & 0 deletions helm/charts/release-watcher/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ data:
hook: "{{ .hook }}"
{{- end }}
{{- end }}
params:
sendReleaseDescription: {{ .Values.params.sendReleaseDescription }}
6 changes: 5 additions & 1 deletion helm/charts/release-watcher/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ releases:
recievers:
telegram: []
# - chatID: "-0000000"
# token: <TOKEN>
# token: <TOKEN>
slack: []

params:
sendReleaseDescription: false
29 changes: 21 additions & 8 deletions helm/index.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
apiVersion: v1
entries:
release-watcher:
- apiVersion: v2
appVersion: v0.0.9
created: "2024-05-29T11:36:43.641089+03:00"
description: A Helm chart to install Release Watcher
digest: 30cbfe7ed31b18faf154800129f845b9f48ccfae8c8825c2ceab2b5124dbff83
home: https://github.com/zvlb/release-watcher
name: release-watcher
sources:
- https://github.com/zvlb/release-watcher
type: application
urls:
- https://zvlb.github.io/release-watcher/helm/packages/release-watcher-0.0.9.tgz
version: 0.0.9
- apiVersion: v2
appVersion: v0.0.8
created: "2024-01-19T12:48:55.435359+02:00"
created: "2024-05-29T11:36:43.640882+03:00"
description: A Helm chart to install Release Watcher
digest: 3fdb533f051824c747a7dc2f95fdcb4aa68ab6a5c22878af715af7c28e00922e
home: https://github.com/zvlb/release-watcher
Expand All @@ -16,7 +29,7 @@ entries:
version: 0.0.8
- apiVersion: v2
appVersion: v0.0.6
created: "2024-01-19T12:48:55.435161+02:00"
created: "2024-05-29T11:36:43.640666+03:00"
description: A Helm chart to install Release Watcher
digest: 042630c6521f340a6ac5ef56444f254f0e845a5214172647ec5f099182e0f93e
home: https://github.com/zvlb/release-watcher
Expand All @@ -29,7 +42,7 @@ entries:
version: 0.0.7
- apiVersion: v2
appVersion: v0.0.6
created: "2024-01-19T12:48:55.434836+02:00"
created: "2024-05-29T11:36:43.640456+03:00"
description: A Helm chart to install Release Watcher
digest: a7c022532fdd40c9ebae0154df34eedd94886c44751be71d8a1eb606ce4a2913
home: https://github.com/zvlb/release-watcher
Expand All @@ -42,7 +55,7 @@ entries:
version: 0.0.6
- apiVersion: v2
appVersion: v0.0.5
created: "2024-01-19T12:48:55.434342+02:00"
created: "2024-05-29T11:36:43.64024+03:00"
description: A Helm chart to install Release Watcher
digest: 3e8a838a93411cf38f875d3e28ce8655f0257144a469cbd8262ec517ef369401
home: https://github.com/zvlb/release-watcher
Expand All @@ -55,7 +68,7 @@ entries:
version: 0.0.5
- apiVersion: v2
appVersion: v0.0.4
created: "2024-01-19T12:48:55.434+02:00"
created: "2024-05-29T11:36:43.640046+03:00"
description: A Helm chart to install Release Watcher
digest: 1e21c2888632e88db613e8eed2250b401d3856d9c4379a4ec5f88fcf6b313d68
home: https://github.com/zvlb/release-watcher
Expand All @@ -68,7 +81,7 @@ entries:
version: 0.0.4
- apiVersion: v2
appVersion: v0.0.3
created: "2024-01-19T12:48:55.433614+02:00"
created: "2024-05-29T11:36:43.639827+03:00"
description: A Helm chart to install Release Watcher
digest: aacda75b2ded0f734c3d20eea3fd94d2783f98337697273a7a96801705e006b4
home: https://github.com/zvlb/release-watcher
Expand All @@ -81,7 +94,7 @@ entries:
version: 0.0.2
- apiVersion: v2
appVersion: v0.0.1
created: "2024-01-19T12:48:55.433018+02:00"
created: "2024-05-29T11:36:43.639584+03:00"
description: A Helm chart to install Release Watcher
digest: 3d316c53a0a466847d6f336d18241c2f2a1b6edfcd10c6686d53079ea2368005
home: https://github.com/zvlb/release-watcher
Expand All @@ -92,4 +105,4 @@ entries:
urls:
- https://zvlb.github.io/release-watcher/helm/packages/release-watcher-0.0.1.tgz
version: 0.0.1
generated: "2024-01-19T12:48:55.432305+02:00"
generated: "2024-05-29T11:36:43.638936+03:00"
Binary file added helm/packages/release-watcher-0.0.9.tgz
Binary file not shown.
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type Config struct {
Releases Releases `yaml:"releases"`
Recievers Recievers `yaml:"recievers"`
Params Params `yaml:params`
}

type Releases struct {
Expand All @@ -30,6 +31,10 @@ type TelegramReciever struct {
Token string `yaml:"token"`
}

type Params struct {
SendReleaseDescription bool `yaml:"sendReleaseDescription"`
}

func GetConfiguration(path string) (Config, error) {
var config Config

Expand Down
12 changes: 10 additions & 2 deletions internal/recievers/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"

"github.com/zvlb/release-watcher/internal/config"
"github.com/zvlb/release-watcher/internal/recievers"
)

Expand All @@ -18,12 +19,14 @@ var (
type SlackReciever struct {
ChannelName string `yaml:"channelName"`
Hook string `yaml:"hook"`
Config config.Config
}

func New(channelname, hook string) recievers.Reciever {
func New(channelname, hook string, config config.Config) recievers.Reciever {
return &SlackReciever{
ChannelName: channelname,
Hook: hook,
Config: config,
}
}

Expand All @@ -34,7 +37,12 @@ func (sr *SlackReciever) GetName() string {
func (sr *SlackReciever) SendData(name, release, description, link string) error {
url := fmt.Sprintf("%v", sr.Hook) //??????

text := fmt.Sprintf("%v. Release: %v\n%v\n\n%v", name, release, description, link)
var text string
if sr.Config.Params.SendReleaseDescription {
text = fmt.Sprintf("%v. Release: %v\n%v\n\n%v", name, release, description, link)
} else {
text = fmt.Sprintf("%v. Release: %v\n%v", name, release, link)
}

body, err := json.Marshal(map[string]string{
"text": text,
Expand Down
12 changes: 10 additions & 2 deletions internal/recievers/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"

"github.com/zvlb/release-watcher/internal/config"
"github.com/zvlb/release-watcher/internal/recievers"
)

Expand All @@ -16,12 +17,14 @@ var (
type TelegramReciever struct {
Token string `yaml:"token"`
ChatID string `yaml:"chatID"`
Config config.Config
}

func New(token, chatID string) recievers.Reciever {
func New(token, chatID string, config config.Config) recievers.Reciever {
return &TelegramReciever{
Token: token,
ChatID: chatID,
Config: config,
}
}

Expand All @@ -32,7 +35,12 @@ func (tr *TelegramReciever) GetName() string {
func (tr *TelegramReciever) SendData(name, release, description, link string) error {
url := fmt.Sprintf("%v%v/%v", telegramAPI, tr.Token, "sendMessage")

text := fmt.Sprintf("<b>%v</b>. Release: <b>%v</b>\n%v\n\n%v", name, release, description, link)
var text string
if tr.Config.Params.SendReleaseDescription {
text = fmt.Sprintf("<b>%v</b>. Release: <b>%v</b>\n%v\n\n%v", name, release, description, link)
} else {
text = fmt.Sprintf("<b>%v</b>. Release: <b>%v</b>\n%v", name, release, link)
}

body, err := json.Marshal(map[string]string{
"chat_id": tr.ChatID,
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func generateRecievers(cfg config.Config) []recievers.Reciever {

// Get telegram Recievers
for _, t := range cfg.Recievers.Telegram {
r := telegram.New(t.Token, t.ChatID)
r := telegram.New(t.Token, t.ChatID, cfg)
recievers = append(recievers, r)
}
// Get slack Recievers
for _, t := range cfg.Recievers.Slack {
r := slack.New(t.ChannelName, t.Hook)
r := slack.New(t.ChannelName, t.Hook, cfg)
recievers = append(recievers, r)
}
return recievers
Expand Down

0 comments on commit 49c57d2

Please sign in to comment.