For those doomed to try reviewing a major amount of diffs in GitHub for a single PR:
- Scroll down the entire list of changes so that GitHub loads all of the collapsible boxes associated with all of the changes
- Open up the inspector/console in the browser devtools. This is probably accessed easily with
ctrl+i
. We want to be in the Console, which in Firefox isctrl+shift+k
. - Type in the following to expand all diffs, in order to avoid needing to click on hundreds of Load diff buttons:
// Expand boxes only for unviewed files that haven't checked the 'Viewed'
// checkbox at the top-right of files within the file reviewer in GitHub UI
Array.from(document.querySelectorAll('.file')).filter(container => !container.querySelector('input.js-reviewed-checkbox:checked')).forEach(pnode => pnode.querySelectorAll('.load-diff-button').forEach(node => node.click()))
Wish GitHub had a Load all diffs button!
It also would be a very good idea to use the checkboxes on the top-right of each file within the GitHub PR UI! It ensures that only modified files in new commits will only uncheck files that have been modified, avoiding needing to review all files over again.
Source GitHub conversation where I found the snippet:
- refined-github/Add support for loading all large diffs at once
- I updated my snippet after seeing an optimized version that will only expand files that haven't already been viewed/reviewed (via the UI checkbox element): https://gist.github.com/juanca/5fd799c5b094e3e4f8b709cd101d7403#gistcomment-3721148
I initially found this JS broswer hack useful when reviewing this PR, which had over 1,000 files modified:
Easiest functionality for me has been to use the gh
(GiHub CLI) and glab
(GitLab CLI) tools.
# pwd / within the repo dir, for GitHub-based repos
gh pr checkout <pr-number>
# pwd / within the repo dir, for GitLab-based repos
glab mr checkout <mr-number>
NOTE: GitHub uses "Pull Requests" (PRs), while GitLab refers to them as "Merge Requests" (MRs).
Alternatively, git
commands can be used to checkout a PR/MR:
# $ID = pull request id
# $BRANCHNAME = name of new branch you wish to create for it locally
git fetch origin pull/$ID/head:$BRANCHNAME
git checkout $BRANCHNAME
In repositories you are contributing to, it's a good idea to configure your local forked copy to also reference the upstream repo you forked from. This allows for easily updating your fork to be synced with the upstream.
Example, using the salt
repo. This path assumes that you're setup for Connecting to GitHub with SSH.
# Using SSH key method, clone down your fork
git clone [email protected]:<forked-repo-path>/salt.git
cd salt
# Using SSH key method for upstream remote config
git remote add upstream [email protected]:saltstack/salt.git
I store this script as git-sync
somewhere in my $PATH
.
# Example file location: ~/.local/bin/git-sync
# Simple script for git usage
# git-sync master
# git-sync main
git checkout $1
git fetch upstream
git pull upstream $1
git push origin $1
From within my salt
repo, I can now sync a specific branch.
git-sync master
Now my fork of salt
has synced the master
branch with what is upstream in the main salt
repo.