Skip to content

Instantly share code, notes, and snippets.

@unixcharles
Created June 12, 2010 19:15
Show Gist options
  • Save unixcharles/435990 to your computer and use it in GitHub Desktop.
Save unixcharles/435990 to your computer and use it in GitHub Desktop.

User can generate url/key for project when they have the right to comment:

teambox.com/hooks/:key

Each key tie to project and user

@hook = Hook.find_by_key(params[:key])

Optional params

format

teambox.com/hooks/:key (none, params => directly to mustache)

teambox.com/hooks/:key/json (params => JSON.parse)

teambox.com/hooks/:key/xml (params => XML.parse)

template

So that the hook mustache template can be self contained into the post:

post >> teambox.com/hooks/:key?say=world&template=hello {{say}}

render >> "hello world"

Without params[:template], it will fallback to @hook.message

Template Exemple for github hook:


{{#payload}}
### New code on {{#repository}}[{{name}}]({{url}}){{/repository}} ###

{{#commits}}
Commit [{{id}}]({{url}})
Message: {{message}}
from {{#author}} [{{name}}](mailto:{{email}}){{/author}}

{{/commits}} before: {{before}}
After: {{after}}
{{/payload}}

From there, configure github to post at /hooks/YOUR-API-KEY/json

json data from Github are contained in to the payload field and look like that:


      {
        "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
        "repository": {
          "url": "http://github.com/defunkt/github",
          "name": "github",
          "description": "You're lookin' at it.",
          "watchers": 5,
          "forks": 2,
          "private": 1,
          "owner": {
            "email": "chris@ozmm.org",
            "name": "defunkt"
          }
        },
        "commits": [
          {
            "id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
            "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
            "author": {
              "email": "chris@ozmm.org",
              "name": "Chris Wanstrath"
            },
            "message": "okay i give in",
            "timestamp": "2008-02-15T14:57:17-08:00",
            "added": ["filepath.rb"]
          },
          {
            "id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
            "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
            "author": {
              "email": "chris@ozmm.org",
              "name": "Chris Wanstrath"
            },
            "message": "update pricing a tad",
            "timestamp": "2008-02-15T14:36:34-08:00"
          }
        ],
        "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
        "ref": "refs/heads/master"
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment