Skip to content

Instantly share code, notes, and snippets.

@evansd
Last active November 19, 2024 11:37
Show Gist options
  • Save evansd/1e475349c7061d1403404aec5ff5551e to your computer and use it in GitHub Desktop.
Save evansd/1e475349c7061d1403404aec5ff5551e to your computer and use it in GitHub Desktop.
Select actions on the job-server "run jobs" page according to their pattern and status

Press F12 to get the developer console and paste the below script in.

You can select and deselect actions which match a particular pattern, and according to whether they've previously succeeded or not.

For example, select all actions starting analyse_ excluding ones which have already run successfully:

selectActions("analyse_").ignoreSuccceeded().check()

To deselect all actions except failed ones:

selectActions("").ignoreFailed().uncheck()
class _Selection {
constructor(pattern, ignoreFailed, ignoreSucceeded) {
this._pattern = pattern;
this._ignoreFailed = ignoreFailed;
this._ignoreSucceeded = ignoreSucceeded;
}
ignoreFailed() {
return new _Selection(this._pattern, true, this._ignoreSucceeded);
}
ignoreSucceeded() {
return new _Selection(this._pattern, this._ignoreFailed, true);
}
check() {
this._setCheckboxes(true);
}
uncheck() {
this._setCheckboxes(false);
}
_setCheckboxes(checked) {
document.querySelectorAll(`[id^="checkbox-${this._pattern}"]`).forEach((checkbox) => {
const hasFailed = ! checkbox.closest('#jobActions')
.querySelector('[data-action-status="failed"]')
.classList.contains('hidden');
const hasSucceeded = ! checkbox.closest('#jobActions')
.querySelector('[data-action-status="succeeded"]')
.classList.contains('hidden');
if (hasFailed && this._ignoreFailed) return;
if (hasSucceeded && this._ignoreSucceeded) return;
checkbox.checked = checked;
});
}
}
function selectActions(pattern) { return new _Selection(pattern); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment