Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.