From a0ffce4d6a8c0f3c165a1f5d82dd6c251a19c5c7 Mon Sep 17 00:00:00 2001 From: blankie Date: Wed, 12 Oct 2022 16:14:04 +0700 Subject: [PATCH] Update nightly.link buttons to version 1.2.1 - Fix viewing job logs --- nightly.link buttons.user.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/nightly.link buttons.user.js b/nightly.link buttons.user.js index 3997b36..858e3de 100644 --- a/nightly.link buttons.user.js +++ b/nightly.link buttons.user.js @@ -3,7 +3,7 @@ // @namespace blankie-scripts // @match http*://github.com/* // @grant none -// @version 1.2 +// @version 1.2.1 // @author blankie // @run-at document-end // @description Show buttons to nightly.link on artifacts and build logs @@ -57,18 +57,35 @@ function addArtifactsButtonAndLinks(artifactsDiv) { return true; } +// https://github.com/EbookFoundation/free-programming-books/actions/runs/3213752190/jobs/5253657996 +// https://github.com/kotatogram/kotatogram-desktop/actions/runs/3231502508/jobs/5291098845 +function getGithubJobsPath(logsHeader) { + let timestampElement = logsHeader.querySelector(".CheckRun-header-timestamp"); + if (timestampElement === null) { + return location.pathname; + } + let headerUrl = timestampElement.getAttribute("data-url"); + if (headerUrl === null) { + return location.pathname; + } + let jobLogsUrl = new URL(headerUrl, location); + return jobLogsUrl.pathname.replace(/\/header\/*$/, ""); +} + function addLogsButton(githubLogsButton, logsHeader) { + let logsUrl = INSTANCE_URL + getGithubJobsPath(logsHeader) + ".txt"; + if (githubLogsButton !== null) { let nightlyLogsButton = document.createElement("a"); nightlyLogsButton.className = "pl-5 dropdown-item btn-link"; nightlyLogsButton.innerText = "View logs on nightly.link"; - nightlyLogsButton.href = INSTANCE_URL + location.pathname + ".txt"; + nightlyLogsButton.href = logsUrl; githubLogsButton.parentNode.append(nightlyLogsButton); return true; } else if (logsHeader !== null) { let logsLink = document.createElement("a"); logsLink.innerText = "View on nightly.link"; - logsLink.href = INSTANCE_URL + location.pathname + ".txt"; + logsLink.href = logsUrl; logsHeader.append(logsLink); return true; }