Webhook: Can't match Github's ping event

Created on 15 Dec 2018  路  9Comments  路  Source: adnanh/webhook

Hello,

while trying to configure a simple webhook to listen to Github API ping, I couldn't make the rules to work :(

This is the config file I'm using:

[
  {
    "id": "github",
    "execute-command": "my-script.sh",
    "command-working-directory": "/tmp",
    "trigger-rule-mismatch-http-response-code": 422,
    "pass-arguments-to-command": [],
    "trigger-rule": {
      "match": {
        "parameter": {
          "source": "header",
          "name": "X-GitHub-Event"
        },
        "type": "value",
        "value": "ping"
      }
    }
  }
]

When I run webhook I got the following error:

github got matched, but didn't get triggered because the trigger rules were not satisfied

This is how I'm running it:

webhook -verbose -hotreload -hooks hooks.json

You can emulate the github webhook call with curl:

curl -H "X-GitHub-Event: ping" -X GET http://localhost:9000/hooks/github

What am I missing here?

Thank you for your awesome work!

All 9 comments

It's working locally with curl for me. What version of webhook are you using?

I'm using 2.5.0 that is provided by Ubuntu 18.04 LTS

Could you please try updating to the latest version? You can download binary from the Releases page or compile it yourself.

I'm a similar issue with travis and can't figure it out. I am using webhook version 2.6.9

My webhook is this

[
  {
    "id": "deploy",
    "execute-command": "/root/foodcomputer-server/deployment.sh",
    "command-working-directory": "/root/foodcomputer-server",
    "trigger-rule":
    {
      "match":
      {
        "type": "value",
        "value": "master",
        "parameter":
        {
          "source": "payload",
          "name": "branch"
        }
      }
    }
  }
]

I can trigger it fine using something like this:

 curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "state=passed&branch=master" https://myurl.io:9000/hooks/deploy

I've even debugged travis's webhook using https://requestbin.fullcontact.com/, and it looks like this in the payload, sent as application/x-www-form-urlencoded:

{
  "id": 100376464,
  "number": "33",
  "branch": "master",
  .... lot more info
}

I've tried running webhook as both a service and from the command itself. I am using https, I'm running the command like this:

/usr/bin/webhook -secure -cert /path/to/cert.pem -key  /path/to/key.pem -verbose -nopanic -hooks /etc/webhook.conf

every time the request is from travis, I get

[webhook] 2019/02/10 21:55:29 [c9a5bb] deploy got matched
[webhook] 2019/02/10 21:55:29 [c9a5bb] deploy got matched, but didn't get triggered because the trigger rules were not satisfied

I feel like I'm missing something really obvious or there is a bug. I can open a new issue if its warranted.

Thanks for making this tool!

@johnpmitsch According to the Travis CI documentation

Webhooks are delivered with a application/x-www-form-urlencoded content type using HTTP POST, with the body including a payload parameter that contains the JSON webhook payload in a URL-encoded format.

Which means they're sending something like this:

payload=<json string>

In order to access such properties, you have to add parse-parameters-as-json declaration to your hook like so:

 "parse-parameters-as-json": [
      {
        "source": "payload",
        "name": "payload"
      }
    ]

and then, in the trigger rule you'll have to change the parameter name to payload.branch, and it should work fine.

@adnanh

I tried this and still can't get a trigger, is it the correct syntax?:

[
  {
    "id": "deploy",
    "execute-command": "/root/foodcomputer-server/deployment.sh",
    "command-working-directory": "/root/foodcomputer-server",
    "parse-parameters-as-json": [
      {
        "source": "payload",
        "name": "payload"
      }
    ],
    "trigger-rule":
    {
      "and":
      [
        {
          "match":
          {
            "type": "value",
            "value": "passed",
            "parameter": {
          "name": "payload.state"
        }
          }
        },
        {
          "match":
          {
            "type": "value",
            "value": "master",
            "parameter": {
          "name": "payload.branch"
        }
          }
        }
      ]
    }
  }
]

You need the "source": "payload" in the parameter declaration:

...
    "match":
          {
            "type": "value",
            "value": "passed",
            "parameter": {
          "name": "payload.state",
              "source": "payload"
        }
          }
...

@adnanh thank you so much, that worked! I submitted a PR in case you want to add an example to the docs https://github.com/adnanh/webhook/pull/304

@johnpmitsch great :-) Thank you :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichelDiz picture MichelDiz  路  5Comments

gedw99 picture gedw99  路  3Comments

simplenotezy picture simplenotezy  路  4Comments

sfxworks picture sfxworks  路  5Comments

dcj picture dcj  路  5Comments