gofmt
This commit is contained in:
parent
dbc5015833
commit
cfb46f2f1e
49
main.go
49
main.go
|
@ -2,15 +2,16 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"log"
|
||||
"github.com/urfave/cli"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
respFormat = "Webhook %d\n URL: %s\n RESPONSE STATUS: %s\n RESPONSE BODY: %s\n"
|
||||
debugRespFormat = "Webhook %d\n URL: %s\n METHOD: %s\n HEADERS: %s\n REQUEST BODY: %s\n RESPONSE STATUS: %s\n RESPONSE BODY: %s\n"
|
||||
)
|
||||
|
||||
var build string
|
||||
|
||||
func main() {
|
||||
|
@ -27,13 +28,13 @@ func main() {
|
|||
Value: "POST",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "Username for basic auth",
|
||||
Name: "username",
|
||||
Usage: "Username for basic auth",
|
||||
EnvVar: "PLUGIN_USERNAME,WEBHOOK_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "Password for basic auth",
|
||||
Name: "password",
|
||||
Usage: "Password for basic auth",
|
||||
EnvVar: "PLUGIN_PASSWORD,WEBHOOK_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
|
@ -43,28 +44,28 @@ func main() {
|
|||
Value: "application/json",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "template",
|
||||
Usage: "Custom template for webhook",
|
||||
Name: "template",
|
||||
Usage: "Custom template for webhook",
|
||||
EnvVar: "PLUGIN_TEMPLATE",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "headers",
|
||||
Usage: "Custom headers key map",
|
||||
Name: "headers",
|
||||
Usage: "Custom headers key map",
|
||||
EnvVar: "PLUGIN_HEADERS",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "urls",
|
||||
Usage: "List of urls to perform the action on",
|
||||
Name: "urls",
|
||||
Usage: "List of urls to perform the action on",
|
||||
EnvVar: "PLUGIN_URLS",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "For debug information",
|
||||
Name: "debug",
|
||||
Usage: "For debug information",
|
||||
EnvVar: "PLUGIN_DEBUG",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-verify",
|
||||
Usage: "Skip ssl verification",
|
||||
Name: "skip-verify",
|
||||
Usage: "Skip ssl verification",
|
||||
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
|
@ -182,15 +183,15 @@ func run(c *cli.Context) error {
|
|||
Started: c.Int64("job.started"),
|
||||
},
|
||||
Config: Config{
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
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"),
|
||||
Template: c.String("template"),
|
||||
Headers: c.StringSlice("headers"),
|
||||
URLs: c.StringSlice("urls"),
|
||||
Debug: c.Bool("debug"),
|
||||
SkipVerify: c.Bool("skip-verify"),
|
||||
},
|
||||
}
|
||||
return plugin.Exec()
|
||||
|
|
47
plugin.go
47
plugin.go
|
@ -1,16 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"bytes"
|
||||
"net/url"
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
Repo struct {
|
||||
Owner string `json:"owner"`
|
||||
|
@ -20,7 +21,7 @@ type (
|
|||
Build struct {
|
||||
Tag string `json:"tag"`
|
||||
Event string `json:"event"`
|
||||
Number int `json:"number"`
|
||||
Number int `json:"number"`
|
||||
Commit string `json:"commit"`
|
||||
Ref string `json:"ref"`
|
||||
Branch string `json:"branch"`
|
||||
|
@ -28,20 +29,20 @@ type (
|
|||
Message string `json:"message"`
|
||||
Status string `json:"status"`
|
||||
Link string `json:"link"`
|
||||
Started int64 `json:"started"`
|
||||
Created int64 `json:"created"`
|
||||
Started int64 `json:"started"`
|
||||
Created int64 `json:"created"`
|
||||
}
|
||||
|
||||
Config struct {
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers []string
|
||||
URLs []string
|
||||
Debug bool
|
||||
SkipVerify bool
|
||||
Template string
|
||||
Headers []string
|
||||
URLs []string
|
||||
Debug bool
|
||||
SkipVerify bool
|
||||
}
|
||||
|
||||
Job struct {
|
||||
|
@ -63,7 +64,7 @@ func (p Plugin) Exec() error {
|
|||
|
||||
if p.Config.Template == "" {
|
||||
data := struct {
|
||||
Repo Repo `json:"repo"`
|
||||
Repo Repo `json:"repo"`
|
||||
Build Build `json:"build"`
|
||||
}{p.Repo, p.Build}
|
||||
|
||||
|
@ -73,11 +74,11 @@ func (p Plugin) Exec() error {
|
|||
}
|
||||
b = buf.Bytes()
|
||||
} else {
|
||||
txt, err := RenderTrim(p.Config.Template, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
text := txt
|
||||
txt, err := RenderTrim(p.Config.Template, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
text := txt
|
||||
b = []byte(text)
|
||||
|
||||
}
|
||||
|
@ -163,5 +164,3 @@ func (p Plugin) Exec() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue