This commit is contained in:
parent
d9828186fd
commit
3d63ed4790
4 changed files with 98 additions and 99 deletions
98
main.go
98
main.go
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -16,6 +17,9 @@ const (
|
||||||
failedColor = "8b0000/dc143c"
|
failedColor = "8b0000/dc143c"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed message_old.tpl
|
||||||
|
var message string
|
||||||
|
|
||||||
type templateData struct {
|
type templateData struct {
|
||||||
Title string
|
Title string
|
||||||
SubTitle string
|
SubTitle string
|
||||||
|
|
@ -139,43 +143,6 @@ func card(d templateData) ([]byte, error) {
|
||||||
d.EventBody = "<b>Project:</b> {{ .Project }}<br><b>Commit-id:</b> <font color=\"#FF0000\">{{ .Commit }}</font><br><b>Branch:</b> <font color=\"#00FF00f\">{{ .Branch }}</font><br><b>Build Status:</b> <font color=\"#0000ff\">{{ .Status }}</font>"
|
d.EventBody = "<b>Project:</b> {{ .Project }}<br><b>Commit-id:</b> <font color=\"#FF0000\">{{ .Commit }}</font><br><b>Branch:</b> <font color=\"#00FF00f\">{{ .Branch }}</font><br><b>Build Status:</b> <font color=\"#0000ff\">{{ .Status }}</font>"
|
||||||
}
|
}
|
||||||
|
|
||||||
// tpl := `
|
|
||||||
//{
|
|
||||||
// "cards": [
|
|
||||||
// {
|
|
||||||
// "header": {
|
|
||||||
// "title": "{{ .Title }}",
|
|
||||||
// "subtitle": "{{ .SubTitle }}",
|
|
||||||
// "imageUrl": "{{ .IconUrl }}",
|
|
||||||
// "imageStyle": "IMAGE"
|
|
||||||
// },
|
|
||||||
// "sections": [
|
|
||||||
// {
|
|
||||||
// "widgets": [
|
|
||||||
// {
|
|
||||||
// "textParagraph": {
|
|
||||||
// "text": "<b>Project:</b> {{ .Project }}<br><b>Commit-id:</b> <font color=\"#FF0000\">{{ .Commit }}</font><br><b>Branch:</b> <font color=\"#00FF00f\">{{ .Branch }}</font><br><b>Build Status:</b> <font color=\"#0000ff\">{{ .Status }}</font>"
|
|
||||||
// },
|
|
||||||
// "buttons": [
|
|
||||||
// {
|
|
||||||
// "textButton": {
|
|
||||||
// "text": "Job Details",
|
|
||||||
// "onClick": {
|
|
||||||
// "openLink": {
|
|
||||||
// "url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
//}`
|
|
||||||
|
|
||||||
if d.Status == "success" {
|
if d.Status == "success" {
|
||||||
d.Add = `
|
d.Add = `
|
||||||
{
|
{
|
||||||
|
|
@ -204,62 +171,7 @@ func card(d templateData) ([]byte, error) {
|
||||||
},`
|
},`
|
||||||
}
|
}
|
||||||
|
|
||||||
tpl := `
|
tmpl, err := template.New("message").Parse(message)
|
||||||
{
|
|
||||||
"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": "<b>{{ .Author }}</b>"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ func Test_card(t *testing.T) {
|
||||||
"sections": [
|
"sections": [
|
||||||
{
|
{
|
||||||
"header": "test",
|
"header": "test",
|
||||||
"collapsible": false,
|
"collapsible": true,
|
||||||
|
"uncollapsibleWidgetsCount": 2,
|
||||||
"widgets": [
|
"widgets": [
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -76,11 +77,7 @@ func Test_card(t *testing.T) {
|
||||||
"text": "no body",
|
"text": "no body",
|
||||||
"maxLines": 2
|
"maxLines": 2
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"widgets": [
|
|
||||||
{
|
{
|
||||||
"buttonList": {
|
"buttonList": {
|
||||||
"buttons": [
|
"buttons": [
|
||||||
|
|
|
||||||
55
message.tpl
Normal file
55
message.tpl
Normal file
|
|
@ -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": "<b>{{ .Author }}</b>"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"textParagraph": {
|
||||||
|
"text": "{{ .EventBody }}",
|
||||||
|
"maxLines": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"buttonList": {
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"text": "View Source Event",
|
||||||
|
"type": "FILLED",
|
||||||
|
"onClick": {
|
||||||
|
"openLink": {
|
||||||
|
"url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
35
message_old.tpl
Normal file
35
message_old.tpl
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"cards": [
|
||||||
|
{
|
||||||
|
"header": {
|
||||||
|
"title": "{{ .Title }}",
|
||||||
|
"subtitle": "{{ .SubTitle }}",
|
||||||
|
"imageUrl": "{{ .IconUrl }}",
|
||||||
|
"imageStyle": "IMAGE"
|
||||||
|
},
|
||||||
|
"sections": [
|
||||||
|
{
|
||||||
|
"widgets": [
|
||||||
|
{
|
||||||
|
"textParagraph": {
|
||||||
|
"text": "<b>Project:</b> {{ .Project }}<br><b>Commit-id:</b> <font color=\"#FF0000\">{{ .Commit }}</font><br><b>Branch:</b> <font color=\"#00FF00f\">{{ .Branch }}</font><br><b>Build Status:</b> <font color=\"#0000ff\">{{ .Status }}</font>"
|
||||||
|
},
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"textButton": {
|
||||||
|
"text": "Job Details",
|
||||||
|
"onClick": {
|
||||||
|
"openLink": {
|
||||||
|
"url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue