Skip to content

Instantly share code, notes, and snippets.

@chaoyangnz
Last active January 6, 2023 02:28
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 chaoyangnz/12a6a279885f04d29f7f4143fcfd9973 to your computer and use it in GitHub Desktop.
Save chaoyangnz/12a6a279885f04d29f7f4143fcfd9973 to your computer and use it in GitHub Desktop.
// ==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