Skip to content

Instantly share code, notes, and snippets.

@dhoko
Last active January 4, 2017 08:00
Show Gist options
  • Save dhoko/6edfe263813388811555 to your computer and use it in GitHub Desktop.
Save dhoko/6edfe263813388811555 to your computer and use it in GitHub Desktop.
Count lines added/removed with Bitbucket
(() => {
const CLASS_LIST = [
{type: 'added', className: '.lines-added'},
{type: 'removed', className: '.lines-removed'}
];
const stats = CLASS_LIST
.reduce((accus, o) => {
const total = Array
.from(document.querySelectorAll(o.className))
.map(item => +item.textContent.trim().slice(1))
.filter(Boolean)
.reduce((a, b) => a+b, 0);
accus[o.type] = total;
return accus;
}, {});
console.log(`There are ${stats.added} lines added and ${stats.removed} lines removed`);
})();
(function countLines() {
var stats = {
added: 0,
removed: 0
};
var counter = function(className) {
return Array.prototype.map
.call(document.querySelectorAll(className), function(item) {
return +item.textContent.trim().slice(1)
})
.filter(Boolean)
.reduce(function(a,b) {
return a + b;
},0) || 0;
};
stats.added = counter('.lines-added');
stats.removed = counter('.lines-removed');
console.log('There are %d lines added and %d lines removed', stats.added, stats.removed);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment