Last active
October 18, 2018 14:30
-
-
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.
This file contains hidden or 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
// ==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> </p><p> </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); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: