Last active
January 6, 2023 02:28
-
-
Save chaoyangnz/12a6a279885f04d29f7f4143fcfd9973 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name buildkite-unblock | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description unblock builkite job | |
// @author Chao | |
// @match https://buildkite.com/*/builds/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const buttons = document.querySelectorAll('.build-pipeline-job-manual:not(.build-pipeline-state-unblocked)') | |
if (buttons.length == 0) return | |
const buildStatus = document.querySelector('.build-status-icon') | |
const unblockButton = htmlToElement('<div style="margin: auto 5px"><button>Unblock</button></div>') | |
buildStatus.parentNode.insertBefore(unblockButton, buildStatus.nextSibling) | |
unblockButton.addEventListener('click', () => unblockAll(buttons)) | |
})(); | |
function unblockAll(buttons) { | |
let i = 0 | |
const next = () => { | |
i += 1 | |
if (i < buttons.length) { | |
unblock(buttons[i], next) | |
} else { | |
document.location.reload(true) | |
} | |
} | |
unblock(buttons[0], next) | |
} | |
function unblock(button, next) { | |
console.info('unblocking', button) | |
button.click() | |
when('.Dialog__Box', () => { | |
document.querySelector('.Dialog__Box input[value=yes]').checked = true | |
document.querySelector('.Dialog__Box button[type=submit]').click() | |
until('.Dialog__Box', next) | |
}) | |
} | |
// utilities | |
function htmlToElement(html) { | |
var template = document.createElement('template'); | |
html = html.trim(); // Never return a text node of whitespace as the result | |
template.innerHTML = html; | |
return template.content.firstChild; | |
} | |
function when(selector, fn) { | |
const elem = document.querySelector(selector) | |
if (elem) { | |
fn(elem) | |
} else { | |
setTimeout(() => when(selector, fn), 100) | |
} | |
} | |
function until(selector, fn) { | |
const elem = document.querySelector(selector) | |
if (!elem) { | |
fn() | |
} else { | |
setTimeout(() => until(selector, fn), 100) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment