Copy a job's whole log from the run page tail and the job log page
Browse files at this commit6216322537370a024df19476643de0bea2639c48Parent: 767f2d0- feat
- copy a job's whole log from the run page tail and the job log page
5 changed files +96 -7
- crates/forge-web/assets/nav.js +40 -0
- crates/forge-web/src/i18n/releases_ci.rs +16 -0
- crates/forge-web/src/pages/ci_job.rs +32 -5
- crates/forge-web/src/pages/ci_runs.rs +4 -2
- style/main.scss +4 -0
crates/forge-web/assets/nav.jsmodified+40 -0
| @@ -1354,6 +1354,46 @@ | |||
| 1354 | } | 1354 | } |
| 1355 | }, false); | 1355 | }, false); |
| 1356 | 1356 | ||
| 1357 | + // "Copy log": fetches the job's log.txt once and puts the whole text on the clipboard. The button is | ||
| 1358 | + // disabled meanwhile, so a big log is not fetched twice; its label shows the outcome, then returns. | ||
| 1359 | + function copyText(text) { | ||
| 1360 | + if (navigator.clipboard && navigator.clipboard.writeText) { | ||
| 1361 | + return navigator.clipboard.writeText(text); | ||
| 1362 | + } | ||
| 1363 | + return new Promise(function (resolve, reject) { | ||
| 1364 | + var ta = document.createElement('textarea'); | ||
| 1365 | + ta.value = text; | ||
| 1366 | + ta.setAttribute('readonly', ''); | ||
| 1367 | + ta.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none'; | ||
| 1368 | + document.body.appendChild(ta); | ||
| 1369 | + ta.select(); | ||
| 1370 | + var ok = false; | ||
| 1371 | + try { ok = document.execCommand('copy'); } catch (err) { ok = false; } | ||
| 1372 | + document.body.removeChild(ta); | ||
| 1373 | + if (ok) { resolve(); } else { reject(new Error('copy')); } | ||
| 1374 | + }); | ||
| 1375 | + } | ||
| 1376 | + | ||
| 1377 | + function copyLog(btn) { | ||
| 1378 | + if (btn.disabled) { return; } | ||
| 1379 | + var label = btn.getAttribute('data-label') || btn.textContent; | ||
| 1380 | + btn.setAttribute('data-label', label); | ||
| 1381 | + btn.disabled = true; | ||
| 1382 | + var done = function (ok) { | ||
| 1383 | + btn.textContent = btn.getAttribute(ok ? 'data-copied' : 'data-failed') || label; | ||
| 1384 | + setTimeout(function () { btn.textContent = label; btn.disabled = false; }, 1500); | ||
| 1385 | + }; | ||
| 1386 | + fetch(btn.getAttribute('data-copy-log'), { credentials: 'include' }) | ||
| 1387 | + .then(function (r) { if (!r.ok) { throw new Error('fetch'); } return r.text(); }) | ||
| 1388 | + .then(function (text) { return copyText(text.replace(/\u001b\[[0-9;?]*[ -\/]*[@-~]/g, '')); }) | ||
| 1389 | + .then(function () { done(true); }, function () { done(false); }); | ||
| 1390 | + } | ||
| 1391 | + | ||
| 1392 | + document.addEventListener('click', function (e) { | ||
| 1393 | + var btn = e.target && e.target.closest ? e.target.closest('[data-copy-log]') : null; | ||
| 1394 | + if (btn) { e.preventDefault(); copyLog(btn); } | ||
| 1395 | + }, false); | ||
| 1396 | + | ||
| 1357 | document.addEventListener('input', function (e) { | 1397 | document.addEventListener('input', function (e) { |
| 1358 | var input = e.target && e.target.closest ? e.target.closest('[data-finder-input]') : null; | 1398 | var input = e.target && e.target.closest ? e.target.closest('[data-finder-input]') : null; |
| 1359 | if (input) { renderFinder(input.closest('dialog')); } | 1399 | if (input) { renderFinder(input.closest('dialog')); } |
crates/forge-web/src/i18n/releases_ci.rsmodified+16 -0
| @@ -58,6 +58,10 @@ pub enum K { | |||
| 58 | Exit, | 58 | Exit, |
| 59 | Log, | 59 | Log, |
| 60 | FullLog, | 60 | FullLog, |
| 61 | + CopyLog, | ||
| 62 | + CopyDone, | ||
| 63 | + CopyFailed, | ||
| 64 | + Duration, | ||
| 61 | LogTruncated, | 65 | LogTruncated, |
| 62 | Artifacts, | 66 | Artifacts, |
| 63 | Timeline, | 67 | Timeline, |
| @@ -259,6 +263,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 259 | (Log, Tr) => "Günlük", | 263 | (Log, Tr) => "Günlük", |
| 260 | (FullLog, En) => "Full log (log.txt)", | 264 | (FullLog, En) => "Full log (log.txt)", |
| 261 | (FullLog, Tr) => "Tam günlük (log.txt)", | 265 | (FullLog, Tr) => "Tam günlük (log.txt)", |
| 266 | + (CopyLog, En) => "Copy log", | ||
| 267 | + (CopyLog, Tr) => "Günlüğü kopyala", | ||
| 268 | + (CopyDone, En) => "Copied", | ||
| 269 | + (CopyDone, Tr) => "Kopyalandı", | ||
| 270 | + (CopyFailed, En) => "Copy failed", | ||
| 271 | + (CopyFailed, Tr) => "Kopyalanamadı", | ||
| 272 | + (Duration, En) => "Duration", | ||
| 273 | + (Duration, Tr) => "Süre", | ||
| 262 | (LogTruncated, En) => "Showing the last 512 KiB of the log. The full log is linked above.", | 274 | (LogTruncated, En) => "Showing the last 512 KiB of the log. The full log is linked above.", |
| 263 | (LogTruncated, Tr) => { | 275 | (LogTruncated, Tr) => { |
| 264 | "Günlüğün son 512 KiB'ı gösteriliyor. Tam günlük yukarıda bağlantılı." | 276 | "Günlüğün son 512 KiB'ı gösteriliyor. Tam günlük yukarıda bağlantılı." |
| @@ -584,6 +596,10 @@ mod tests { | |||
| 584 | K::Exit, | 596 | K::Exit, |
| 585 | K::Log, | 597 | K::Log, |
| 586 | K::FullLog, | 598 | K::FullLog, |
| 599 | + K::CopyLog, | ||
| 600 | + K::CopyDone, | ||
| 601 | + K::CopyFailed, | ||
| 602 | + K::Duration, | ||
| 587 | K::LogTruncated, | 603 | K::LogTruncated, |
| 588 | K::Artifacts, | 604 | K::Artifacts, |
| 589 | K::Timeline, | 605 | K::Timeline, |
crates/forge-web/src/pages/ci_job.rsmodified+32 -5
| @@ -34,7 +34,8 @@ use crate::i18n::{ | |||
| 34 | releases_ci::{self as g, K}, | 34 | releases_ci::{self as g, K}, |
| 35 | }; | 35 | }; |
| 36 | use crate::pages::ci_runs::{ | 36 | use crate::pages::ci_runs::{ |
| 37 | - can_write, changed_event, events_response, job_href, job_status, run_href, state_text, | 37 | + age_text, can_write, changed_event, duration_text, events_response, job_href, job_status, |
| 38 | + run_href, state_text, | ||
| 38 | }; | 39 | }; |
| 39 | use crate::pages::repo::repo_head; | 40 | use crate::pages::repo::repo_head; |
| 40 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | 41 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| @@ -242,6 +243,14 @@ fn attachment_name(name: &str) -> String { | |||
| 242 | .collect() | 243 | .collect() |
| 243 | } | 244 | } |
| 244 | 245 | ||
| 246 | +/// "2026-10-20 15:31:56 UTC" for a stored RFC3339 stamp; anything shorter is shown as it is. | ||
| 247 | +fn full_date(stamp: &str) -> String { | ||
| 248 | + match stamp.get(..19) { | ||
| 249 | + Some(head) => format!("{} UTC", head.replace('T', " ")), | ||
| 250 | + None => stamp.to_owned(), | ||
| 251 | + } | ||
| 252 | +} | ||
| 253 | + | ||
| 245 | /// The job page's values, already shown as text. | 254 | /// The job page's values, already shown as text. |
| 246 | struct JobView { | 255 | struct JobView { |
| 247 | name: String, | 256 | name: String, |
| @@ -253,7 +262,10 @@ struct JobView { | |||
| 253 | exit_code: String, | 262 | exit_code: String, |
| 254 | message: String, | 263 | message: String, |
| 255 | started: String, | 264 | started: String, |
| 265 | + started_full: String, | ||
| 256 | finished: String, | 266 | finished: String, |
| 267 | + finished_full: String, | ||
| 268 | + duration: String, | ||
| 257 | run_href: String, | 269 | run_href: String, |
| 258 | run_number: i64, | 270 | run_number: i64, |
| 259 | log_href: String, | 271 | log_href: String, |
| @@ -298,10 +310,13 @@ async fn job_body( | |||
| 298 | } | 310 | } |
| 299 | </p> | 311 | </p> |
| 300 | if !job.started.is_empty() { | 312 | if !job.started.is_empty() { |
| 301 | - <p class="muted small">(g::t(lang, K::Started)) " " (job.started.as_str())</p> | 313 | + <p class="muted small">(g::t(lang, K::Started)) " " <time datetime=(job.started_full.as_str()) title=(full_date(job.started_full.as_str()))>(job.started.as_str())</time></p> |
| 302 | } | 314 | } |
| 303 | if !job.finished.is_empty() { | 315 | if !job.finished.is_empty() { |
| 304 | - <p class="muted small">(g::t(lang, K::Finished)) " " (job.finished.as_str())</p> | 316 | + <p class="muted small">(g::t(lang, K::Finished)) " " <time datetime=(job.finished_full.as_str()) title=(full_date(job.finished_full.as_str()))>(job.finished.as_str())</time></p> |
| 317 | + } | ||
| 318 | + if !job.duration.is_empty() { | ||
| 319 | + <p class="muted small">(g::t(lang, K::Duration)) " " (job.duration.as_str())</p> | ||
| 305 | } | 320 | } |
| 306 | if !job.message.is_empty() { | 321 | if !job.message.is_empty() { |
| 307 | <p>(job.message.as_str())</p> | 322 | <p>(job.message.as_str())</p> |
| @@ -326,6 +341,7 @@ async fn job_body( | |||
| 326 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> | 341 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> |
| 327 | <button type="button" class="ci-mini" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> | 342 | <button type="button" class="ci-mini" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> |
| 328 | <button type="button" class="ci-mini" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> | 343 | <button type="button" class="ci-mini" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> |
| 344 | + <button type="button" class="ci-mini" data-copy-log=(job.log_href.as_str()) data-copied=(g::t(lang, K::CopyDone)) data-failed=(g::t(lang, K::CopyFailed))>(g::t(lang, K::CopyLog))</button> | ||
| 329 | <span class="ci-logfold" data-log-fold-box="true" hidden="hidden"> | 345 | <span class="ci-logfold" data-log-fold-box="true" hidden="hidden"> |
| 330 | <button type="button" class="ci-mini" data-log-fold="close">(g::t(lang, K::LogCollapseAll))</button> | 346 | <button type="button" class="ci-mini" data-log-fold="close">(g::t(lang, K::LogCollapseAll))</button> |
| 331 | <button type="button" class="ci-mini" data-log-fold="open">(g::t(lang, K::LogExpandAll))</button> | 347 | <button type="button" class="ci-mini" data-log-fold="open">(g::t(lang, K::LogExpandAll))</button> |
| @@ -402,8 +418,19 @@ async fn job_page(cx: &Cx) -> Result<impl View> { | |||
| 402 | .map(|code| code.to_string()) | 418 | .map(|code| code.to_string()) |
| 403 | .unwrap_or_default(), | 419 | .unwrap_or_default(), |
| 404 | message: job.message.clone().unwrap_or_default(), | 420 | message: job.message.clone().unwrap_or_default(), |
| 405 | - started: job.started_at.clone().unwrap_or_default(), | 421 | + started: job |
| 406 | - finished: job.finished_at.clone().unwrap_or_default(), | 422 | + .started_at |
| 423 | + .as_deref() | ||
| 424 | + .map(|stamp| age_text(lang, stamp)) | ||
| 425 | + .unwrap_or_default(), | ||
| 426 | + started_full: job.started_at.clone().unwrap_or_default(), | ||
| 427 | + finished: job | ||
| 428 | + .finished_at | ||
| 429 | + .as_deref() | ||
| 430 | + .map(|stamp| age_text(lang, stamp)) | ||
| 431 | + .unwrap_or_default(), | ||
| 432 | + finished_full: job.finished_at.clone().unwrap_or_default(), | ||
| 433 | + duration: duration_text(lang, job.started_at.as_deref(), job.finished_at.as_deref()), | ||
| 407 | run_href: run_href(&title, run.number), | 434 | run_href: run_href(&title, run.number), |
| 408 | run_number: run.number, | 435 | run_number: run.number, |
| 409 | log_href: format!("{}/log.txt", job_href(&title, &job.id)), | 436 | log_href: format!("{}/log.txt", job_href(&title, &job.id)), |
crates/forge-web/src/pages/ci_runs.rsmodified+4 -2
| @@ -179,7 +179,7 @@ fn unix_of(stamp: &str) -> Option<i64> { | |||
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | /// "3 minutes ago" for a stamp. An unreadable stamp is shown as it is stored. | 181 | /// "3 minutes ago" for a stamp. An unreadable stamp is shown as it is stored. |
| 182 | -fn age_text(lang: Lang, stamp: &str) -> String { | 182 | +pub(crate) fn age_text(lang: Lang, stamp: &str) -> String { |
| 183 | match unix_of(stamp) { | 183 | match unix_of(stamp) { |
| 184 | Some(unix) => relative_time(lang, unix, now_unix()), | 184 | Some(unix) => relative_time(lang, unix, now_unix()), |
| 185 | None => stamp.to_owned(), | 185 | None => stamp.to_owned(), |
| @@ -187,7 +187,7 @@ fn age_text(lang: Lang, stamp: &str) -> String { | |||
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | /// "1m 5s", or "" when the job never started. A running job counts up to now. | 189 | /// "1m 5s", or "" when the job never started. A running job counts up to now. |
| 190 | -fn duration_text(lang: Lang, started: Option<&str>, finished: Option<&str>) -> String { | 190 | +pub(crate) fn duration_text(lang: Lang, started: Option<&str>, finished: Option<&str>) -> String { |
| 191 | let Some(start) = started.and_then(unix_of) else { | 191 | let Some(start) = started.and_then(unix_of) else { |
| 192 | return String::new(); | 192 | return String::new(); |
| 193 | }; | 193 | }; |
| @@ -1804,6 +1804,8 @@ async fn runs_body( | |||
| 1804 | <div class="ci-job-tail" data-job-tail="true" hidden=(if job.expanded { None } else { Some("hidden") })> | 1804 | <div class="ci-job-tail" data-job-tail="true" hidden=(if job.expanded { None } else { Some("hidden") })> |
| 1805 | <pre class="ci-logpre">(job.tail.as_str())</pre> | 1805 | <pre class="ci-logpre">(job.tail.as_str())</pre> |
| 1806 | <a class="ci-job-full" href=(job.href.as_str())>(g::t(lang, K::FullLog))</a> | 1806 | <a class="ci-job-full" href=(job.href.as_str())>(g::t(lang, K::FullLog))</a> |
| 1807 | + " " | ||
| 1808 | + <button type="button" class="ci-mini ci-job-copy" data-copy-log=(format!("{}/log.txt", job.href)) data-copied=(g::t(lang, K::CopyDone)) data-failed=(g::t(lang, K::CopyFailed))>(g::t(lang, K::CopyLog))</button> | ||
| 1807 | </div> | 1809 | </div> |
| 1808 | } else if !job.preview.is_empty() { | 1810 | } else if !job.preview.is_empty() { |
| 1809 | <p class="ci-job-last" title=(job.preview.as_str())> | 1811 | <p class="ci-job-last" title=(job.preview.as_str())> |
style/main.scssmodified+4 -0
| @@ -5064,6 +5064,10 @@ button.ci-job-last { | |||
| 5064 | } | 5064 | } |
| 5065 | } | 5065 | } |
| 5066 | 5066 | ||
| 5067 | +.ci-job-copy { | ||
| 5068 | + margin: 6px 0 0 8px; | ||
| 5069 | +} | ||
| 5070 | + | ||
| 5067 | .ci-job-full { | 5071 | .ci-job-full { |
| 5068 | display: inline-block; | 5072 | display: inline-block; |
| 5069 | margin-top: 6px; | 5073 | margin-top: 6px; |