Last active
February 17, 2020 15:32
-
-
Save dkarlinsky/84b62daab8b66b775d3b310aa7241152 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 GCB Invocation Log Link | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Adds Invocations view link to GCB build results. Fixes log download link. | |
// @author Dmitry Karlinsky | |
// @match https://source.cloud.google.com/results/builds/gcb-with-custom-workers* | |
// @grant none | |
// ==/UserScript== | |
function newElement(name, attributes = {}) { | |
const el = document.createElement(name); | |
for (let field of Object.entries(attributes)) { | |
if (field[0].startsWith('@')) { | |
el.setAttribute(field[0].slice(1), field[1]); | |
} else { | |
el[field[0]] = field[1]; | |
} | |
} | |
return el; | |
} | |
function invocationUrl() { | |
const buildId = document.URL.match("\\/([a-z0-9\-]{36})\\/")[1] | |
if(!buildId) { | |
console.log("build id not found in URL", document.URL); | |
} | |
return `https://source.cloud.google.com/results/builds/gcb-with-custom-workers/${buildId}/steps/8/invocations/${buildId}`; | |
} | |
function fixDownloadLink() { | |
const logHeaderInfo = document.querySelector(".log-header-info"); | |
if(logHeaderInfo) { | |
logHeaderInfo.style.zIndex = 100; | |
} else { | |
setTimeout(fixDownloadLink, 1000); | |
} | |
} | |
function addInvocationLink() { | |
const targetElement = document.querySelector(".build-status"); | |
const elementId = "invocation_link_added"; | |
const url = invocationUrl(); | |
console.log("targetElement", targetElement, "url", url); | |
if(url && targetElement && !document.getElementById(elementId)) { | |
console.log("appending link to", targetElement); | |
targetElement.appendChild(newElement("div",{ | |
id: elementId, | |
"@class": "info-desc", | |
innerHTML: `<a target="_blank" href ="${url}">Invocation Log</a>` | |
})); | |
} else { | |
setTimeout(addInvocationLink, 1000); | |
} | |
} | |
(function() { | |
'use strict'; | |
setTimeout(addInvocationLink, 1000); | |
setTimeout(fixDownloadLink, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment