mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-14 09:34:43 +00:00
Update README.md
refactoring
This commit is contained in:
parent
9e5ebb599a
commit
624d94e736
1 changed files with 44 additions and 33 deletions
37
README.md
37
README.md
|
@ -1,15 +1,20 @@
|
||||||
# Installing
|
# webhook
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
*Please note:* Before installing the webhook, make sure you have installed `go` and properly set up your `$GOPATH` environment variable.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
go get github.com/adnanh/webhook
|
go get github.com/adnanh/webhook
|
||||||
```
|
```
|
||||||
|
|
||||||
# Updating
|
## Updating
|
||||||
```go
|
```go
|
||||||
go get -u github.com/adnanh/webhook
|
go get -u github.com/adnanh/webhook
|
||||||
```
|
```
|
||||||
|
|
||||||
# Adding hooks
|
## Adding hooks
|
||||||
Hooks are defined using JSON format. The hooks file must contain an array of JSON formatted hooks. Here is an example of a valid hooks file containing one hook. The hook will be triggered whenever a push to the master branch occurrs.
|
Hooks are defined using JSON format. The _hooks file_ must contain an array of JSON formatted hooks. Here is an example of a valid _hooks file_ containing only one hook. The hook will be triggered whenever a push to the master branch occurrs.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
@ -28,7 +33,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
# Trigger rules
|
## Trigger rules
|
||||||
### And
|
### And
|
||||||
*And rule* will evaluate to _true_, if and only if all of the sub rules evaluate to _true_.
|
*And rule* will evaluate to _true_, if and only if all of the sub rules evaluate to _true_.
|
||||||
```json
|
```json
|
||||||
|
@ -90,20 +95,21 @@
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### Match
|
### Match
|
||||||
*Match rule* will evaluate to _true_, if and only if the payload structure contains the key specified in the `parameter` value, contains same value as specified in the `value` value.
|
*Match rule* will evaluate to _true_, if and only if the payload JSON object contains the key specified in the `parameter` field that has the same value as specified in the `value` field.
|
||||||
*Please note:* due to technical limitations, _number_ and _boolean_ values in hooks file must be wrapped around with quotes.
|
|
||||||
|
*Please note:* Due to technical reasons, _number_ and _boolean_ values in the _hooks file_ must be wrapped around with a pair of quotes.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"match":
|
"match":
|
||||||
{
|
{
|
||||||
"parameter": "ref",
|
"parameter": "repository.id",
|
||||||
"value": "refs/heads/master"
|
"value": "123456"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
It is possible to specify the values deeper in the payload JSON object with the dot operator, and if a value of the specified key is an array, it's possible to index the array values by using the number instead of string as the key, as shown in a following example:
|
It is possible to specify the values deeper in the payload JSON object with the dot operator, and if a value of the specified key happens to be an array, it's possible to index the array values by using the number instead of a string as the key, which is shown in the following example:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"match":
|
"match":
|
||||||
|
@ -113,10 +119,11 @@ It is possible to specify the values deeper in the payload JSON object with the
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
# Running
|
## Running
|
||||||
In your `$GOPATH/bin` directory, you should have `webhook` binary.
|
After installing webhook, in your `$GOPATH/bin` directory you should have `webhook` binary.
|
||||||
|
|
||||||
Simply running the binary using `./webhook` command, will start the webhook with the default options. That means the webhook will listen on all interfaces on port 9000. It will try to read and parse `hooks.json` file from the same directory where the binary is located, and it will log everything to stdout and the file `webhook.log`.
|
By simply running the binary using the `./webhook` command, the webhook will start with the default options.
|
||||||
|
That means the webhook will listen on _all interfaces_ on port `9000`. It will try to read and parse `hooks.json` file from the same directory where the binary is located, and it will log everything to `stdout` and the file `webhook.log`.
|
||||||
|
|
||||||
To override any of these options, you can use the following command line flags:
|
To override any of these options, you can use the following command line flags:
|
||||||
```bash
|
```bash
|
||||||
|
@ -125,3 +132,7 @@ To override any of these options, you can use the following command line flags:
|
||||||
-log="webhook.log": path to the log file
|
-log="webhook.log": path to the log file
|
||||||
-port=9000: port the webhook server should listen on
|
-port=9000: port the webhook server should listen on
|
||||||
```
|
```
|
||||||
|
|
||||||
|
All hooks are served under the `http://ip:port/hook/:id`, where the `:id` corresponds to the hook *id* specified in _hooks file_.
|
||||||
|
|
||||||
|
Visiting `http://ip:port` will show version, uptime and number of hooks the webhook is serving.
|
||||||
|
|
Loading…
Add table
Reference in a new issue