Hacker News new | ask | show | jobs
by pmcollins 1483 days ago
My brain is a very bad virtual machine and it's very bad at parsing diffs (even GitHub ones), so I like to check out the code under review locally, browse it and see what my IDE says about it (thank you JetBrains), run it, and run the tests while stepping through the code. Makes a big difference.
5 comments

One of the best moves our team ever made was moving to code review means actually checking out and running the code in our IDE. So many little improvements happened: logs got better, runtime-messages got better. Since we were reviewing in the IDE, running the profiler was a snap, and dropping a breakpoint in a diff lising let the reviewer inspect state right at the point of change. Another benefit: it was a lot easier to fix bugs found in review than just punt to the original developer... so the reviews became a lot less painful.
That’s an underappreciated technique, and I’m not sure why. Someone once remarked (verbally) in the context of a code review that they would need to run the code to fully understand it, to which I replied “Why don’t you?” The look on their face was priceless, first confusion, then enlightenment. There’s no law or invisible wall that prevents you from leaving that web-based diff viewer.
A previous coworker taught me to do this :finger-guns: I use VSCode with the GitHub pull requests extension now, and it's such a better experience than attempting to review directly on github.com. My reviews are not just quicker but also higher quality since I can easily step through code changes directly in the IDE. Great advice.
I have this script:

    $ cat ~/bin/git-pr 
    #!/bin/sh
    
    if [ $# -lt 1 ]; then
      exit -1
    fi
    
    git fetch origin refs/pull/$1/head:pr/$1
So I can run `git pr <number>` to get `pr/<number>` branch created locally that I can checkout to.
Also there is github cli for checking out PR

     $ gh pr checkout {<number> | <url> | <branch>}
You can also configure git to fetch the GitHub PR branches[0]. Add this line to your .git/config:

    fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
This has to be done in each repository you have checked out locally, but maybe it is possible to also have this done globally. But I never tried to do it.

[0] http://tiborsimko.org/github-local-handling-of-pull-requests...

You can add to the set of refs that git pulls (via remote.origin.refs); so for me it's `git checkout pr/123/head` (or /merge) instead, without creating a local branch that you need to delete later.
IntelliJ's integration with GitHub PRs is nice. The one thing I miss is you can't what changed if you switch from the PR diff view to the normal code view which you need for code navigation and refactoring.