Using Webhooks

What are webhooks?

Webhooks provide a way to trigger a remote URL when a repository is committed or pushed to. They provide a simple way for you to trigger your own operations to take place after a repository is updated.

How do you add a webhook?

To enable a webhook, simply go into your repository and choose the Settings tab from the top bar. Within the Preferences section, add the URL the request should be to in the the "Post-Receive URL Hooks" textbox. You can specify multiple URLs by putting one per line.

webhooks-1.jpg

How do they work?

After a repository is committed to or pushed to, Trunks will make an HTTP POST to the URLs listed in the box. The request will include a payload detailing the changes in the update.

Trunks follows the same payload structure as GitHub, allowing you to easily re-use hooks you might have already created.

The payload is POSTed as form data under the "payload" parameter and is JSON encoded. The structure of the payload is as follows:

{
  :before     => before,
  :after      => after,
  :ref        => ref,
  :commits    => [{
    :id        => commit.id,
    :message   => commit.message,
    :timestamp => commit.committed_date.xmlschema,
    :url       => commit_url,
    :added     => array_of_added_paths,
    :removed   => array_of_removed_paths,
    :modified  => array_of_modified_paths,
    :author    => {
      :name  => commit.author.name,
      :email => commit.author.email
    }
  }],
  :repository => {
    :name        => repository.name,
    :url         => repo_url,
    :private     => true,
    :owner => {
      :name  => repository.owner.login,
      :email => repository.owner.email
    }
  }
}