-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
95 lines (77 loc) · 1.83 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
87
88
89
90
91
92
93
94
95
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
v, err := NewValidator()
if err != nil {
log.Panic(err)
}
c, err := NewConfig(v)
if err != nil {
log.Panicln(err)
}
descriptionParts := []DescriptionPart{
{
Name: "Repository",
Value: fmt.Sprintf("[%s](%s)", c.GitHubRepository, c.GetRepositoryUrl()),
},
}
descriptionParts = append(descriptionParts, DescriptionPart{
Name: "Workflow",
Value: c.GitHubWorkflow,
})
if c.GitHubJobName != "" {
descriptionParts = append(descriptionParts, DescriptionPart{
Name: "Job name",
Value: c.GitHubJobName,
})
}
if c.GitHubRef != "" {
descriptionParts = append(descriptionParts, DescriptionPart{
Name: "Ref",
Value: c.GitHubRef,
})
}
if c.GitHubActor != "" {
descriptionParts = append(descriptionParts, DescriptionPart{
Name: "Author",
Value: c.GitHubActor,
})
}
descriptionParts = append(descriptionParts, DescriptionPart{
Name: "Commit",
Value: fmt.Sprintf("[%s](%s)", c.GitHubSha, c.GetCommitUrl()),
})
embed := map[string]string{
"description": GetDescription(descriptionParts),
}
runUrl := c.GetRunUrl()
if runUrl != "" {
embed["url"] = runUrl
}
if c.GitHubJobStatus == "success" {
embed["title"] = "Action is successful."
} else if c.GitHubJobStatus == "failure" {
embed["title"] = "Action has failed."
} else if c.GitHubJobStatus == "cancelled" {
embed["title"] = "Action is cancelled."
}
payload := map[string]interface{}{
"embeds": []map[string]string{embed},
}
payloadByte, err := json.Marshal(payload)
req, err := http.NewRequest(http.MethodPost, c.DiscordWebhookUrl, bytes.NewBuffer(payloadByte))
if err != nil {
log.Panicln(err)
}
req.Header.Set("content-type", "application/json")
_, err = http.DefaultClient.Do(req)
if err != nil {
log.Panicln(err)
}
}