Last active
January 4, 2017 08:00
-
-
Save dhoko/6edfe263813388811555 to your computer and use it in GitHub Desktop.
Count lines added/removed with Bitbucket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
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`); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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