Skip to content

Instantly share code, notes, and snippets.

@aal89
Last active October 18, 2018 14:30
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/dfb9262687ddfcc8ec0f1f26c61b76e3 to your computer and use it in GitHub Desktop.
Save aal89/dfb9262687ddfcc8ec0f1f26c61b76e3 to your computer and use it in GitHub Desktop.
Tampermonkey script to clearly notify users of PR's that should not get approved/merged yet.
// ==UserScript==
// @name Clearly notify for unstable builds in Bitbucket
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Clearly notifies the user if the PR should not be merged and/or approved.
// @author Alex
// @match https://bitbucket.org/vdgsecurity/vdg-vms/pull-requests/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener('load', function () {
try {
var build_data_ele = document.querySelector('#pull-request-diff-header > div.aui-item.detail-summary--panel > ul > li:nth-child(1) > div > a > span:nth-child(1)');
var build_data = JSON.parse(build_data_ele.getAttribute('data-status-counts'));
appendMessage('<small>All systems are go!</small>', 0);
if(build_data && build_data.SUCCESSFUL === 0) {
appendMessage('<small>No successful builds.</small>');
}
if(build_data && build_data.INPROGRESS > 0) {
appendMessage('<small>A build is in progress.</small>');
}
} catch(e) {
if(window.location.href !== 'https://bitbucket.org/vdgsecurity/vdg-vms/pull-requests/' &&
!window.location.href.startsWith('https://bitbucket.org/vdgsecurity/vdg-vms/pull-requests/new?')) {
appendMessage('<small>Missing build data?</small>', 2);
}
}
}, false);
function appendMessage(msg = '', style = 1) {
var css = 'position: absolute; float: right; right: 20px; top: 25px; background-color: white; width: 334px;';
if(document.body.lastChild.style.cssText === css) {
document.body.removeChild(document.body.lastChild);
}
var elem = document.createElement('span');
elem.style.cssText = css;
if(style === 0) {
elem.innerHTML = `<br><h2><font color=green>You may merge/approve!</font></h2>${msg}`;
} else if(style === 1) {
elem.innerHTML = `<p>&nbsp;</p><p>&nbsp;</p><br><h2><font color=red>Do <strong>not</strong> merge/approve!</font></h2>${msg}`;
} else if(style === 2) {
elem.innerHTML = `<br><h2>Error!</h2>${msg}`;
}
document.body.appendChild(elem);
}
})();
@aal89
Copy link
Author

aal89 commented Oct 18, 2018

A messy script that was quickly hacked together. But it seems to work. These messages are not shown for the PR overview page and creation page.

Output:


screenshot 2018-10-18 at 11 33 10


screenshot 2018-10-18 at 14 52 20 1


screenshot 2018-10-18 at 11 33 38


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