-
-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from moorereason/iss193
Add Template docs
- Loading branch information
Showing
2 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Templates in Webhook | ||
|
||
[`webhook`][w] can parse the `hooks.json` input file as a Go template when given the `-template` [CLI parameter](Webhook-Parameters.md). | ||
|
||
In additional to the [built-in Go template functions and features][tt], `webhook` provides a `getenv` template function for inserting environment variables into a `hooks.json` file. | ||
|
||
## Example Usage | ||
|
||
In the example `hooks.json` file below, the `payload-hash-sha1` matching rule looks up the secret hash from the environment using the `getenv` template function. | ||
Additionally, the result is piped through the built-in Go template function `js` to ensure that the result is a well-formed Javascript/JSON string. | ||
|
||
``` | ||
{ | ||
"id": "webhook", | ||
"execute-command": "/home/adnan/redeploy-go-webhook.sh", | ||
"command-working-directory": "/home/adnan/go", | ||
"response-message": "I got the payload!", | ||
"response-headers": | ||
[ | ||
{ | ||
"name": "Access-Control-Allow-Origin", | ||
"value": "*" | ||
} | ||
], | ||
"pass-arguments-to-command": | ||
[ | ||
{ | ||
"source": "payload", | ||
"name": "head_commit.id" | ||
}, | ||
{ | ||
"source": "payload", | ||
"name": "pusher.name" | ||
}, | ||
{ | ||
"source": "payload", | ||
"name": "pusher.email" | ||
} | ||
], | ||
"trigger-rule": | ||
{ | ||
"and": | ||
[ | ||
{ | ||
"match": | ||
{ | ||
"type": "payload-hash-sha1", | ||
"secret": "{{ getenv "XXXTEST_SECRET" | js }}", | ||
"parameter": | ||
{ | ||
"source": "header", | ||
"name": "X-Hub-Signature" | ||
} | ||
} | ||
}, | ||
{ | ||
"match": | ||
{ | ||
"type": "value", | ||
"value": "refs/heads/master", | ||
"parameter": | ||
{ | ||
"source": "payload", | ||
"name": "ref" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
``` | ||
|
||
[w]: https://github.com/adnanh/webhook | ||
[tt]: https://golang.org/pkg/text/template/ |