-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (75 loc) · 1.95 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
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)
type Githubstuff struct {
Tag_name string `json:"tag_name"`
Name string `json:"name"`
Body string `json:"body"`
}
func main() {
res, err := http.Get("https://api.github.com/repos/NOCanoa/go-ghaction-test/releases/latest")
if err != nil {
panic(err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
panic(fmt.Sprintf("response status error: %d %s", res.StatusCode, res.Status))
}
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
/* fmt.Println(string(body)) */
var github Githubstuff
err = json.Unmarshal(body, &github)
if err != nil {
panic(err)
}
/* fmt.Print(github.Body) */
webhookURL := "no-webhook"
if len(os.Args) >= 2 {
webhookURL = os.Args[1]
}
message := map[string]interface{}{
"content": "",
"username": "ZenDroid",
"avatar_url": "https://cdn.jsdelivr.net/gh/zen-browser/www/public/logos/zen-alpha-black.png",
"embeds": []map[string]interface{}{
{
"title": "",
"description": "# 🚀 New update " + github.Tag_name + "\r\n \r\n" + github.Body,
"color": 16711680,
"footer": map[string]interface{}{
"text": github.Tag_name,
"icon_url": "https://cdn.jsdelivr.net/gh/zen-browser/www/public/logos/zen-alpha-black.png",
},
},
},
}
jsonData, err := json.Marshal(message)
if err != nil {
log.Fatal(err)
}
req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonData))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
log.Fatalf("Failed to send message: %s", resp.Status)
}
log.Println("Message sent successfully!")
}