mirror of
https://github.com/appleboy/drone-telegram.git
synced 2026-06-13 18:41:32 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e3fc3f805d | |||
| 44ac6f43de | |||
| 5ac85a3412 | |||
| 79e531f648 | |||
| abba2cb37d | |||
| 7f8bd6ba04 | |||
| 0dc176a2ac | |||
| 2af2c10e0e |
@@ -10,6 +10,7 @@ environment:
|
||||
secure: em/TNLUXxG19O/HvbvfJuQ==
|
||||
docker_password:
|
||||
secure: Yo9FJJqihaNz5q8T4Jz8tQ==
|
||||
GO111MODULE: on
|
||||
|
||||
branches:
|
||||
only:
|
||||
@@ -23,6 +24,7 @@ install:
|
||||
|
||||
build_script:
|
||||
- ps: |
|
||||
go mod download
|
||||
if ( $env:APPVEYOR_REPO_TAG -eq 'false' ) {
|
||||
$version = $env:APPVEYOR_REPO_COMMIT
|
||||
} else {
|
||||
|
||||
@@ -175,7 +175,8 @@ Example configuration with a generic message template loaded from file, with add
|
||||
```
|
||||
|
||||
Where `message_file.tpl` is:
|
||||
```
|
||||
|
||||
```bash
|
||||
Build finished for *{{tpl.app}}* - *{{tpl.env}}*
|
||||
|
||||
{{#success build.status}}
|
||||
@@ -185,6 +186,18 @@ Build finished for *{{tpl.app}}* - *{{tpl.env}}*
|
||||
{{/success}}
|
||||
```
|
||||
|
||||
Example configuration with a custom socks5 URL:
|
||||
|
||||
```diff
|
||||
- name: send telegram notification
|
||||
image: appleboy/drone-telegram
|
||||
settings:
|
||||
token: xxxxxxxxxx
|
||||
to: telegram_user_id
|
||||
message: send message using custom socks5 URL
|
||||
+ socks5: socks5://67.204.21.1:64312
|
||||
```
|
||||
|
||||
## Parameter Reference
|
||||
|
||||
token
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
[](https://godoc.org/github.com/appleboy/drone-telegram)
|
||||
[](https://cloud.drone.io/appleboy/drone-telegram)
|
||||
[](https://ci.appveyor.com/project/appleboy/drone-telegram)
|
||||
[](https://ci.appveyor.com/project/appleboy/drone-telegram-cd47y)
|
||||
[](https://codecov.io/gh/appleboy/drone-telegram)
|
||||
[](https://goreportcard.com/report/github.com/appleboy/drone-telegram)
|
||||
[](https://hub.docker.com/r/appleboy/drone-telegram/)
|
||||
|
||||
@@ -5,6 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
||||
org.label-schema.vendor="Bo-Yi Wu" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/amd64/drone-telegram /bin/
|
||||
COPY release/linux/amd64/drone-telegram /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-telegram"]
|
||||
|
||||
@@ -5,6 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
||||
org.label-schema.vendor="Bo-Yi Wu" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/arm/drone-telegram /bin/
|
||||
COPY release/linux/arm/drone-telegram /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-telegram"]
|
||||
|
||||
@@ -5,6 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
||||
org.label-schema.vendor="Bo-Yi Wu" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/arm64/drone-telegram /bin/
|
||||
COPY release/linux/arm64/drone-telegram /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-telegram"]
|
||||
|
||||
@@ -5,5 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
||||
org.label-schema.vendor="Bo-Yi Wu" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/drone-telegram.exe /drone-telegram.exe
|
||||
COPY release/drone-telegram.exe /drone-telegram.exe
|
||||
|
||||
ENTRYPOINT [ "\\drone-telegram.exe" ]
|
||||
|
||||
@@ -245,6 +245,11 @@ func main() {
|
||||
Usage: "Provides the target deployment environment for the running build. This value is only available to promotion and rollback pipelines.",
|
||||
EnvVar: "DRONE_DEPLOY_TO",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "socks5",
|
||||
Usage: "Socks5 proxy URL",
|
||||
EnvVar: "PLUGIN_SOCKS5,SOCKS5,INPUT_SOCKS5",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -310,6 +315,7 @@ func run(c *cli.Context) error {
|
||||
Venue: c.StringSlice("venue"),
|
||||
Format: c.String("format"),
|
||||
GitHub: c.Bool("github"),
|
||||
Socks5: c.String("socks5"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -83,6 +85,7 @@ type (
|
||||
Venue []string
|
||||
Format string
|
||||
GitHub bool
|
||||
Socks5 string
|
||||
}
|
||||
|
||||
// Plugin values.
|
||||
@@ -273,9 +276,21 @@ func (p Plugin) Exec() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
var proxyURL *url.URL
|
||||
if proxyURL, err = url.Parse(p.Config.Socks5); err != nil {
|
||||
return fmt.Errorf("unable to unmarshall socks5 proxy url from string '%s': %v", p.Config.Socks5, err)
|
||||
}
|
||||
|
||||
var bot *tgbotapi.BotAPI
|
||||
if bot, err = tgbotapi.NewBotAPI(p.Config.Token); err != nil {
|
||||
return
|
||||
if len(p.Config.Socks5) > 0 {
|
||||
proxyClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}
|
||||
bot, err = tgbotapi.NewBotAPIWithClient(p.Config.Token, proxyClient)
|
||||
} else {
|
||||
bot, err = tgbotapi.NewBotAPI(p.Config.Token)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bot.Debug = p.Config.Debug
|
||||
|
||||
@@ -385,3 +385,36 @@ func TestTemplateVars(t *testing.T) {
|
||||
err := plugin.Exec()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestProxySendMessage(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Repo: Repo{
|
||||
Name: "go-hello",
|
||||
Namespace: "appleboy",
|
||||
},
|
||||
Commit: Commit{
|
||||
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
|
||||
Author: "Bo-Yi Wu",
|
||||
Branch: "master",
|
||||
Message: "start use proxy",
|
||||
Email: "test@gmail.com",
|
||||
},
|
||||
Build: Build{
|
||||
Tag: "1.0.0",
|
||||
Number: 101,
|
||||
Status: "success",
|
||||
Link: "https://github.com/appleboy/go-hello",
|
||||
},
|
||||
|
||||
Config: Config{
|
||||
Token: os.Getenv("TELEGRAM_TOKEN"),
|
||||
To: []string{os.Getenv("TELEGRAM_TO")},
|
||||
Message: []string{"Send message from socks5 proxy URL."},
|
||||
Debug: false,
|
||||
Socks5: os.Getenv("SOCKS5"),
|
||||
},
|
||||
}
|
||||
|
||||
err := plugin.Exec()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user