Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show total changed lines of code for all files combined in a PR (new view) on Bitbucket. This is a TamperMonkey script.
// ==UserScript==
// @name Bitbucket totals in PR
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Show total changed lines of code
// @author You
// @match https://bitbucket.org/*/*/pull-requests/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener('load', function() {
setTimeout(() => {
const total = (a, c) => a + c;
const innerToInt = ele => parseInt(ele.innerHTML);
const containsNumber = ele => ele.innerHTML.match(/^[+-].\d*$/);
const allSpanTags = Array(...document.getElementsByTagName('span'));
const totalForAllNumbers = allSpanTags.filter(containsNumber).map(innerToInt).reduce(total, 0);
const colorInt = (int) => parseInt(int) < 0 ? `<font color=darkred>${int}</font>` : `<font color=green>${int}</font>`;
// set the total change number next to header text for that column
document
.querySelector('#PullRequestWelcomeTourTarget-Files > section > button > span:nth-of-type(2) > span')
.insertAdjacentHTML('beforeend', ` <small>affected lines: <b>${colorInt(totalForAllNumbers)}</b></small>`);
}, 500);
}, false);
})();
@aal89

This comment has been minimized.

Copy link
Owner Author

@aal89 aal89 commented Jun 30, 2020

Result:

image

(this particular PR removed more lines of code than it added)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment