From 6216322537370a024df19476643de0bea2639c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 20 Oct 2026 22:15:03 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20copy=20a=20job's=20whole=20?= =?UTF-8?q?log=20from=20the=20run=20page=20tail=20and=20the=20job=20log=20?= =?UTF-8?q?page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/assets/nav.js | 40 ++++++++++++++++++++++++ crates/forge-web/src/i18n/releases_ci.rs | 16 ++++++++++ crates/forge-web/src/pages/ci_job.rs | 37 +++++++++++++++++++--- crates/forge-web/src/pages/ci_runs.rs | 6 ++-- style/main.scss | 4 +++ 5 files changed, 96 insertions(+), 7 deletions(-) diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index a1a021c..0292be4 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -1354,6 +1354,46 @@ } }, false); + // "Copy log": fetches the job's log.txt once and puts the whole text on the clipboard. The button is + // disabled meanwhile, so a big log is not fetched twice; its label shows the outcome, then returns. + function copyText(text) { + if (navigator.clipboard && navigator.clipboard.writeText) { + return navigator.clipboard.writeText(text); + } + return new Promise(function (resolve, reject) { + var ta = document.createElement('textarea'); + ta.value = text; + ta.setAttribute('readonly', ''); + ta.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none'; + document.body.appendChild(ta); + ta.select(); + var ok = false; + try { ok = document.execCommand('copy'); } catch (err) { ok = false; } + document.body.removeChild(ta); + if (ok) { resolve(); } else { reject(new Error('copy')); } + }); + } + + function copyLog(btn) { + if (btn.disabled) { return; } + var label = btn.getAttribute('data-label') || btn.textContent; + btn.setAttribute('data-label', label); + btn.disabled = true; + var done = function (ok) { + btn.textContent = btn.getAttribute(ok ? 'data-copied' : 'data-failed') || label; + setTimeout(function () { btn.textContent = label; btn.disabled = false; }, 1500); + }; + fetch(btn.getAttribute('data-copy-log'), { credentials: 'include' }) + .then(function (r) { if (!r.ok) { throw new Error('fetch'); } return r.text(); }) + .then(function (text) { return copyText(text.replace(/\u001b\[[0-9;?]*[ -\/]*[@-~]/g, '')); }) + .then(function () { done(true); }, function () { done(false); }); + } + + document.addEventListener('click', function (e) { + var btn = e.target && e.target.closest ? e.target.closest('[data-copy-log]') : null; + if (btn) { e.preventDefault(); copyLog(btn); } + }, false); + document.addEventListener('input', function (e) { var input = e.target && e.target.closest ? e.target.closest('[data-finder-input]') : null; if (input) { renderFinder(input.closest('dialog')); } diff --git a/crates/forge-web/src/i18n/releases_ci.rs b/crates/forge-web/src/i18n/releases_ci.rs index 079066f..8eb17e9 100644 --- a/crates/forge-web/src/i18n/releases_ci.rs +++ b/crates/forge-web/src/i18n/releases_ci.rs @@ -58,6 +58,10 @@ pub enum K { Exit, Log, FullLog, + CopyLog, + CopyDone, + CopyFailed, + Duration, LogTruncated, Artifacts, Timeline, @@ -259,6 +263,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { (Log, Tr) => "Günlük", (FullLog, En) => "Full log (log.txt)", (FullLog, Tr) => "Tam günlük (log.txt)", + (CopyLog, En) => "Copy log", + (CopyLog, Tr) => "Günlüğü kopyala", + (CopyDone, En) => "Copied", + (CopyDone, Tr) => "Kopyalandı", + (CopyFailed, En) => "Copy failed", + (CopyFailed, Tr) => "Kopyalanamadı", + (Duration, En) => "Duration", + (Duration, Tr) => "Süre", (LogTruncated, En) => "Showing the last 512 KiB of the log. The full log is linked above.", (LogTruncated, Tr) => { "Günlüğün son 512 KiB'ı gösteriliyor. Tam günlük yukarıda bağlantılı." @@ -584,6 +596,10 @@ mod tests { K::Exit, K::Log, K::FullLog, + K::CopyLog, + K::CopyDone, + K::CopyFailed, + K::Duration, K::LogTruncated, K::Artifacts, K::Timeline, diff --git a/crates/forge-web/src/pages/ci_job.rs b/crates/forge-web/src/pages/ci_job.rs index c2f5bde..7172f70 100644 --- a/crates/forge-web/src/pages/ci_job.rs +++ b/crates/forge-web/src/pages/ci_job.rs @@ -34,7 +34,8 @@ use crate::i18n::{ releases_ci::{self as g, K}, }; use crate::pages::ci_runs::{ - can_write, changed_event, events_response, job_href, job_status, run_href, state_text, + age_text, can_write, changed_event, duration_text, events_response, job_href, job_status, + run_href, state_text, }; use crate::pages::repo::repo_head; use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; @@ -242,6 +243,14 @@ fn attachment_name(name: &str) -> String { .collect() } +/// "2026-10-20 15:31:56 UTC" for a stored RFC3339 stamp; anything shorter is shown as it is. +fn full_date(stamp: &str) -> String { + match stamp.get(..19) { + Some(head) => format!("{} UTC", head.replace('T', " ")), + None => stamp.to_owned(), + } +} + /// The job page's values, already shown as text. struct JobView { name: String, @@ -253,7 +262,10 @@ struct JobView { exit_code: String, message: String, started: String, + started_full: String, finished: String, + finished_full: String, + duration: String, run_href: String, run_number: i64, log_href: String, @@ -298,10 +310,13 @@ async fn job_body( }

if !job.started.is_empty() { -

(g::t(lang, K::Started)) " " (job.started.as_str())

+

(g::t(lang, K::Started)) " "

} if !job.finished.is_empty() { -

(g::t(lang, K::Finished)) " " (job.finished.as_str())

+

(g::t(lang, K::Finished)) " "

+ } + if !job.duration.is_empty() { +

(g::t(lang, K::Duration)) " " (job.duration.as_str())

} if !job.message.is_empty() {

(job.message.as_str())

@@ -326,6 +341,7 @@ async fn job_body( +