Last active
February 18, 2020 10:22
-
-
Save vpodzime/7d69b83494fde9840f60427c0f4c7835 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 Jenkins console linker | |
// @namespace https://cfengine.com | |
// @version 0.1 | |
// @description Adds images with links to console output for jenkins jobs | |
// @author Vratislav Podzimek <v.podzimek@mykolab.com> | |
// @match https://ci.cfengine.com/job/*/* | |
// @match https://ci.cfengine.com/*/*/job/*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function add_image_links() { | |
// console.log("Trying to add image links to console outputs of Jenkins jobs"); | |
var i = 0; | |
var as_l = 0; | |
var as = []; | |
var d = null; | |
var ca = null; | |
var img = null; | |
var fc = null; | |
var parent = null; | |
var res = document.evaluate("//div[@id='matrix']//a[@class='model-link inside']", document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); | |
var a = res.iterateNext(); | |
while (a !== null) { | |
// console.log(a.text); | |
as.push(a); | |
a = res.iterateNext(); | |
} | |
//as.sortBy(function (item) { return item.text; }); | |
var matrix = document.getElementById("matrix"); | |
matrix.setAttribute("style", "display: grid; grid-template-columns: auto auto auto; grid-gap: 2px;"); | |
var children = Array.from(matrix.childNodes); | |
var n_children = children.length; | |
var config_header = null; | |
for (i = 0; i < n_children; i++) { | |
if ((children[i].tagName == null) || (children[i].tagName === "IMG")) { | |
matrix.removeChild(children[i]); | |
} | |
if (children[i].tagName == "H2") { | |
config_header = children[i]; | |
} | |
} | |
if (config_header !== null) { | |
if (document.getElementById("main-header") == null) { | |
config_header.setAttribute("id", "main-header"); | |
matrix.parentNode.insertBefore(config_header, matrix); | |
} else { | |
matrix.removeChild(config_header); | |
} | |
} | |
var skipped_header = document.getElementById("skipped-header"); | |
if (skipped_header == null) { | |
skipped_header = document.createElement("h2"); | |
skipped_header.setAttribute("id", "skipped-header"); | |
skipped_header.setAttribute("style", "padding-top: 5px;"); | |
skipped_header.innerText = "Skipped Configurations"; | |
matrix.parentNode.appendChild(skipped_header); | |
} | |
var skipped_matrix = document.getElementById("skipped-matrix"); | |
if (skipped_matrix == null) { | |
skipped_matrix = document.createElement("div"); | |
skipped_matrix.setAttribute("id", "skipped-matrix"); | |
skipped_matrix.setAttribute("style", matrix.getAttribute("style")); | |
matrix.parentNode.appendChild(skipped_matrix); | |
} | |
// console.log("Found these links to job results: " + as.toString()); | |
as_l = as.length; | |
for (i = 0; i < as_l; i++) { | |
a = as[i]; | |
if ((a.parentNode != null) && (a.parentNode.tagName === "DIV") && (a.parentNode.getAttribute("class") === "config")) { | |
continue; | |
} | |
d = document.createElement("div"); | |
d.setAttribute("class", "config"); | |
ca = document.createElement("a"); | |
img = document.createElement("img"); | |
if (/https:\/\/ci\.cfengine\.com\/job\/[^\/]*\/.+/.test(document.documentURI)) { | |
ca.href = a.href + "console"; | |
} else { | |
ca.href = a.href + "lastBuild/console"; | |
} | |
img.src = "https://ci.cfengine.com/static/575d1924/images/24x24/terminal.png"; | |
ca.appendChild(img); | |
d.appendChild(ca); | |
d.appendChild(a); | |
if (a.innerHTML.includes("skipped")) { | |
parent = skipped_matrix; | |
} else { | |
parent = matrix; | |
} | |
parent.appendChild(d); | |
} | |
} | |
add_image_links(); | |
setInterval(add_image_links, 500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment