Skip to content

Instantly share code, notes, and snippets.

@sorenlouv
Last active November 23, 2018 14:33
Show Gist options
  • Save sorenlouv/d71032c5d81c0fcd38722d23711444f5 to your computer and use it in GitHub Desktop.
Save sorenlouv/d71032c5d81c0fcd38722d23711444f5 to your computer and use it in GitHub Desktop.
Count lines-of-code changed on Github PR excluding certain files
/*
The number of changed files (additions/deletions) includes all files.
I wanted to see how many files I had changed, excluding tests and test snapshots.
This filter will help you do that.
To use it, go to the PR, navigate to "Files" and invoke the following
*/
(function() {
const excludeWords = ['test', 'mock-responses', 'typings'];
document.querySelector('.toc-select button').click();
setTimeout(() => {
const { added, deleted } = Array.from(
document.querySelectorAll('.select-menu-item-text')
)
.filter(item => item.querySelector('.filename') !== null)
.map(item => {
const trimNumber = elm => {
if (!elm) {
return 0;
}
return parseInt(
elm.innerText
.trim()
.slice(1)
.replace(/,/g, ''),
10
);
};
const added = trimNumber(item.querySelector('.text-green'));
const deleted = trimNumber(item.querySelector('.text-red'));
const filename = item.querySelector('.description').innerText.trim();
return { added, deleted, filename };
})
.filter(item => !excludeWords.some(word => item.filename.includes(word)))
.reduce(
(acc, item) => {
console.log(item);
acc.added += item.added;
acc.deleted += item.deleted;
return acc;
},
{ added: 0, deleted: 0 }
);
document.querySelector('.diffstat .text-green').innerText += `(${added})`;
document.querySelector('.diffstat .text-red').innerText += `(${deleted})`;
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment