mirror of
https://github.com/clem109/drone-wechat.git
synced 2026-06-04 10:23:45 +08:00
added all the config types for the wechat plugin
This commit is contained in:
@@ -26,7 +26,7 @@ docker build --rm -t plugins/webhook .
|
||||
|
||||
```
|
||||
docker run --rm \
|
||||
-e PLUGIN_URLS=https://hooks.somplace.com/endpoing/... \
|
||||
-e PLUGIN_URLS=https://bbc.com/... \
|
||||
-e PLUGIN_HEADERS="HEADER1=value1" \
|
||||
-e PLUGIN_USERNAME=drone \
|
||||
-e PLUGIN_PASSWORD=password \
|
||||
|
||||
@@ -2,17 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/urfave/cli"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var build = "0" // build number set at compile-time
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "webhook plugin"
|
||||
app.Usage = "webhook plugin"
|
||||
app.Name = "WeChat work plugin"
|
||||
app.Usage = "Wechat Work plugin"
|
||||
app.Action = run
|
||||
app.Version = fmt.Sprintf("1.0.0+%s", build)
|
||||
app.Flags = []cli.Flag{
|
||||
@@ -23,14 +24,14 @@ func main() {
|
||||
Value: "POST",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "username for basic auth",
|
||||
EnvVar: "PLUGIN_USERNAME,WEBHOOK_USERNAME",
|
||||
Name: "access-token",
|
||||
Usage: "The access token for authorization",
|
||||
EnvVar: "PLUGIN_ACCESS_TOKEN,WEBHOOK_ACCESS_TOKEN",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "password for basic auth",
|
||||
EnvVar: "PLUGIN_PASSWORD,WEBHOOK_PASSWORD",
|
||||
Name: "msgtype",
|
||||
Usage: "The type of message, either text, textcard",
|
||||
EnvVar: "PLUGIN_MSGTYPE,WEBHOOK_MSGTYPE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "content-type",
|
||||
@@ -39,20 +40,32 @@ func main() {
|
||||
Value: "application/json",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "template",
|
||||
Name: "touser",
|
||||
Usage: "The users to send the message to, @all for all users",
|
||||
EnvVar: "PLUGIN_TO_USER",
|
||||
Value: "@all",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "toparty",
|
||||
Usage: "Party ID to send messages to",
|
||||
EnvVar: "PLUGIN_TO_PARTY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "safe",
|
||||
Usage: "Whether to make this message confidential or not, 0 is false, 1 is true. Defaults to false",
|
||||
EnvVar: "PLUGIN_SAFE",
|
||||
Value: "0",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "content",
|
||||
Usage: "custom template for webhook",
|
||||
EnvVar: "PLUGIN_TEMPLATE",
|
||||
EnvVar: "PLUGIN_CONTENT",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "headers",
|
||||
Usage: "custom headers key map",
|
||||
EnvVar: "PLUGIN_HEADERS",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "urls",
|
||||
Usage: "list of urls to perform the action on",
|
||||
EnvVar: "PLUGIN_URLS",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "enable debug information",
|
||||
@@ -177,12 +190,15 @@ func run(c *cli.Context) error {
|
||||
},
|
||||
Config: Config{
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
AccessToken: c.String("access-token"),
|
||||
MsgType: c.String("msgtype"),
|
||||
ToUser: c.StringSlice("touser"),
|
||||
ToParty: c.StringSlice("toparty"),
|
||||
Safe: c.Bool("safe"),
|
||||
Content: c.String("content"),
|
||||
ContentType: c.String("content-type"),
|
||||
Template: c.String("template"),
|
||||
Headers: c.StringSlice("headers"),
|
||||
URLs: c.StringSlice("urls"),
|
||||
Debug: c.Bool("debug"),
|
||||
SkipVerify: c.Bool("skip-verify"),
|
||||
},
|
||||
|
||||
@@ -40,12 +40,15 @@ type (
|
||||
|
||||
Config struct {
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
AccessToken string
|
||||
MsgType string
|
||||
ToUser []string
|
||||
ToParty []string
|
||||
Safe bool
|
||||
Content string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers []string
|
||||
URLs []string
|
||||
Debug bool
|
||||
SkipVerify bool
|
||||
}
|
||||
@@ -66,7 +69,7 @@ func (p Plugin) Exec() error {
|
||||
var buf bytes.Buffer
|
||||
var b []byte
|
||||
|
||||
if p.Config.Template == "" {
|
||||
if p.Config.Content == "" {
|
||||
data := struct {
|
||||
Repo Repo `json:"repo"`
|
||||
Build Build `json:"build"`
|
||||
@@ -92,6 +95,8 @@ func (p Plugin) Exec() error {
|
||||
// and content_type values will be applied to
|
||||
// every webhook request.
|
||||
|
||||
// TODO: Construct URL for WeChat work
|
||||
|
||||
for i, rawurl := range p.Config.URLs {
|
||||
uri, err := url.Parse(rawurl)
|
||||
|
||||
|
||||
Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user