Webhook

A simple HTTP server is written in Go to take incoming webhooks and execute actions. It supports methods of validating webhook secrets, and can pass values provided from the hook call into shell scripts.

Example Webhooks

From GitHub

Accepts a GitHub actions call, and validates a secret set on the call in Github.

[
    {
        "id": "hugo",
        "execute-command": "/usr/local/src/hugo-sites/hugo-update.sh",
        "command-working-directory": "/usr/local/src/hugo-sites",
        "trigger-rule": {
            "match": {
                "type": "payload-hmac-sha1",
                "secret": "xxxxxxxxxxxxx",
                "parameter": {
                    "source": "header",
                    "name": "X-Hub-Signature"
                }
            }
        }
    },
]

Pass arguments from the webhook to the command line

Same as above, but passes in the repositories’ SSH URL to allow for the script to understand the source repository the webhook has come from. Uses the pass-arguments-to-command setting.

The value repository.ssh_url represents the path in the JSON submitted as part of the webhook.

[
  {
    "id": "hugo",
    "execute-command": "/usr/local/src/hugo-sites/hugo-update.sh",
    "command-working-directory": "/usr/local/src/hugo-sites",
    "pass-arguments-to-command": [
      {
        "source": "payload",
        "name": "repository.ssh_url"
      }
    ],
    "trigger-rule": {
      "match": {
        "type": "payload-hmac-sha1",
        "secret": "xxxxxxxxxxxxx",
        "parameter": {
          "source": "header",
          "name": "X-Hub-Signature"
        }
      }
    }
  },
]

References


Last updated: