Polish Your PRs đ + Rev Up Your Reviews đ
Itâs first thing Monday morning, youâve opened up your email and noticed that @en6in33r [Handle changed to protect the innocent. -Ed] has requested you to review their PR. You open it up and discover that it has no description, contains 29 commits, changes 73 files with 3,000+ additions and 2,300+ deletions. đŽ Where do you begin?!
Defining a standard for how PRâs should be formatted and clear goals for reviewing peersâ code is helpful for ensuring that feedback is meaningful and that the process is efficient amongst the team.
Weâve worked to improve the review process on the Front End team over at Turo. Here are some of the helpful tips weâve learned along the way.
Note: this blog revolves around using git/GitHub for a teamâs version control and code review process. Youâll still be able to use and adapt these tips within a different toolset.
It starts with your commits
A long time ago, in a galaxy far far away, there once was an Engineer that committed their changes like this:
> Fix the bug> Jk that didnât fix it, this time itâs fixed> OMG WHY IS THIS BUG STILL HERE> Final bug fix> Final final bug fix
Well, maybe that hits a little closer to home⌠it might have been you⌠yesterday. Weâve all done it.
Committing often (and pushing) is valuable. It helps guarantee that if your computer decides to retire right before a deadline, that your work wonât be lost. On the other hand, doing so can convolute the commit history and make it hard to understand whatâs going on.
- Clean up your commit history if it gets messy â If you do find yourself in the situation above, before submitting your code for review, rebase against master (or whichever branch is your base for releasing) and clean up your commits. This will help structure your changes in a way that makes it easier for your fellow reviewer to parse.
- Explain why the change is necessary â Though the names of functions and variables should be descriptive enough to inform what the code is doing, commit messages should aim to answer both what is happening and why it needs to happen.
An example â say that you have a React button component that needs to be extended to allow it to display in different colors depending on which type of user is viewing it. Even a simple change can benefit from a thought out commit message:
Not good:
> Add button colorGood.
> Add color prop to allow Button to be green for Guests or purple for Owners
Everything cleaned up and ready to go? Time to open a Pull Request (PR)!
Fill out the Description
Going back to the (coughnightmarecough) PR that I shared at the beginning âcan you tell what itâs about? No? Itâs important for Engineers to provide sufficient context to the people reviewing their changes. It can be hard (or nearly impossible) to provide a successful review without being given all of the appropriate information at the startâ and tracking down these pieces can add a lot of extra time.
Consider including the following in your next PR to help your fellow reviewer:
- Link to the product requirements â At Turo, we use Jira to track and break down the features that we are working on. A link to the Jira ticket (or tickets) that are involved in a PR are included in the PRâs Description in order to make it convenient for the reviewer to look back at the acceptance requirements.
- Give it a meaningful title â Typically, we include the ticket number and name.
- Summarize the changes â in a few sentences, what is in this PR and why is the change required. (Hint: you might be able to copy this directly from the original task ticket)
- State how to test the feature â Does the Reviewer need to be signed in with a specific test account? Is there a URL for a test instance that they should use to test? Describe the user experience/flow that they would need to go through in order to reach the feature or confirm the absence of the bug.
- List any actions you need to take before this is deployed â Sometimes you have tasks, like waiting for translations to be completed or deploying another branch, that will hold up a PR from being merged, but they may not be a blocker for getting a review. Noting these in the PR prevents the reviewer from taking the time to leave comments when the items are already on your radar.
- Provide screenshots of the before and after when making a UI change or introducing a new component. Iâve found that creating Markdown tables* helps to clearly display the changes side by side.
Markdown in GitHub PR and result:
| Before | After |
| --- | --- |
| ![alt text](link to image)|![alt text](link to image)|
Requesting Review
We are responsible for deploying our own code at Turo, and each Engineer is responsible for making sure that their work gets the eyes đthat it needs before it can be shipped đ˘. Our Engineering team guideline is that each PR gets two â /đ review approvals before it can be deployed.
- Be clear about deadlines â Everyone has a lot of work on their plate, so if you arenât clear about when you need the review by, it could drop to the bottom of someoneâs to-do queue. If it fixes a major product bug or a new feature is being scheduled to go out alongside a marketing announcement, make sure that the Reviewer is aware and can plan accordingly.
- Be clear about what youâre looking to have reviewed â Is this a work in progress that you want an initial round of feedback on to make sure that youâre making good architecture decisions? Is this feature in its final form and ready to ship ASAP? Is it a proof-of-concept for a library youâre considering utilizing?
- Request review from someone whoâs familiar with the code â If youâre working in an existing feature, consider asking someone that has worked in the space before to review the changes. Their familiarity with it will afford a quicker understanding of the changeâs context and potentially lead to a shorter turn around.
- Alternatively, request review from someone who is new to this part of the code base â Requesting review from someone that has less familiarity with the area is also valuable. Though it may take a bit longer for them to understand the context and get through the review, they come in with a fresh set of eyes that may catch an edge case or bug that you missed due to running through the same flow so many times during development.
- Avoid rebasing after youâve requested a review â As a reviewer, it can be hard to tell whatâs new vs. what youâve already looked at. If you absolutely need to rebase, check in with your Reviewers to make sure itâs not going to impact their progress.
Pro tip: if waiting for code review is a blocker for moving on to the next item on your to-do list and thus leaves you with some free time, offer to take a look at a PR opened by the Reviewer you just requested in order to help open up their plate. Teamwork!
Leaving and responding to feedback
First and foremost, be respectful. There is always more than one way to write a piece of code and itâs okay to have different opinions. To the Reviewer, ask for clarification if something doesnât make sense. To the Committer, donât be offended by suggestions.
- Be conscious of how you phrase comments â Comments that contain required and suggested changes should be distinguishable from one another. When leaving comment for a required, merge-blocking change, explain why it needs to be addressed (e.g. a given line or segment does not meet a team standard).
- Link to documentation to further explain the problem or support the suggestion that you are making
> Not good:
This should be a boolean.> Good.
We've stored a variable like this in the past as a boolean instead of a string [link to file]. I would suggest doing that here too.
- Respond to comments as soon as you can after someone reviews your work. As a product and team continues to grow (join us!), the number of PRs does too. To ensure that everything is staying on track, itâs up to the owner to continue to play an active role in getting their work through the review process.
- Take larger discussions offline â If thereâs a back and forth that seems to continue to go on, donât hesitate to chat in person â sometimes thatâs more efficient. Make sure to summarize any decisions made offline in the PR to keep everyone involved up to date.
- Lint your code! By utilizing ESLint and Prettier weâve been able to produce a consistent code style amongst our team. Gone are the days when a PR ends up with a dozen âdelete these extra linesâ, âadd a semi-colonâ, âthis line is too longâ comments. A linter will highlight code that doesnât adhere to certain style guidelines and Prettier will look at the set of rules the team has established and reprint the code to follow them. Itâs a HUGE time saver.
Thatâs all folks đ
Whether youâre opening PRâs or reviewing (most likely both), I hope that some of these tips will help make the code review process smoother for you and your team.
Bonus tip: If your team uses Slack, you can set up a slackbot to post previews of each GitHub PR that is opened. Images and gifs are rendered in the preview and make for a great way to grab your peerâs attention to persuade them to check out your PR đ. Here are some of my favorites: