(This is only a concept, but I proved out all the parts seperately so they should work together)
The downside of github hooks is that right now the only one available through the web is when the repo receives a push. We wanted to have the repo update anytime anyone merges a pull request into the master branch.
I found this walkthrough which sets a repo up to pull from a normal github hook: https://gist.github.com/oodavid/1809044
So if you follow that entire guide but then switch out the “Set up service hook” piece for what I have below it should work.
Setting up a hook on a pull request
First go into github and click on account settings, then Applications and generate a personal access token.
Then using a rest client POST the following, you’ll need to setup a http://requestb.in/ to view the payload:
Header: Authorization token personal_access_token_XXXXXXXXXXXXXXXXXXXX
1 2 3 4 5 6 7 8
Using the “Advanced REST Client” extension in chrome it looks something like this:
Send that and you should get a success message.
Now do a pull request / merge inside github and check your request bin and you should have a huge payload in there.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
So now going back to that walkthrough, inside your deploy.php page just check the payload for a state of “closed” and you can do a git pull. If the pull request was rejected the state will also be closed and this will still do a pull, but the app will simply be up to date so everythings kosher. You should also be able to check for which branch the pull request was on, but once again, pulling everytime a pull request is closed shouldn’t be a big deal.
This hook will now show up in Github under Settings -> Service Hooks -> WebHook URLS
- How to setup pull_request hook
- Receive POST payload
- Github API
- Github Hooks Api
- Deploy via hooks