-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
86 lines (82 loc) · 2.69 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"bytes"
"fmt"
"net/http"
"github.com/sethvargo/go-githubactions"
)
func main() {
project := githubactions.GetInput("project")
if project == "" {
githubactions.Fatalf("Missing input 'project'")
}
commit := githubactions.GetInput("commit")
if commit == "" {
githubactions.Fatalf("Missing input 'commit'")
}
branch := githubactions.GetInput("branch")
if branch == "" {
githubactions.Fatalf("Missing input 'branch'")
}
status := githubactions.GetInput("status")
if status == "" {
githubactions.Fatalf("Missing input 'status'")
}
actionid := githubactions.GetInput("actionid")
if actionid == "" {
githubactions.Fatalf("Missing input 'actionid'")
}
webhook := githubactions.GetInput("webhook")
if webhook == "" {
githubactions.Fatalf("Missing input 'webshook'")
}
fmt.Println("URL:> ", webhook)
data := `{
"cards": [
{
"header": {
"title": "GitHub Action",
"subtitle": "Build Job",
"imageUrl": "https://github.githubassets.com/images/modules/logos_page/Octocat.png",
"imageStyle": "IMAGE"
},
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "<b>Project:</b> %s<br><b>Commit-id:</b> <font color=\"#FF0000\">%s</font><br><b>Branch:</b> <font color=\"#00FF00f\">%s</font><br><b>Build Status:</b> <font color=\"#0000ff\">%s</font>"
},
"buttons": [
{
"textButton": {
"text": "Job Details",
"onClick": {
"openLink": {
"url": "https://github.com/%s"
}
}
}
}
]
}
]
}
]
}
]
}`
var jsonStr = []byte(fmt.Sprintf(data, project, commit, branch, status, actionid ))
req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
}