Review your code with GitHub Code Review

It might be hard to believe, so please stop reading for just a minute and go find some of your old code. No, seriously. Do it. I'll wait.

You’re back? Good. Now tell me, what do you think about that code? I know. It’s bad. Right now you’d certainly write it in a completely different and better way. And I believe you. The problem is, however, in a year you’ll have the same opinion about your present coding skills. Put this way, your code will always suck no matter what. (That’s a good thing! If it didn’t, you wouldn’t be able to see its flaws or tinker and refactor it, something that's always possible. You should really begin to worry when a piece you wrote a long time ago still looks good. It's a sign that you haven’t progressed.)

Please note: I’m not telling you this to make you feel bad. I’m telling you this because it’s important for our craft. My coworkers act the same way when they ask me what the hell I was thinking when I committed that hackish workaround. They do it because they care.

The truth is, the only way to produce good code as a team is to let others review it and then apply their feedback. (It’s also a lot faster than waiting a year to improve it yourself, you know.) Your skills are augmented by the abilities of the rest of the team. As it happens, we at Monterail built an internal tool exactly for this that we are now open-sourcing, because, well, we’re team players and let’s be honest: we love you.

GitHub Code Review

It’s called GitHub Code Review.

Some of you may have already heard of it. During wroc_love.rb, I had a lightning talk that explained all the details of GHCR.

Next, install the browser extension and go to the settings page to provide the URL for GHCR API.

Click the Save button, and then the Authorize button.

Select the repository from the list to connect it to the API, or navigate to the repository’s settings page on GitHub and press the Connect button.

Done! From now on, when you commit anything to the repository, it gets recorded in your instance of the GHCR API via a GitHub hook.

How do you use it? Simply go to your GitHub repository, then click on the pending commit counter and begin your code review session.

At the top of a commit, you’ll see a bar with three new buttons: Next pending, Accept, Discuss.

Next pending — moves you to another not yet reviewed commit.

Accept — marks the commit as accepted.

Discuss — marks commit up for discussion. (It used to be the Reject button, but we felt it might be too offensive. Not like the beginning of this post.)

The GHCR API will send a HipChat notification to the committer who wrote the code that you have doubts about. Please use GitHub comments to point out which parts of the code concerned you.

Here's the best part: thanks to the stats in the API, we can show the pending commits counter on a TV in a location in the office where all of us can see it. When it gets too high, it becomes a trigger for the team to review some commits. Just try it yourself!