21 Aug 2018 Upgrading Code Reviews With JetBrains’ Upsource
Code reviews are important. They improve code quality, share technical knowledge and keep everyone up to date on what’s going on in your codebase. Some Shiners have recently started using a new tool called Upsource that has helped us become quicker and more effective at code review.
Code review – our process
We use code reviews as a safeguard for code quality – nothing gets deployed to production without a review. We also like it to share the knowledge around, by reading others’ code and having your own examined, you get to learn from everyone else’s technical knowledge, making us all better programmers. Finally, when you have a large team managing a very large codebase, having constant code reviews makes sure that we don’t get stuck with only one or two people knowing how something works and thus being the only people able to work on it.
We use a fairly standard agile workflow with JIRA where a developer picks up a ticket which describes a feature or user story, creates a git branch for it and moves it out of development when it’s complete. A code review is the last step before a JIRA ticket may be marked as finished development. When the programming work is finished, the developer who wrote the code must seek out a review before it can move on. This works well because it means we have a second set of eyes to check over the code and look for issues before it moves past the development stage, and turnaround time on bug fixing is always lower the earlier it happens.
Why the change?
We were originally using GitLab for code reviews. A developer would create a merge request and notify the team, wait for someone to look over it. It can be merged once someone gives it the thumbs up. We had a few problems though. The first is that gitlab’s tool for reading code worked largely like just reading over a text file. There was no code navigation, some syntax highlighting but arguably not the best, and it didn’t feel as intuitive as reading code in your IDE of choice. It provided every file changed in alphabetical order, you couldn’t see what depended on changes and it was very hard to see structure. This made reviews slow and it was hard to be thorough so we weren’t getting the benefits talked about above to the extent we wanted.
Additionally there were a bunch of little issues. We couldn’t get multiple build statuses to show on the merge request so you had to go and manually check the integration test job in Jenkins. The thumbs up wouldn’t be removed if you added more commits to the branch, so if you submitted a review, got an approval, then added another commit, you couldn’t guarantee that the approval was for the code that you were actually going with.
Upsource is a tool for performing code reviews, created by JetBrains. You probably already know of JetBrains because they’ve made an IDE that is either your favourite or was your favourite until you decided all the cool features weren’t worth the loading time. Under the hood Upsource runs on JetBrains’ IntelliJ platform so it has all of the nice code-reading features you expect from a fully fledged IDE.
The first question about a code review tool is how well does it facilitate review? These tools will often come with different bells and whistles but the core experience is what drives it. With Upsource you get a lot of the same features you expect out of an IDE. You can use a tree browser to look at files in context, you can see where an object or function is used and where it is declared and you can get definitions for classes and functions.
This all makes it easier for you to understand the code so you can make more informed comments about it. Commenting is the same as review tools you’d be familiar with – you can make line or review level comments, comments can be marked as resolved, and they support markdown.
Most modern software development processes involve using a lot of different tools. You’ve got your issue tracker, your automation server for running builds and tests, maybe you have a static analysis tool as well. The processing doesn’t stop once you’ve pushed to your Git repository anymore.
Upsource will integrate with all of these tools. You can link between it and your issue tracker of choice (especially if it’s JIRA, it has a whole section in the setup for JIRA integration) and get any number of statuses from your build server. External inspections can be sent to Upsource via an API call, so if your static analysis tool raises issues with your code you can see them as inspections in Upsource, viewed in the same way other IntelliJ based tools show code inspections.
If you’re like me and already use any of the IntelliJ-based IDEs like IntelliJ IDEA then you get an extra feature – you don’t have to leave your IDE to review code! Earlier I talked about how Upsource has a lot of IDE-class features. This takes it even further and lets you just use your IDE to read the code and do the review. Perfect if you’re as lazy as I am!
Upsource has a lot of extra features as well. You can set deadlines for reviews to make sure none of them sit there forever without being looked at, assign people to reviews and automate the process so it randomly assigns people from a group.
You can browse entire repositories or even all of your code that upsource knows about using Upsource’s code browser. It makes it easy to find places where some dependency is being used or some business rule is being followed that needs updating. Because the code browser is a boiled down IDE, this is actually quite a nice experience when you do need to use it.
Finally, to make your team lead happy, there are lots of different statistics and reports available in Upsource. Arguably the most useful is seeing review activity per user so you can tell if only one person is doing all the reviews.
The team I’m a part of has been using Upsource for a few weeks now, and the change has been well worth it. There has been some teething issues – I was asked how to do a merge request by about 15 different people because the UI for the tool itself isn’t that intuitive. Now that it’s all ironed out though and we are starting to get over those issues, it’s clear that this has been a good move. Our reviews are easier than ever, they happen faster and it’s so much easier to provide quality feedback on code. If you’re working somewhere where code reviews happen often (which in theory should be everywhere that code is written by more than one person) I highly recommend looking at Upsource as a way to improve that workflow, or at the very least look around and see if there’s something better that suits your needs. One thing to be aware of is pricing: Upsource is free for up to 10 users, but once you go above that you’ll start paying.