Where i work we use GitHub for scm and PivotalTracker for our task management. When we started with our code reviews we wanted the pull request process to be as unobtrusive as possible. Here is what we did to automate as much as possible.
Our code review workflow
- Start the task in PivotalTracker
- Create a new feature branch by checking out origin/develop under a new name.
- Prefix all commits with [#task_id] to have them show up in PivotalTracker.
- When you are done prefix your last commit message with [fixes #task_id]. This will mark the PivotalTracker task as “Fixed” and a pull request will be created automatically.
- When you peer has reviewed the code and wants to merge it, he or she should prefix the merge message with [delivers #task_id]. If the last commit was correctly prefixed with [fixes #task_id], this is only a matter of changing one word as the last commit message will be pre-populated with the last commit message automatically.
- Delete the branch using the button that appears after merging the PR.
The improvements to the usual process are that you never have to go to PivotalTracker and click “Done”, or “Deliver”. You also never have to go to GitHub.com and create a PR every time. This is all done automatically via a GitHub service hook and a local pre-push hook.
Making it happen
- Set up a service hook in GitHub for PivotalTracker. Go to repository settings via the wrench icon on the right on your repository page on GitHub. Then click Webooks & Services and finally Add service and select PivotalTracker. Paste your API key from PivotalTracker and you’re set.
- Install “hub” via homebrew: brew install –HEAD hub
You may need to invoke hub pull-request manually once to feed it your GitHub login details.
- Install this script as a pre-push hook by putting it in .git/hooks/pr.pre-push.sh in your project and making it executable with chmod +x .git/hooks/pr.pre-push.sh: https://gist.github.com/maciekish/af85f320e0595f8e3cd7#file-pre-push
Now, whenever you push a local branch not named develop or master to origin, and the commit message contains the text [fixes #task_id] a pull request will be created automatically for your peers to review. Isn’t that neat?