Skip to content

Instantly share code, notes, and snippets.

@aal89
Last active June 30, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aal89/4e535f92ba4cdfec576941e9eb331b1a to your computer and use it in GitHub Desktop.
Save aal89/4e535f92ba4cdfec576941e9eb331b1a to your computer and use it in GitHub Desktop.
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
Copy link
Author

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