Compare commits

...

13 Commits

Author SHA1 Message Date
Adnan Hajdarević 147c95dd8b Merge pull request #158 from adnanh/development
2.6.5
2017-08-09 09:53:37 +02:00
Adnan Hajdarevic cfd138c96d Fix #141 2017-08-09 09:52:59 +02:00
Adnan Hajdarević c19e514ee9 Merge pull request #143 from wrouesnel/yaml-decoding
Use the github.com/ghodss/yaml library to unserialize webhooks.
2017-08-09 09:29:58 +02:00
Adnan Hajdarević c7ec25f378 Merge pull request #156 from andrewharvey/patch-1
Update README.md for Debian stretch release of webhook package
2017-08-02 14:06:24 +02:00
Andrew Harvey 6916f89a2b Update README.md for Debian stretch release of webhook package 2017-08-02 22:02:55 +10:00
Adnan Hajdarević ed251c3cc7 Merge pull request #149 from adnanh/master
Readme backmerge
2017-07-06 09:25:12 +02:00
Adnan Hajdarević 9db13ef649 Update README.md 2017-07-06 09:24:50 +02:00
Adnan Hajdarević 98512463d8 Update README.md 2017-07-06 09:24:00 +02:00
Will Rouesnel 53ec2e7acc Add tests for YAML file parsing. 2017-06-29 02:34:58 +10:00
Adnan Hajdarević c581e0532b Merge pull request #144 from ilkelma/use-combined-output
Change to CombinedOutput to consume Stderr as well
2017-06-16 10:59:03 +02:00
ilkelma 3a75bbf4db Change to CombinedOutput to consume Stderr as well 2017-06-13 16:23:59 -04:00
Will Rouesnel 2f1ea098c0 Use the github.com/ghodss/yaml library to unserialize webhooks.
This supports both JSON and YAML seamlessly, providing for an easier human
parseable format on disk.
2017-06-12 19:56:09 +10:00
Adnan Hajdarević ccd28908db Create README.md 2017-06-08 11:16:41 +02:00
7 changed files with 178 additions and 54 deletions
+8 -3
View File
@@ -12,7 +12,7 @@ If you don't have time to waste configuring, hosting, debugging and maintaining
For example, if you're using Github or Bitbucket, you can use [webhook](https://github.com/adnanh/webhook/) to set up a hook that runs a redeploy script for your project on your staging server, whenever you push changes to the master branch of your project.
If you use Slack, you can set up an "Outgoing webhook integration" to run various commands on your server, which can then report back directly to your Slack channels using the "Incoming webhook integrations".
If you use Mattermost or Slack, you can set up an "Outgoing webhook integration" or "Slash command" to run various commands on your server, which can then report back directly to you or your channels using the "Incoming webhook integrations", or the appropriate response body.
[webhook](https://github.com/adnanh/webhook/) aims to do nothing more than it should do, and that is:
1. receive the request,
@@ -35,8 +35,8 @@ $ go get github.com/adnanh/webhook
to get the latest version of the [webhook](https://github.com/adnanh/webhook/).
### Using package manager
#### Debian "sid"
If you are using unstable version of Debian linux ("sid"), you can install webhook using `apt-get install webhook` which will install community packaged version (thanks [@freeekanayaka](https://github.com/freeekanayaka)) from https://packages.debian.org/sid/webhook
#### Debian
If you are using Debian linux ("stretch" or later), you can install webhook using `apt-get install webhook` which will install community packaged version (thanks [@freeekanayaka](https://github.com/freeekanayaka)) from https://packages.debian.org/sid/webhook
### Download prebuilt binaries
Prebuilt binaries for different architectures are available at [GitHub Releases](https://github.com/adnanh/webhook/releases).
@@ -93,6 +93,11 @@ Big thanks to [all the current contributors](https://github.com/adnanh/webhook/g
# Community Contributions
See the [webhook-contrib][wc] repository for a collections of tools and helpers related to [webhook][w] that have been contributed by the [webhook][w] community.
# Sponsors
## <a href="https://www.browserstack.com/?ref=webhook"><img src="http://www.hajdarevic.net/browserstack.svg" alt="BrowserStack" width="250"/></a>
[BrowserStack](https://www.browserstack.com/?ref=webhook) is a cloud-based cross-browser testing tool that enables developers to test their websites across various browsers on different operating systems and mobile devices, without requiring users to install virtual machines, devices or emulators.
# License
The MIT License (MIT)
+3 -1
View File
@@ -15,6 +15,8 @@ import (
"regexp"
"strconv"
"strings"
"github.com/ghodss/yaml"
)
// Constants used to specify the parameter source
@@ -503,7 +505,7 @@ func (h *Hooks) LoadFromFile(path string) error {
return e
}
e = json.Unmarshal(file, h)
e = yaml.Unmarshal(file, h)
return e
}
+1
View File
@@ -233,6 +233,7 @@ var hooksLoadFromFileTests = []struct {
ok bool
}{
{"../hooks.json.example", true},
{"../hooks.yaml.example", true},
{"", true},
// failures
{"missing.json", false},
+28
View File
@@ -0,0 +1,28 @@
- 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: mysecret
parameter:
source: header
name: X-Hub-Signature
- match:
type: value
value: refs/heads/master
parameter:
source: payload
name: ref
+75
View File
@@ -0,0 +1,75 @@
- trigger-rule:
and:
- match:
parameter:
source: header
name: X-Hub-Signature
secret: mysecret
type: payload-hash-sha1
- match:
parameter:
source: payload
name: ref
type: value
value: refs/heads/master
include-command-output-in-response: true
trigger-rule-mismatch-http-response-code: 400
execute-command: '{{ .Hookecho }}'
pass-arguments-to-command:
- source: payload
name: head_commit.id
- source: payload
name: head_commit.author.email
pass-environment-to-command:
- source: payload
name: head_commit.timestamp
id: github
command-working-directory: /
- trigger-rule:
and:
- match:
parameter:
source: payload
name: payload.canon_url
type: value
value: https://bitbucket.org
- match:
parameter:
source: payload
name: payload.repository.absolute_url
type: value
value: /webhook/testing/
- match:
parameter:
source: payload
name: payload.commits.0.branch
type: value
value: master
parse-parameters-as-json:
- source: payload
name: payload
trigger-rule-mismatch-http-response-code: 999
execute-command: '{{ .Hookecho }}'
response-message: success
include-command-output-in-response: false
id: bitbucket
command-working-directory: /
- trigger-rule:
match:
parameter:
source: payload
name: ref
type: value
value: refs/heads/master
pass-arguments-to-command:
- source: payload
name: commits.0.id
- source: payload
name: user_name
- source: payload
name: user_email
execute-command: '{{ .Hookecho }}'
response-message: success
include-command-output-in-response: true
id: gitlab
command-working-directory: /
+12 -3
View File
@@ -21,7 +21,7 @@ import (
)
const (
version = "2.6.4"
version = "2.6.5"
)
var (
@@ -152,7 +152,16 @@ func main() {
}
l := negroni.NewLogger()
l.ALogger = log.New(os.Stderr, "[webhook] ", log.Ldate|log.Ltime)
l.SetFormat("{{.Status}} | {{.Duration}} | {{.Hostname}} | {{.Method}} {{.Path}} \n")
standardLogger := log.New(os.Stdout, "[webhook] ", log.Ldate|log.Ltime)
if !*verbose {
standardLogger.SetOutput(ioutil.Discard)
}
l.ALogger = standardLogger
negroniRecovery := &negroni.Recovery{
Logger: l.ALogger,
@@ -326,7 +335,7 @@ func handleHook(h *hook.Hook, headers, query, payload *map[string]interface{}, b
log.Printf("executing %s (%s) with arguments %q and environment %s using %s as cwd\n", h.ExecuteCommand, cmd.Path, cmd.Args, envs, cmd.Dir)
out, err := cmd.Output()
out, err := cmd.CombinedOutput()
log.Printf("command output: %s\n", out)
+8 -4
View File
@@ -21,7 +21,8 @@ func TestWebhook(t *testing.T) {
hookecho, cleanupHookecho := buildHookecho(t)
defer cleanupHookecho()
config, cleanupConfig := genConfig(t, hookecho)
for _, hookTmpl := range []string{"test/hooks.json.tmpl", "test/hooks.yaml.tmpl"} {
config, cleanupConfig := genConfig(t, hookecho, hookTmpl)
defer cleanupConfig()
webhook, cleanupWebhook := buildWebhook(t)
@@ -77,6 +78,7 @@ func TestWebhook(t *testing.T) {
t.Errorf("failed %q (id: %s):\nexpected status: %#v, response: %s\ngot status: %#v, response: %s", tt.desc, tt.id, tt.respStatus, tt.respBody, res.StatusCode, body)
}
}
}
}
func buildHookecho(t *testing.T) (bin string, cleanup func()) {
@@ -103,8 +105,8 @@ func buildHookecho(t *testing.T) (bin string, cleanup func()) {
return bin, func() { os.RemoveAll(tmp) }
}
func genConfig(t *testing.T, bin string) (config string, cleanup func()) {
tmpl := template.Must(template.ParseFiles("test/hooks.json.tmpl"))
func genConfig(t *testing.T, bin string, hookTemplate string) (config string, cleanup func()) {
tmpl := template.Must(template.ParseFiles(hookTemplate))
tmp, err := ioutil.TempDir("", "webhook-config-")
if err != nil {
@@ -116,7 +118,9 @@ func genConfig(t *testing.T, bin string) (config string, cleanup func()) {
}
}()
path := filepath.Join(tmp, "hooks.json")
outputBaseName := filepath.Ext(filepath.Ext(hookTemplate))
path := filepath.Join(tmp, outputBaseName)
file, err := os.Create(path)
if err != nil {
t.Fatalf("Creating config template: %v", err)