Hubload
Parses post-receive payloads from GitHub
Install
One day I will get around to packaging this up as a gem. For now, I guess you can just clone it.
Usage
To use a post-receive hook for your repo, you’ll need to go into the admin section (or ask someone that has access to it) and click on Post-Receive URLs. See help.github.com/post-receive-hooks/ for more on setting one up.
Largely, this just parses and wraps the values sent from GitHub. However, it adds a couple convenience methods as well for formatting and more intuitive naming( ie - private? method for a repo, etc).
When any commits are pushed to that repo, GitHub will wrap up the commit info in a JSON payload and POST it to the URL you specify. At your post-receive URL, you’ll then be able to parse the payload:
@parsed_load = Hubload.new(params[:payload])
This will give you a Hubload object, which has references to the commits details, namely: before, after, ref, repo, and commits.
Ref
ref = @parsed_load.ref # => Hubload::Ref object
ref.value # => 'refs/heads/master' (or whatever branch)
After / Before
before = @parsed_load.before # => Hubload::After object
before.value # => 027fa2043b65e7d4092ba310966980db5d36a265
after = @parsed_load.after # => Hubload::After object
after.value # => 027fa2043b65e7d4092ba310966980db5d36a264
Repo
You also get info about the commit’s repo
repo = @parsed_load.repo # => Hubload::Repo object
Check out the source for all the info provided by Hubload::Repo. A few examples:
repo.fork? # => false
repo.publicly_visible? # => true
repo.owner # => Hunter Gillane
Commits
GitHub’s post-receive payload can potentially more than one commit. For that reason you’ll get an array of commits in the payload.
commits = @parsed_load.commits # => Hubload::Commit []
Here are some of the methods available for a single commit:
commit_1 = commits[0]
commit_1.pretty_time # => "07:48 PM"
commit_1.pretty_date # => "Jan 1, 2010"
commit_1. => "added some stuff"
etc.
One More Thing
Enjoy!
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 Hunter Gillane. See LICENSE for details.