use new webhook package
This commit is contained in:
parent
38877a0a7c
commit
e17c338fe4
13
DOCS.md
13
DOCS.md
|
@ -67,7 +67,7 @@ The following is an example Webhook payload (whitespace added):
|
|||
|
||||
In some cases you may want to submit a custom payload in the body of your hook. For the use case we expose the following additional parameters:
|
||||
|
||||
* `template` - Go template to create a custom payload body. See [docs](https://golang.org/pkg/text/template/)
|
||||
* `template` - Handlebars template to create a custom payload body. See [docs](http://handlebarsjs.com/)
|
||||
* `content_type` - HTTP request content type
|
||||
|
||||
Example configuration that generate a custom Yaml payload:
|
||||
|
@ -80,9 +80,9 @@ notify:
|
|||
- https://your.other.webhook/...
|
||||
content_type: application/yaml
|
||||
template: >
|
||||
repo: {{.Repo.FullName}}
|
||||
build: {{.Build.Number}}
|
||||
commit: {{.Build.Commit}}
|
||||
repo: {{repo.full_name}}
|
||||
build: {{build.number}}
|
||||
commit: {{build.commit}}
|
||||
```
|
||||
|
||||
## Basic Authentication
|
||||
|
@ -106,11 +106,6 @@ notify:
|
|||
password: $$PASSWORD
|
||||
urls:
|
||||
- https://tower.example.com/...
|
||||
content_type: application/yaml
|
||||
template: >
|
||||
repo: {{.Repo.FullName}}
|
||||
build: {{.Build.Number}}
|
||||
commit: {{.Build.Commit}}
|
||||
```
|
||||
|
||||
## Debugging Webhooks
|
||||
|
|
18
main.go
18
main.go
|
@ -8,20 +8,22 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/drone-go/plugin"
|
||||
"github.com/drone/drone-go/template"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// plugin settings
|
||||
var sys = drone.System{}
|
||||
var repo = drone.Repo{}
|
||||
var build = drone.Build{}
|
||||
var vargs = Webhook{}
|
||||
|
||||
// set plugin parameters
|
||||
plugin.Param("system", &sys)
|
||||
plugin.Param("repo", &repo)
|
||||
plugin.Param("build", &build)
|
||||
plugin.Param("vargs", &vargs)
|
||||
|
@ -52,18 +54,16 @@ func main() {
|
|||
var buf bytes.Buffer
|
||||
if len(vargs.Template) == 0 {
|
||||
if err := json.NewEncoder(&buf).Encode(&data); err != nil {
|
||||
fmt.Printf("Error encoding content template. %s\n", err)
|
||||
fmt.Printf("Error encoding json payload. %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
|
||||
t, err := template.New("_").Parse(vargs.Template)
|
||||
err := template.Write(&buf, vargs.Template, &drone.Payload{
|
||||
Build: &build,
|
||||
Repo: &repo,
|
||||
System: &sys,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing content template. %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := t.Execute(&buf, &data); err != nil {
|
||||
fmt.Printf("Error executing content template. %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue