Skip to content

Instantly share code, notes, and snippets.

@monkpit
Forked from kpittman-securus/cleanupPR.js
Created April 28, 2021 23:18
Show Gist options
  • Save monkpit/2070c5204625d64f3eea588d5e00e934 to your computer and use it in GitHub Desktop.
Save monkpit/2070c5204625d64f3eea588d5e00e934 to your computer and use it in GitHub Desktop.
Mark deleted as viewed, sort all files by number of changes
const container = $('#files');
const files = Array.from($$('.file'));
const getSortText = (el) => el.querySelector('.diffstat').innerText;
files.sort((a, b) => {
const aSortText = getSortText(a);
const bSortText = getSortText(b);
if (aSortText > bSortText) return 1;
if (aSortText < bSortText) return -1;
return 0;
});
container.innerHTML = ''
for (const file of files) {
container.appendChild(file);
}
const openFiles = Array.from($$('.file.open'));
const deletions = openFiles.filter(file => file.querySelector('.diffstat[aria-label*=": 0 additions"]'));
const markAsViewed = (fileEl) => fileEl.querySelector('[class*=reviewed-toggle]').click();
deletions.map(markAsViewed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment