(function () { document.querySelectorAll(".section-toggle").forEach(function (btn) { btn.addEventListener("click", function () { var sec = btn.parentElement; sec.classList.toggle("open"); }); }); var log = document.querySelector("[data-log]"); var hits = []; var hitAt = -1; function clearHits() { if (!log) { return; } log.querySelectorAll(".hit").forEach(function (el) { el.classList.remove("hit", "on"); }); hits = []; hitAt = -1; } function showHit(i) { if (!hits.length) { return; } hitAt = (i + hits.length) % hits.length; hits.forEach(function (el, n) { el.classList.toggle("on", n === hitAt); }); var current = hits[hitAt]; var sec = current.closest(".logsec"); if (sec) { sec.classList.add("open"); } current.scrollIntoView({ block: "center" }); } var search = document.querySelector("[data-log-search]"); if (search && log) { search.addEventListener("submit", function (ev) { ev.preventDefault(); var q = (search.querySelector("input").value || "").toLowerCase(); clearHits(); if (!q) { return; } log.querySelectorAll("[data-line]").forEach(function (row) { var code = row.querySelector("code"); var text = code ? code.textContent.toLowerCase() : ""; if (text.indexOf(q) >= 0) { row.classList.add("hit"); hits.push(row); } }); showHit(0); }); } var prev = document.querySelector("[data-log-prev]"); var next = document.querySelector("[data-log-next]"); if (prev) { prev.addEventListener("click", function () { showHit(hitAt - 1); }); } if (next) { next.addEventListener("click", function () { showHit(hitAt + 1); }); } var wrapBtn = document.querySelector("[data-log-wrap]"); if (wrapBtn && log) { wrapBtn.setAttribute("aria-pressed", log.classList.contains("nowrap") ? "false" : "true"); wrapBtn.addEventListener("click", function () { var off = log.classList.toggle("nowrap"); wrapBtn.setAttribute("aria-pressed", off ? "false" : "true"); }); } var topBtn = document.querySelector("[data-log-top]"); var bottomBtn = document.querySelector("[data-log-bottom]"); if (topBtn && log) { topBtn.addEventListener("click", function () { log.scrollTop = 0; }); } if (bottomBtn && log) { bottomBtn.addEventListener("click", function () { log.scrollTop = log.scrollHeight; }); } var fullBtn = document.querySelector("[data-log-full]"); var wrapBox = document.querySelector("[data-console]"); if (fullBtn && wrapBox) { fullBtn.addEventListener("click", function () { if (document.fullscreenElement) { document.exitFullscreen(); return; } if (wrapBox.requestFullscreen) { wrapBox.requestFullscreen().catch(function () { wrapBox.classList.toggle("full"); }); return; } wrapBox.classList.toggle("full"); }); } var stageSelect = document.querySelector("[data-stage-select]"); if (stageSelect) { stageSelect.addEventListener("change", function () { var want = stageSelect.value; document.querySelectorAll(".related li").forEach(function (li) { li.hidden = li.getAttribute("data-stage") !== want; }); }); } function rowElement(html) { var wrap = document.createElement("tbody"); wrap.innerHTML = (html || "").trim(); return wrap.querySelector("tr"); } function stagesFromHTML(html) { var row = rowElement(html); if (row) { return row.querySelector(".stages"); } var wrap = document.createElement("div"); wrap.innerHTML = (html || "").trim(); return wrap.querySelector(".stages"); } function findStage(root, name) { var buttons = root.querySelectorAll("button.stage-dot[data-stage]"); for (var i = 0; i < buttons.length; i++) { if (buttons[i].getAttribute("data-stage") === name) { return buttons[i]; } } return null; } function setQueue(root, text) { var q = root.querySelector("[data-queue]"); if (!text) { if (q) { q.remove(); } return; } if (!q) { q = document.createElement("span"); q.className = "queue"; q.setAttribute("data-queue", ""); var anchor = root.querySelector("a"); if (anchor && anchor.parentElement === root) { anchor.insertAdjacentElement("afterend", q); } else { (anchor || root).appendChild(q); } } q.textContent = text; } function patchPipeRow(live, row) { var status = live.querySelector("[data-pipe-status]"); if (status) { status.className = "status " + row.status; var label = status.querySelector("[data-pipe-label]"); if (label) { label.textContent = row.label || ""; } } var dur = live.querySelector("[data-pipe-duration]"); if (dur) { dur.textContent = row.duration || ""; } var when = live.querySelector("[data-pipe-when]"); if (when) { when.textContent = row.when || ""; } var stages = live.querySelector(".stages"); if (!stages) { return; } var buttons = stages.querySelectorAll(":scope > .stage > button.stage-dot[data-stage]"); var next = row.stages || []; var same = buttons.length === next.length; for (var i = 0; same && i < buttons.length; i++) { if (buttons[i].getAttribute("data-stage") !== next[i].name) { same = false; } } if (!same) { var freshStages = stagesFromHTML(row.html); if (!freshStages) { return; } var openName = ""; var openPop = live.querySelector(".stage-pop:popover-open"); if (openPop) { var openBtn = openPop.parentElement.querySelector("button.stage-dot"); openName = openBtn ? openBtn.getAttribute("data-stage") : ""; } stages.innerHTML = freshStages.innerHTML; if (openName) { var again = findStage(live, openName); if (again) { again.click(); } } return; } next.forEach(function (st) { var btn = findStage(live, st.name); if (!btn) { return; } btn.className = "stage-dot " + st.status; btn.setAttribute("data-tip", st.tip || ""); btn.setAttribute("aria-label", st.tip || ""); var pop = btn.parentElement.querySelector(".stage-pop"); if (!pop) { return; } (st.jobs || []).forEach(function (job) { var li = pop.querySelector('[data-job="' + job.id + '"]'); if (!li) { return; } var dot = li.querySelector(".stage-dot"); if (dot) { dot.className = "stage-dot sm " + job.status; } setQueue(li, job.queue); }); }); } function applyPipeRows(rows, scrollX, scrollY, box, left) { var body = document.querySelector("table.pipes tbody"); if (!body) { return; } var ids = {}; rows.forEach(function (row) { ids[String(row.id)] = true; }); body.querySelectorAll("tr[data-pipe]").forEach(function (tr) { if (ids[tr.getAttribute("data-pipe")]) { return; } var rect = tr.getBoundingClientRect(); var h = tr.offsetHeight; tr.remove(); if (rect.bottom <= 0) { scrollY -= h; } }); rows.forEach(function (row, index) { var live = body.querySelector('tr[data-pipe="' + row.id + '"]'); if (!live) { var fresh = rowElement(row.html); if (!fresh) { return; } var existing = body.querySelectorAll("tr[data-pipe]"); var before = existing[index] || null; if (before) { body.insertBefore(fresh, before); } else { body.appendChild(fresh); } if (scrollY > 0) { scrollY += fresh.offsetHeight; } return; } patchPipeRow(live, row); var existing = body.querySelectorAll("tr[data-pipe]"); if (existing[index] && existing[index] !== live) { body.insertBefore(live, existing[index]); } }); window.scrollTo(scrollX, scrollY); if (box) { box.scrollLeft = left; } } function applyDetail(data) { var pill = document.querySelector("[data-pipe-status]"); if (pill && data.status) { pill.className = "status " + data.status; var label = pill.querySelector("[data-pipe-label]"); if (label) { label.textContent = data.label || ""; } } (data.jobs || []).forEach(function (job) { var li = document.querySelector('.clean li[data-job="' + job.id + '"]'); if (!li) { return; } var st = li.querySelector("[data-job-status]"); if (st) { st.className = "status " + job.status; var lab = st.querySelector("[data-job-label]"); if (lab) { lab.textContent = job.label || ""; } } setQueue(li, job.queue); }); var head = document.querySelector("[data-head-pipe]"); if (head) { patchPipeRow(head, data); } } var liveEl = document.querySelector("[data-live-on]"); if (liveEl) { var liveURL = liveEl.getAttribute("data-live"); var liveTimer = function () { if (document.hidden) { setTimeout(liveTimer, 3000); return; } var box = document.querySelector(".hscroll"); var scrollX = window.scrollX; var scrollY = window.scrollY; var left = box ? box.scrollLeft : 0; fetch(liveURL, { headers: { Accept: "application/json" }, credentials: "same-origin", cache: "no-store" }) .then(function (res) { if (!res.ok) { throw new Error("live"); } return res.json(); }) .then(function (data) { if (data.rows) { applyPipeRows(data.rows, scrollX, scrollY, box, left); } else { applyDetail(data); window.scrollTo(scrollX, scrollY); if (box) { box.scrollLeft = left; } } window.dispatchEvent(new Event("resize")); if (data.active) { setTimeout(liveTimer, 3000); } }) .catch(function () { setTimeout(liveTimer, 3000); }); }; setTimeout(liveTimer, 3000); } if (!wrapBox || wrapBox.getAttribute("data-running") !== "1" || !log) { return; } var offset = parseInt(wrapBox.getAttribute("data-offset") || "0", 10); var url = wrapBox.getAttribute("data-log-url"); var pending = ""; var lineNo = 0; log.querySelectorAll("[data-line]").forEach(function (row) { var n = parseInt(row.getAttribute("data-line") || "0", 10); if (n > lineNo) { lineNo = n; } }); var currentSec = log.querySelector(".logsec.open:last-of-type"); var ansiNames = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]; var follow = true; log.scrollTop = log.scrollHeight; log.addEventListener("scroll", function () { follow = log.scrollHeight - log.scrollTop - log.clientHeight < 48; }); function ansiClass(state) { var parts = []; if (state.bold) { parts.push("ansi-bold"); } if (state.dim) { parts.push("ansi-dim"); } if (state.italic) { parts.push("ansi-italic"); } if (state.underline) { parts.push("ansi-underline"); } if (state.fg) { parts.push("ansi-fg-" + state.fg); } if (state.bg) { parts.push("ansi-bg-" + state.bg); } return parts.join(" "); } function paint(code, text) { var state = {}; var buf = ""; function flush() { if (!buf) { return; } var cls = ansiClass(state); if (!cls) { code.appendChild(document.createTextNode(buf)); } else { var span = document.createElement("span"); span.className = cls; span.textContent = buf; code.appendChild(span); } buf = ""; } for (var i = 0; i < text.length; i++) { if (text.charCodeAt(i) !== 27 || i + 1 >= text.length) { buf += text.charAt(i); continue; } if (text.charAt(i + 1) === "[") { var end = i + 2; while (end < text.length) { var c = text.charCodeAt(end); if (c >= 32 && c <= 63) { end++; continue; } break; } if (end < text.length && text.charCodeAt(end) >= 64 && text.charCodeAt(end) <= 126) { flush(); if (text.charAt(end) === "m") { applySGR(state, text.slice(i + 2, end)); } i = end; continue; } } buf += text.charAt(i); } flush(); } function applySGR(state, params) { if (!params) { state.bold = state.dim = state.italic = state.underline = false; state.fg = state.bg = ""; return; } var nums = params.split(";").map(function (p) { return parseInt(p, 10) || 0; }); for (var i = 0; i < nums.length; i++) { var n = nums[i]; if (n === 0) { state.bold = state.dim = state.italic = state.underline = false; state.fg = state.bg = ""; } else if (n === 1) { state.bold = true; state.dim = false; } else if (n === 2) { state.dim = true; } else if (n === 3) { state.italic = true; } else if (n === 4) { state.underline = true; } else if (n === 22) { state.bold = false; state.dim = false; } else if (n === 23) { state.italic = false; } else if (n === 24) { state.underline = false; } else if (n >= 30 && n <= 37) { state.fg = ansiNames[n - 30]; } else if (n === 39) { state.fg = ""; } else if (n >= 40 && n <= 47) { state.bg = ansiNames[n - 40]; } else if (n === 49) { state.bg = ""; } else if (n >= 90 && n <= 97) { state.fg = "bright-" + ansiNames[n - 90]; } else if (n >= 100 && n <= 107) { state.bg = "bright-" + ansiNames[n - 100]; } else if ((n === 38 || n === 48) && nums[i + 1] === 5 && i + 2 < nums.length) { var name = ""; if (nums[i + 2] >= 0 && nums[i + 2] <= 7) { name = ansiNames[nums[i + 2]]; } else if (nums[i + 2] >= 8 && nums[i + 2] <= 15) { name = "bright-" + ansiNames[nums[i + 2] - 8]; } if (name) { if (n === 38) { state.fg = name; } else { state.bg = name; } } i += 2; } else if ((n === 38 || n === 48) && nums[i + 1] === 2) { i += 4; } } } function addLine(ts, text) { lineNo += 1; var row = document.createElement("div"); row.className = "logline"; row.setAttribute("data-line", String(lineNo)); var ln = document.createElement("span"); ln.className = "ln"; ln.textContent = String(lineNo); var time = document.createElement("span"); time.className = "ts"; time.textContent = ts; var code = document.createElement("code"); paint(code, text); row.appendChild(ln); row.appendChild(time); row.appendChild(code); if (currentSec) { var list = currentSec.querySelector("ol"); var li = document.createElement("li"); li.className = "logline"; li.setAttribute("data-line", String(lineNo)); li.appendChild(ln); li.appendChild(time); li.appendChild(code); list.appendChild(li); row = li; } else { log.appendChild(row); } if (follow) { log.scrollTop = log.scrollHeight; } } function openSection(title) { var sec = document.createElement("section"); sec.className = "logsec open"; var btn = document.createElement("button"); btn.type = "button"; btn.className = "section-toggle"; var chev = document.createElement("span"); chev.className = "chev"; var label = document.createElement("span"); label.className = "sectitle"; label.textContent = title; btn.appendChild(chev); btn.appendChild(label); btn.addEventListener("click", function () { sec.classList.toggle("open"); }); var ol = document.createElement("ol"); sec.appendChild(btn); sec.appendChild(ol); log.appendChild(sec); currentSec = sec; } function closeSection(dur) { if (!currentSec) { return; } if (dur) { var pill = document.createElement("span"); pill.className = "pill"; pill.textContent = dur; currentSec.querySelector("button").appendChild(pill); } currentSec = null; } function take(line) { var tab = line.indexOf("\t"); var ts = ""; var text = line; if (tab >= 0) { ts = line.slice(0, tab); text = line.slice(tab + 1); } if (ts.length >= 19 && ts.indexOf("T") === 10) { ts = ts.slice(11, 19); } if (text.indexOf("section_start:") === 0) { var body = text.slice("section_start:".length); var colon = body.indexOf(":"); openSection(colon >= 0 ? body.slice(colon + 1) : body); return; } if (text.indexOf("section_end:") === 0) { var end = text.slice("section_end:".length); var dtab = end.indexOf("\t"); closeSection(dtab >= 0 ? end.slice(dtab + 1) : ""); return; } addLine(ts, text); } function poll() { fetch(url + "?offset=" + offset, { headers: { Accept: "application/json" } }) .then(function (res) { return res.json(); }) .then(function (data) { var chunk = pending + (data.text || ""); var rows = chunk.split("\n"); pending = rows.pop(); rows.forEach(function (row) { if (row) { take(row); } }); offset = data.offset || offset; var qEl = document.querySelector(".jobhead [data-queue]"); if (qEl) { qEl.textContent = data.queue || ""; qEl.hidden = !data.queue; } if (data.status === "running" || data.status === "queued") { setTimeout(poll, 1500); return; } if (pending) { take(pending); pending = ""; } window.location.reload(); }) .catch(function () { setTimeout(poll, 3000); }); } setTimeout(poll, 1500); })();