-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (43 loc) · 1.05 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/yanzay/tbot/v2"
)
func main() {
icons := map[string]string{
"failure": "❗",
"cancelled": "❕",
"success": "✅",
}
var (
// inputs
token = os.Getenv("INPUT_TOKEN")
chat = os.Getenv("INPUT_CHAT")
status = os.Getenv("INPUT_STATUS")
// github env
workflow = os.Getenv("GITHUB_WORKFLOW")
repo = os.Getenv("GITHUB_REPOSITORY")
commit = os.Getenv("GITHUB_SHA")
)
if token == "" {
log.Fatal("token input is required")
}
if chat == "" {
log.Fatal("chat input is required")
}
if status == "" {
log.Fatal("status input is required")
}
c := tbot.NewClient(token, http.DefaultClient, "https://api.telegram.org")
icon := icons[strings.ToLower(status)]
link := fmt.Sprintf("https://github.com/%s/commit/%s/checks", repo, commit)
msg := fmt.Sprintf(`%s*%s*: %s ([%s](%s))`, icon, status, repo, workflow, link)
_, err := c.SendMessage(chat, msg, tbot.OptParseModeMarkdown)
if err != nil {
log.Fatalf("unable to send message: %v", err)
}
}