Last active
September 3, 2024 13:18
-
-
Save basilevs/522fdddb0011913b645e9f42a24e56f5 to your computer and use it in GitHub Desktop.
Add useful artifact links to RCPTT build page.
This file contains hidden or 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 RCPTT useful shortcuts | |
// @version 4 | |
// @match https://ci.eclipse.org/* | |
// @match https://ci.eclipse.org/rcptt/view/active/job/master/1723/ | |
// @grant none | |
// ==/UserScript== | |
function log() { | |
console.log(...arguments); | |
} | |
const buildPathPattern = new RegExp('/job/[^/]+/(?:\\d+|lastSuccessfulBuild|lastBuild|lastCompletedBuild)/'.replaceAll('/', '\\/'), 'd'); | |
function getBuildPath() { | |
const originalPath = location.pathname; | |
const match = buildPathPattern.exec(location.pathname); | |
if (match) { | |
return location.pathname.substring(0, match.indices[0][1]); | |
} | |
return null; | |
} | |
const tasks = document.evaluate('//div[@id="tasks"]', document, null, XPathResult.singleNode).iterateNext(); | |
function createTask(label, url) { | |
const element = document.createElement('a'); | |
tasks.appendChild(element); | |
element.outerHTML = `<a href="${url}" class="task-link ">${label}</a>`; | |
} | |
async function exists(url) { | |
const response = await fetch(url, { method: "HEAD" }); | |
console.log(`Got status for ${url}: ${response.status}`); | |
return response.status == 200; | |
} | |
async function rawCreateExistingTask(label, path) { | |
let url = artifactToAbsoluteUrl(path); | |
if (await exists(url)) { | |
createTask(label, url); | |
return; | |
} | |
url = workspaceToAbsoluteUrl(path); | |
if (await exists(url)) { | |
createTask(label, url); | |
return; | |
} | |
} | |
async function createExistingTask(label, path) { | |
rawCreateExistingTask(label, path); | |
rawCreateExistingTask('Mockup '+label, 'mockups/'+path); | |
} | |
const buildPath = getBuildPath(); | |
function artifactToAbsoluteUrl(artifactPath) { | |
return new URL(buildPath + 'artifact/' + artifactPath, location) | |
} | |
function workspaceToAbsoluteUrl(workspacePath) { | |
// https://ci.eclipse.org/rcptt/job/Pull_requests/job/fixJobHangup/lastBuild/execution/node/15/ws/rcpttTests/target/results/ | |
return new URL(buildPath + 'execution/node/15/ws/' + workspacePath, location) | |
} | |
if (buildPath && tasks) { | |
log(`This is a build URL: ${buildPath}`); | |
// https://ci.eclipse.org/rcptt/job/Pull_requests/job/master/34/artifact/rcpttTests/target/results/tests.html | |
createExistingTask('HTML Test report', 'rcpttTests/target/results/tests.html'); | |
// https://ci.eclipse.org/rcptt/view/active/job/Pull_requests/job/exceptiFix/4/artifact/rcpttTests/target/results/tests.report | |
createExistingTask('Binary Test report', 'rcpttTests/target/results/tests.report'); | |
// https://ci.eclipse.org/rcptt/job/Pull_requests/job/PR-57/4/artifact/repository/full/target/repository/ | |
createExistingTask('P2 repository', 'repository/full/target/repository/'); | |
// https://ci.eclipse.org/rcptt/view/active/job/master/1744/execution/node/15/ws/rcpttTests/target/results/aut-console-0_console.log | |
createExistingTask('AUT output', 'rcpttTests/target/results/aut-console-0_console.log'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment