mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-14 01:24:54 +00:00
Merge c2da943240
into 1b13355196
This commit is contained in:
commit
7d8c292a02
3 changed files with 21 additions and 20 deletions
|
@ -828,7 +828,7 @@ func (r Rules) Evaluate(req *Request) (bool, error) {
|
||||||
return r.Match.Evaluate(req)
|
return r.Match.Evaluate(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AndRule will evaluate to true if and only if all of the ChildRules evaluate to true
|
// AndRule will evaluate to true if and only if all of the ChildRules evaluate to true
|
||||||
|
|
|
@ -351,20 +351,21 @@ func TestHookExtractCommandArguments(t *testing.T) {
|
||||||
// we test both cases where the name of the data is used as the name of the
|
// we test both cases where the name of the data is used as the name of the
|
||||||
// env key & the case where the hook definition sets the env var name to a
|
// env key & the case where the hook definition sets the env var name to a
|
||||||
// fixed value using the envname construct like so::
|
// fixed value using the envname construct like so::
|
||||||
// [
|
//
|
||||||
// {
|
// [
|
||||||
// "id": "push",
|
// {
|
||||||
// "execute-command": "bb2mm",
|
// "id": "push",
|
||||||
// "command-working-directory": "/tmp",
|
// "execute-command": "bb2mm",
|
||||||
// "pass-environment-to-command":
|
// "command-working-directory": "/tmp",
|
||||||
// [
|
// "pass-environment-to-command":
|
||||||
// {
|
// [
|
||||||
// "source": "entire-payload",
|
// {
|
||||||
// "envname": "PAYLOAD"
|
// "source": "entire-payload",
|
||||||
// },
|
// "envname": "PAYLOAD"
|
||||||
// ]
|
// },
|
||||||
// }
|
// ]
|
||||||
// ]
|
// }
|
||||||
|
// ]
|
||||||
var hookExtractCommandArgumentsForEnvTests = []struct {
|
var hookExtractCommandArgumentsForEnvTests = []struct {
|
||||||
exec string
|
exec string
|
||||||
args []Argument
|
args []Argument
|
||||||
|
@ -596,7 +597,7 @@ var andRuleTests = []struct {
|
||||||
[]byte{},
|
[]byte{},
|
||||||
true, false,
|
true, false,
|
||||||
},
|
},
|
||||||
{"empty rule", AndRule{{}}, nil, nil, nil, nil, false, false},
|
{"empty rule", AndRule{{}}, nil, nil, nil, nil, true, false},
|
||||||
// failures
|
// failures
|
||||||
{
|
{
|
||||||
"invalid rule",
|
"invalid rule",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -172,7 +172,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !*verbose {
|
if !*verbose {
|
||||||
log.SetOutput(ioutil.Discard)
|
log.SetOutput(io.Discard)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create pidfile
|
// Create pidfile
|
||||||
|
@ -379,7 +379,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
isMultipart := strings.HasPrefix(req.ContentType, "multipart/form-data;")
|
isMultipart := strings.HasPrefix(req.ContentType, "multipart/form-data;")
|
||||||
|
|
||||||
if !isMultipart {
|
if !isMultipart {
|
||||||
req.Body, err = ioutil.ReadAll(r.Body)
|
req.Body, err = io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] error reading the request body: %+v\n", req.ID, err)
|
log.Printf("[%s] error reading the request body: %+v\n", req.ID, err)
|
||||||
}
|
}
|
||||||
|
@ -608,7 +608,7 @@ func handleHook(h *hook.Hook, r *hook.Request) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range files {
|
for i := range files {
|
||||||
tmpfile, err := ioutil.TempFile(h.CommandWorkingDirectory, files[i].EnvName)
|
tmpfile, err := os.CreateTemp(h.CommandWorkingDirectory, files[i].EnvName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] error creating temp file [%s]", r.ID, err)
|
log.Printf("[%s] error creating temp file [%s]", r.ID, err)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Reference in a new issue