This commit is contained in:
parent
f2566ae21d
commit
0303b4b9aa
3 changed files with 232 additions and 90 deletions
179
main.go
179
main.go
|
|
@ -99,7 +99,7 @@ func main() {
|
|||
|
||||
jsonStr, err := card(data)
|
||||
if err != nil {
|
||||
githubactions.Fatalf(err.Error())
|
||||
githubactions.Fatalf("error %s", err.Error())
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr))
|
||||
|
|
@ -134,40 +134,41 @@ 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>"
|
||||
}
|
||||
|
||||
//data := `{
|
||||
// "cards": [
|
||||
// tpl := `
|
||||
//{
|
||||
// "cards": [
|
||||
// {
|
||||
// "header": {
|
||||
// "title": "{{ .Title }}",
|
||||
// "subtitle": "{{ .SubTitle }}",
|
||||
// "imageUrl": "{{ .IconUrl }}",
|
||||
// "imageStyle": "IMAGE"
|
||||
// },
|
||||
// "sections": [
|
||||
// {
|
||||
// "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": [
|
||||
// {
|
||||
// "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 }}"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// "textButton": {
|
||||
// "text": "Job Details",
|
||||
// "onClick": {
|
||||
// "openLink": {
|
||||
// "url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
//}`
|
||||
|
||||
if d.Status == "success" {
|
||||
|
|
@ -199,64 +200,64 @@ 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": "<b>{{ .Author }}</b>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"textParagraph": {
|
||||
"text": "{{ .EventBody }}",
|
||||
"maxLines": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgets": [
|
||||
{
|
||||
"buttonList": {
|
||||
"buttons": [
|
||||
{
|
||||
"text": "View Source Event",
|
||||
"type": "FILLED",
|
||||
"onClick": {
|
||||
"openLink": {
|
||||
"url": "{{ .GitURL }}/{{ .Project }}/actions/runs/{{ .ActionID }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgets": [
|
||||
{
|
||||
"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 {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue