Repository: adnanh/webhook (go)

Issue:
Payload as Content-Type text/plain as argument to script
Hi, 

I'm trying to configure webhook to also send a payload, configured as text/plain to my script.

I got the following hooks.json
```
[
        {
                "id": "testHook",
                "execute-command": "/var/script/test.sh",
                "command-working-directory": "/my/working/dir",
                "pass-arguments-to-command": [
                        {
                                "source": "entire-payload"
                        }
                ]
        }
]
```
My test.sh is just:
```
#!/bin/sh

PARAM=$1

echo "Test Texecuted"
echo "Param: "
echo $PARAM
```
If I send a payload like {"test": "test2"} I get the desired output. 

But if I send this payload as a content-type text/plain, only null is passed. The problem is, I can get JSON-conform payloads as well as payloads that are just a string. I only want to pass the complete payload to my script, is that somehow possible? Thanks in advance!


Pull request description:
Add option to send raw request body to command
The existing `entire-payload` option sends a JSON representation of the
parsed request body.  Add a new `raw-request-body` source to send the
raw request body.

Fixes #439

Patch:
diff --git a/internal/hook/hook.go b/internal/hook/hook.go
index 19809e7..987f324 100644
--- a/internal/hook/hook.go
+++ b/internal/hook/hook.go
@@ -31,15 +31,16 @@ import (
 
 // Constants used to specify the parameter source
 const (
-	SourceHeader        string = "header"
-	SourceQuery         string = "url"
-	SourceQueryAlias    string = "query"
-	SourcePayload       string = "payload"
-	SourceRequest       string = "request"
-	SourceString        string = "string"
-	SourceEntirePayload string = "entire-payload"
-	SourceEntireQuery   string = "entire-query"
-	SourceEntireHeaders string = "entire-headers"
+	SourceHeader         string = "header"
+	SourceQuery          string = "url"
+	SourceQueryAlias     string = "query"
+	SourcePayload        string = "payload"
+	SourceRawRequestBody string = "raw-request-body"
+	SourceRequest        string = "request"
+	SourceString         string = "string"
+	SourceEntirePayload  string = "entire-payload"
+	SourceEntireQuery    string = "entire-query"
+	SourceEntireHeaders  string = "entire-headers"
 )
 
 const (
@@ -449,6 +450,9 @@ func (ha *Argument) Get(r *Request) (string, error) {
 	case SourceString:
 		return ha.Name, nil
 
+	case SourceRawRequestBody:
+		return string(r.Body), nil
+
 	case SourceRequest:
 		if r == nil || r.RawRequest == nil {
 			return "", errors.New("request is nil")


Test patch:
diff --git a/test/hooks.json.tmpl b/test/hooks.json.tmpl
index fd5cb83..032d331 100644
--- a/test/hooks.json.tmpl
+++ b/test/hooks.json.tmpl
@@ -168,6 +168,17 @@
       ],
     }
   },
+  {
+    "id": "txt-raw",
+    "execute-command": "{{ .Hookecho }}",
+    "command-working-directory": "/",
+    "include-command-output-in-response": true,
+    "pass-arguments-to-command": [
+      {
+        "source": "raw-request-body"
+      }
+    ]
+  },
   {
     "id": "sendgrid",
     "execute-command": "{{ .Hookecho }}",
diff --git a/test/hooks.yaml.tmpl b/test/hooks.yaml.tmpl
index 82833dc..9d73d8b 100644
--- a/test/hooks.yaml.tmpl
+++ b/test/hooks.yaml.tmpl
@@ -97,6 +97,13 @@
           name: "app.messages.message.#text"
         value: "Hello!!"
 
+- id: txt-raw
+  execute-command: '{{ .Hookecho }}'
+  command-working-directory: /
+  include-command-output-in-response: true
+  pass-arguments-to-command:
+  - source: raw-request-body
+
 - id: sendgrid
   execute-command: '{{ .Hookecho }}'
   command-working-directory: /
diff --git a/webhook_test.go b/webhook_test.go
index 885efb6..539cdd4 100644
--- a/webhook_test.go
+++ b/webhook_test.go
@@ -572,6 +572,25 @@ env: HOOK_head_commit.timestamp=2013-03-12T08:14:29-07:00
 		`success`,
 		``,
 	},
+	{
+		"txt-raw",
+		"txt-raw",
+		nil,
+		"POST",
+		map[string]string{"Content-Type": "text/plain"},
+		"text/plain",
+		`# FOO
+
+blah
+blah`,
+		false,
+		http.StatusOK,
+		`# FOO
+
+blah
+blah`,
+		``,
+	},
 	{
 		"payload-json-array",
 		"sendgrid",