It was possible to have multiple hooks with the same ID, but the return in the for/if of the hookHandler method were stopping the loop, thus making it impossible to continue the executions of the other hooks. This isn't the behaviour expected because a service might be down, because you want to run more than one hook, or don't want to stop due to one that failed. This commit fixes it, and add tests associated. The hooks have been copied from the github one, slightly modified and spread in the template file. A "dummy" hook which is never called has also been added, just in case it could mess with some other, and a test for non existing hook has also been added to the tests. This PR fixes: https://github.com/adnanh/webhook/issues/76
227 lines
4.6 KiB
Cheetah
227 lines
4.6 KiB
Cheetah
[
|
|
{
|
|
"id": "github",
|
|
"execute-command": "{{ .Hookecho }}",
|
|
"command-working-directory": "/",
|
|
"include-command-output-in-response": true,
|
|
"pass-environment-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "head_commit.timestamp"
|
|
}
|
|
],
|
|
"pass-arguments-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "head_commit.id"
|
|
},
|
|
{
|
|
"source": "payload",
|
|
"name": "head_commit.author.email"
|
|
}
|
|
],
|
|
"trigger-rule":
|
|
{
|
|
"and":
|
|
[
|
|
{
|
|
"match":
|
|
{
|
|
"type": "payload-hash-sha1",
|
|
"secret": "mysecret",
|
|
"parameter":
|
|
{
|
|
"source": "header",
|
|
"name": "X-Hub-Signature"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"match":
|
|
{
|
|
"type": "value",
|
|
"value": "refs/heads/master",
|
|
"parameter":
|
|
{
|
|
"source": "payload",
|
|
"name": "ref"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"id": "github-called-twice",
|
|
"execute-command": "{{ .Hookecho }}",
|
|
"command-working-directory": "/",
|
|
"include-command-output-in-response": true,
|
|
"pass-environment-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "created"
|
|
}
|
|
],
|
|
"pass-arguments-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "head_commit.id"
|
|
},
|
|
{
|
|
"source": "payload",
|
|
"name": "repository.fork"
|
|
}
|
|
],
|
|
"trigger-rule":
|
|
{
|
|
"and":
|
|
[
|
|
{
|
|
"match":
|
|
{
|
|
"type": "payload-hash-sha1",
|
|
"secret": "mysecret",
|
|
"parameter":
|
|
{
|
|
"source": "header",
|
|
"name": "X-Hub-Signature"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"match":
|
|
{
|
|
"type": "value",
|
|
"value": "refs/heads/master",
|
|
"parameter":
|
|
{
|
|
"source": "payload",
|
|
"name": "ref"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"id": "bitbucket",
|
|
"execute-command": "{{ .Hookecho }}",
|
|
"command-working-directory": "/",
|
|
"include-command-output-in-response": true,
|
|
"response-message": "success",
|
|
"parse-parameters-as-json": [
|
|
{
|
|
"source": "payload",
|
|
"name": "payload"
|
|
}
|
|
],
|
|
"trigger-rule": {
|
|
"and": [
|
|
{
|
|
"match": {
|
|
"type": "value",
|
|
"parameter": {
|
|
"source": "payload",
|
|
"name": "payload.canon_url"
|
|
},
|
|
"value": "https://bitbucket.org"
|
|
}
|
|
},
|
|
{
|
|
"match": {
|
|
"type": "value",
|
|
"parameter": {
|
|
"source": "payload",
|
|
"name": "payload.repository.absolute_url"
|
|
},
|
|
"value": "/webhook/testing/"
|
|
}
|
|
},
|
|
{
|
|
"match": {
|
|
"type": "value",
|
|
"parameter": {
|
|
"source": "payload",
|
|
"name": "payload.commits.0.branch"
|
|
},
|
|
"value": "master"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"id": "gitlab",
|
|
"execute-command": "{{ .Hookecho }}",
|
|
"command-working-directory": "/",
|
|
"response-message": "success",
|
|
"include-command-output-in-response": true,
|
|
"pass-arguments-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "commits.0.id"
|
|
},
|
|
{
|
|
"source": "payload",
|
|
"name": "user_name"
|
|
},
|
|
{
|
|
"source": "payload",
|
|
"name": "user_email"
|
|
}
|
|
],
|
|
"trigger-rule":
|
|
{
|
|
"match":
|
|
{
|
|
"type": "value",
|
|
"value": "refs/heads/master",
|
|
"parameter":
|
|
{
|
|
"source": "payload",
|
|
"name": "ref"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"id": "uncalled-hook",
|
|
"execute-command": "{{ .Hookecho }}",
|
|
"command-working-directory": "/",
|
|
"include-command-output-in-response": true,
|
|
"response-message": "success",
|
|
"parse-parameters-as-json": [
|
|
{
|
|
"source": "payload",
|
|
"name": "payload"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "github-called-twice",
|
|
"execute-command": "{{ .Hookecho }}",
|
|
"command-working-directory": "/",
|
|
"include-command-output-in-response": true,
|
|
"pass-environment-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "pusher.email"
|
|
}
|
|
],
|
|
"pass-arguments-to-command":
|
|
[
|
|
{
|
|
"source": "payload",
|
|
"name": "repository.created_at"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|