-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
111 lines (106 loc) · 2.76 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
var telegramBotToken, telegramParseMode, ciProjectUrl, ciPipelineId, ciCommitSlug, text string
var telegramChatId int
app := &cli.App{
Name: "notifyer",
Version: "v3.0.0",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "telegram_bot_token",
DefaultText: "YOUR_TELEGRAM_BOT_TOKEN",
Aliases: []string{"tbt"},
Usage: "TELEGRAM_BOT_TOKEN",
EnvVars: []string{"NOTIFYER_TELEGRAM_BOT_TOKEN"},
Destination: &telegramBotToken,
},
&cli.StringFlag{
Name: "ci_project_url",
Aliases: []string{"cpu"},
Usage: "CI_PROJECT_URL - GitLab CI",
EnvVars: []string{"CI_PROJECT_URL"},
Destination: &ciProjectUrl,
},
&cli.StringFlag{
Name: "ci_pipeline_id",
Aliases: []string{"cpi"},
Usage: "CI_PIPELINE_ID - GitLab CI",
EnvVars: []string{"CI_PIPELINE_ID"},
Destination: &ciPipelineId,
},
&cli.StringFlag{
Name: "ci_commit_slug",
Aliases: []string{"gcs"},
Usage: "CI_COMMIT_REF_SLUG - GitLab CI",
EnvVars: []string{"CI_COMMIT_REF_SLUG"},
Destination: &ciCommitSlug,
},
&cli.IntFlag{
Name: "telegram_chat_id",
Aliases: []string{"tci"},
Usage: "TELEGRAM_CHAT_ID - Telegram",
EnvVars: []string{"NOTIFYER_TELEGRAM_CHAT_ID"},
Destination: &telegramChatId,
},
&cli.StringFlag{
Name: "telegram_parse_mode",
Aliases: []string{"tpm"},
Usage: "TELEGRAM_PARSE_MODE - Telegram",
EnvVars: []string{"NOTIFYER_TELEGRAM_PARSE_MODE"},
DefaultText: "HTML",
Destination: &telegramParseMode,
},
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Usage: "TEXT",
EnvVars: []string{"NOTIFYER_TEXT"},
Destination: &text,
},
},
Commands: []*cli.Command{
{
Name: "release",
Aliases: []string{"r"},
Usage: "Release [ready]",
Subcommands: []*cli.Command{
{
Name: "ready",
Usage: "release ready",
Action: func(c *cli.Context) error {
fmt.Println("[Notifyer] Release ready")
sendTextToTelegramChat(telegramChatId, text, telegramBotToken, telegramParseMode)
return nil
},
},
},
},
{
Name: "deploy",
Aliases: []string{"d"},
Usage: "Deploy [done]",
Subcommands: []*cli.Command{
{
Name: "done",
Usage: "deploy done",
Action: func(c *cli.Context) error {
fmt.Println("[Notifyer] Deploy done")
sendTextToTelegramChat(telegramChatId, text, telegramBotToken, telegramParseMode)
return nil
},
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}