Code Review

Code Review

This file contains useful information about conducting code reviews.

When we review a big pull request, it is very hard to understand from the Github page how things are connected inside the project.

That’s why I believe it is best to fetch the code and review it inside a text editor, but along with this, we need to make some tweaks. The tweaks should make it easier to review code inside the text editor. The best way I have found so far is to make the commit we are reviewing appear as a new commit in the code - which it is - and utilize the editor’s highlighting resources.

Add the following aliases to your shell source file, eg. zshrc

1
2
3
4
5
6
# git pull-request review
alias gpw='git reset --soft HEAD~1; git restore --staged .'
 
# git pull-requrest restore
alias gpr='git reset --hard HEAD@{1}'
 

Source the file (. ~/.zshrc).

Now, we have two more aliases that can be used when reviewing a pull request.

gpw will take our current HEAD commit and move it back one commit, making the commit we are reviewing appear as if we made the changes. With this change, in VSCode for example, it’s a lot easier to follow where the changes are, what they are intended to do, and how they fit into the bigger picture.

After the review, we can restore everything as it was with the gpr alias.

good read:

sean goedecke - Mistakes I see engineers making in their code reviews