From 3d63ed4790dff5eecd7f9d962284a9e46caff10b Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Thu, 16 Apr 2026 11:55:54 +0200 Subject: [PATCH] chore: test old --- main.go | 98 +++---------------------------------------------- main_test.go | 9 ++--- message.tpl | 55 +++++++++++++++++++++++++++ message_old.tpl | 35 ++++++++++++++++++ 4 files changed, 98 insertions(+), 99 deletions(-) create mode 100644 message.tpl create mode 100644 message_old.tpl diff --git a/main.go b/main.go index 56a2ade..75b1dd3 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + _ "embed" "fmt" "net/http" "os" @@ -16,6 +17,9 @@ const ( failedColor = "8b0000/dc143c" ) +//go:embed message_old.tpl +var message string + type templateData struct { Title string SubTitle string @@ -139,43 +143,6 @@ func card(d templateData) ([]byte, error) { d.EventBody = "Project: {{ .Project }}
Commit-id: {{ .Commit }}
Branch: {{ .Branch }}
Build Status: {{ .Status }}" } - // tpl := ` - //{ - // "cards": [ - // { - // "header": { - // "title": "{{ .Title }}", - // "subtitle": "{{ .SubTitle }}", - // "imageUrl": "{{ .IconUrl }}", - // "imageStyle": "IMAGE" - // }, - // "sections": [ - // { - // "widgets": [ - // { - // "textParagraph": { - // "text": "Project: {{ .Project }}
Commit-id: {{ .Commit }}
Branch: {{ .Branch }}
Build Status: {{ .Status }}" - // }, - // "buttons": [ - // { - // "textButton": { - // "text": "Job Details", - // "onClick": { - // "openLink": { - // "url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}" - // } - // } - // } - // } - // ] - // } - // ] - // } - // ] - // } - // ] - //}` - if d.Status == "success" { d.Add = ` { @@ -204,62 +171,7 @@ func card(d templateData) ([]byte, error) { },` } - tpl := ` - { - "cardsV2": [ - { - "cardId": "notify-{{ .ActionID }}", - "card": { - "header": { - "title": "{{ .Title }}", - "subtitle": "{{ .SubTitle }}", - "imageUrl": "{{ .IconUrl }}", - "imageType": "SQUARE" - }, - "sections": [ - { - "header": "{{ .Title }}", - "collapsible": false, - "widgets": [ - {{ .Add }} - { - "decoratedText": { - "startIcon": { - "knownIcon": "PERSON" - }, - "text": "{{ .Author }}" - } - }, - { - "textParagraph": { - "text": "{{ .EventBody }}", - "maxLines": 2 - } - }, - { - "buttonList": { - "buttons": [ - { - "text": "View Source Event", - "type": "FILLED", - "onClick": { - "openLink": { - "url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}" - } - } - } - ] - } - } - ] - } - ] - } - } - ] - } - ` - tmpl, err := template.New("").Parse(tpl) + tmpl, err := template.New("message").Parse(message) if err != nil { return nil, err } diff --git a/main_test.go b/main_test.go index c7bcd29..0798bd4 100644 --- a/main_test.go +++ b/main_test.go @@ -50,7 +50,8 @@ func Test_card(t *testing.T) { "sections": [ { "header": "test", - "collapsible": false, + "collapsible": true, + "uncollapsibleWidgetsCount": 2, "widgets": [ { @@ -76,11 +77,7 @@ func Test_card(t *testing.T) { "text": "no body", "maxLines": 2 } - } - ] - }, - { - "widgets": [ + }, { "buttonList": { "buttons": [ diff --git a/message.tpl b/message.tpl new file mode 100644 index 0000000..68eb5e2 --- /dev/null +++ b/message.tpl @@ -0,0 +1,55 @@ +{ + "cardsV2": [ + { + "cardId": "notify-{{ .ActionID }}", + "card": { + "header": { + "title": "{{ .Title }}", + "subtitle": "{{ .SubTitle }}", + "imageUrl": "{{ .IconUrl }}", + "imageType": "SQUARE" + }, + "sections": [ + { + "header": "{{ .Title }}", + "collapsible": true, + "uncollapsibleWidgetsCount": 2, + "widgets": [ + {{ .Add }} + { + "decoratedText": { + "startIcon": { + "knownIcon": "PERSON" + }, + "text": "{{ .Author }}" + } + }, + { + "textParagraph": { + "text": "{{ .EventBody }}", + "maxLines": 2 + } + }, + { + "buttonList": { + "buttons": [ + { + "text": "View Source Event", + "type": "FILLED", + "onClick": { + "openLink": { + "url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}" + } + } + } + ] + } + } + ] + } + ] + } + } + ] +} + \ No newline at end of file diff --git a/message_old.tpl b/message_old.tpl new file mode 100644 index 0000000..9a57795 --- /dev/null +++ b/message_old.tpl @@ -0,0 +1,35 @@ +{ + "cards": [ + { + "header": { + "title": "{{ .Title }}", + "subtitle": "{{ .SubTitle }}", + "imageUrl": "{{ .IconUrl }}", + "imageStyle": "IMAGE" + }, + "sections": [ + { + "widgets": [ + { + "textParagraph": { + "text": "Project: {{ .Project }}
Commit-id: {{ .Commit }}
Branch: {{ .Branch }}
Build Status: {{ .Status }}" + }, + "buttons": [ + { + "textButton": { + "text": "Job Details", + "onClick": { + "openLink": { + "url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}" + } + } + } + } + ] + } + ] + } + ] + } + ] +}