diff --git a/changelog.d/fixed-merge-toast-repo.md b/changelog.d/fixed-merge-toast-repo.md new file mode 100644 index 0000000000..6298c92730 --- /dev/null +++ b/changelog.d/fixed-merge-toast-repo.md @@ -0,0 +1 @@ +- Show the tracker's existing repository chip on merge notifications, keeping same-number PRs in different repositories linked to their own merge and row. diff --git a/src/pkg/dashboard/stage_tracker_cues_test.go b/src/pkg/dashboard/stage_tracker_cues_test.go index d5c24f5d26..2f0d2f7b86 100644 --- a/src/pkg/dashboard/stage_tracker_cues_test.go +++ b/src/pkg/dashboard/stage_tracker_cues_test.go @@ -358,6 +358,14 @@ func stageTrackerCelebrateJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerDetachedOrigin"), jsFunc(t, html, "celebrateDetached"), jsFunc(t, html, "stageTrackerMergeBannerNumber"), + jsFunc(t, html, "stageTrackerMergeBannerRepo"), + jsConstLine(t, html, "STAGE_TRACKER_REPO_TINTS"), + jsFunc(t, html, "stageTrackerRepoTint"), + jsFunc(t, html, "stageTrackerRepoShort"), + jsFunc(t, html, "stageTrackerIsPrimary"), + jsFunc(t, html, "stageTrackerRepoChipHtml"), + jsFunc(t, html, "stageTrackerPrimaryRepo"), + "var _stageTrackerFilter = { repo: '' };", jsFunc(t, html, "stageTrackerMergeBannerText"), jsFunc(t, html, "toastCountdownBar"), jsFunc(t, html, "toastCountdownCancel"), diff --git a/src/pkg/dashboard/stage_tracker_merge_banner_countdown.test.js b/src/pkg/dashboard/stage_tracker_merge_banner_countdown.test.js index 6ae96f5a36..5658259db6 100644 --- a/src/pkg/dashboard/stage_tracker_merge_banner_countdown.test.js +++ b/src/pkg/dashboard/stage_tracker_merge_banner_countdown.test.js @@ -54,11 +54,11 @@ function makeDom() { const BANNER_MS = 30000; const src = [ - 'const window = {};', + 'const window = { _primaryRepo: "hivecommons/hive" };', + 'const _stageTrackerFilter = { repo: "" };', 'function esc(s) { return typeof s === "string" ? s.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """) : ""; }', 'const _stageTrackerMerged = { server: { recent: [] } };', 'const _stageTrackerPRTitle = {};', - 'function stageTrackerMergedIdent(repo, n) { return repo + "#" + n; }', 'function stageTrackerMergedByText() { return ""; }', 'function stageTrackerReducedMotion() { return true; }', 'function stageTrackerAfter(el, ev, ms, fn) { fn(); }', @@ -67,6 +67,13 @@ const src = [ pick(/function toastCountdownBar\(el, ms, onExpire\) \{[\s\S]*?\n \}\n/, 'toastCountdownBar'), pick(/function toastCountdownCancel\(el\) \{[\s\S]*?\n \}\n/, 'toastCountdownCancel'), pick(/function stageTrackerMergeBannerNumber\(b\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerNumber'), + pick(/function stageTrackerMergeBannerRepo\(b\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerRepo'), + pick(/const STAGE_TRACKER_REPO_TINTS = [^\n]*\n/, 'STAGE_TRACKER_REPO_TINTS'), + pick(/function stageTrackerRepoTint\(repo\) \{[\s\S]*?\n \}\n/, 'stageTrackerRepoTint'), + pick(/function stageTrackerRepoShort\(repo\) \{[\s\S]*?\n \}\n/, 'stageTrackerRepoShort'), + pick(/function stageTrackerIsPrimary\(repo, primary\) \{[\s\S]*?\n \}\n/, 'stageTrackerIsPrimary'), + pick(/function stageTrackerRepoChipHtml\(repo, ctx\) \{[\s\S]*?\n \}\n/, 'stageTrackerRepoChipHtml'), + pick(/function stageTrackerPrimaryRepo\(\) \{[^\n]*\n/, 'stageTrackerPrimaryRepo'), pick(/function stageTrackerMergeBannerText\(b, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerText'), pick(/function stageTrackerMergeBanner\(b\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBanner'), pick(/function stageTrackerMergeBannerDismiss\(el\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerDismiss'), @@ -75,7 +82,7 @@ const src = [ function load() { const dom = makeDom(); - const api = new Function('document', 'setTimeout', 'clearTimeout', src + '; return { banner: stageTrackerMergeBanner, dismiss: stageTrackerMergeBannerDismiss, hamBannerDismiss };')(dom.document, dom.setTimeout, dom.clearTimeout); + const api = new Function('document', 'setTimeout', 'clearTimeout', src + '; return { banner: stageTrackerMergeBanner, dismiss: stageTrackerMergeBannerDismiss, hamBannerDismiss, merged: _stageTrackerMerged, filter: _stageTrackerFilter, chip: stageTrackerRepoChipHtml };')(dom.document, dom.setTimeout, dom.clearTimeout); return Object.assign(dom, api); } @@ -127,3 +134,67 @@ test('manual × dismiss clears the pending timer and the bar', () => { assert.strictEqual(el._countdown, null); assert.ok(!el.children.some(c => c.className === 'toast-bar'), 'bar removed with the countdown'); }); + +test('merge banners reuse tracker chips and preserve repo-scoped actions for colliding PR numbers', () => { + const d = load(); + d.merged.server.recent = [ + { repo: 'other/hive', number: 528, title: 'other merge', url: 'https://github.com/other/hive/pull/528', lane: 'other lane' }, + { repo: 'hivecommons/hive', number: 528, title: 'actual merge', url: 'https://github.com/hivecommons/hive/pull/528', lane: 'actual lane' }, + { repo: 'acme/console', number: 528, title: 'console merge', url: 'https://github.com/acme/console/pull/528' }, + ]; + d.filter.repo = 'other/hive'; + for (const repo of ['hivecommons/hive', 'other/hive', 'acme/console']) { + const rowKey = repo + '/issue#42'; + const el = d.banner({ key: repo + '/pr#528', repo, number: 528, rowKey }); + const chip = d.chip(repo, { repoChips: { primary: 'hivecommons/hive', active: d.filter.repo } }); + assert.ok(el.innerHTML.includes(chip + ' #528 merged'), 'exact existing chip markup'); + assert.strictEqual(el.getAttribute('data-ham-row'), rowKey); + assert.ok(el.innerHTML.includes(`data-action="hamBannerShowRow" data-arg0="${rowKey}" data-stop="1">Show row`)); + assert.ok(el.innerHTML.includes(`href="https://github.com/${repo}/pull/528" target="_blank" rel="noopener">Open on GitHub`)); + assert.ok(el.innerHTML.includes('data-action="hamMergedOpen" data-stop="1">All merges')); + const expected = d.merged.server.recent.find(e => e.repo === repo); + assert.ok(el.innerHTML.includes(expected.title), 'metadata belongs to actual event repo'); + for (const other of d.merged.server.recent.filter(e => e.repo !== repo)) { + assert.ok(!el.innerHTML.includes(other.url), 'no other repo URL borrowed'); + assert.ok(!el.innerHTML.includes(other.title), 'no other repo title borrowed'); + } + } +}); + +test('banner identity comes from event fields, never the primary repo or current filter', () => { + const d = load(); + d.filter.repo = 'unrelated/selected'; + const events = [ + { repo: 'acme/console', number: 528 }, + { pr: { repo: 'acme/console', number: 528 } }, + { key: 'acme/console/pr#528' }, + { repo: 'console', key: 'acme/console/pr#528' }, + { url: 'https://github.com/acme/console/pull/528' }, + { pr: { url: 'https://github.com/acme/console/pull/528', number: 528 } }, + ]; + for (const event of events) { + const el = d.banner(event); + assert.ok(el.innerHTML.includes('data-action="hamRepoChip" data-arg0="acme/console"')); + assert.ok(el.innerHTML.includes('href="https://github.com/acme/console/pull/528"')); + assert.ok(!el.innerHTML.includes('hivecommons/hive')); + assert.ok(!el.innerHTML.includes('unrelated/selected')); + } + const unknown = d.banner({ number: 528 }); + assert.ok(!unknown.innerHTML.includes('ham-repo-chip'), 'no repository identity means no chip'); + assert.ok(!unknown.innerHTML.includes('Open on GitHub'), 'no guessed repository link'); + assert.ok(unknown.innerHTML.includes('All merges'), 'merged list remains available'); + const short = d.banner({ repo: 'console', number: 528 }); + assert.ok(short.innerHTML.includes('data-arg0="console"'), 'explicit short audit identity is retained'); + assert.ok(!short.innerHTML.includes('Open on GitHub'), 'short identity does not invent an owner'); +}); + +test('merge repo chips use the existing escaping and preview behavior', () => { + const d = load(); + const repo = 'acme/'; + const el = d.banner({ repo, number: 528, preview: true, rowKey: repo + '/pr#528' }); + assert.ok(el.innerHTML.includes(d.chip(repo, { repoChips: { primary: 'hivecommons/hive', active: '' } }))); + assert.ok(el.innerHTML.includes('data-arg0="acme/<console"&>"')); + assert.ok(!el.innerHTML.includes(' 0 ? k[1] : ''; } + // Event identity only: never borrow the currently selected/primary repo. + // Keep an explicit short audit repo when no canonical identity is carried. + function stageTrackerMergeBannerRepo(b) { + if (!b) return ''; + const repo = String(b.repo || (b.pr && b.pr.repo) || ''); + if (repo.indexOf('/') > 0) return repo; + const key = String(b.key || '').match(/^(.+)\/pr#\d+$/); + if (key) return key[1]; + const url = String(b.url || (b.pr && b.pr.url) || '').match(/^https:\/\/github\.com\/([^/]+\/[^/]+)\/pull\/\d+(?:[?#].*)?$/); + return url ? url[1] : repo; + } function stageTrackerMergeBannerText(b, nowMs) { const d = new Date(b.at || nowMs); const hm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`; @@ -970,9 +981,11 @@ if (!document.body) return null; let box = document.getElementById('merge-banners'); if (!box) { box = document.createElement('div'); box.id = 'merge-banners'; box.className = 'merge-banners'; box.setAttribute('aria-live', 'polite'); document.body.appendChild(box); } - const recent = ((_stageTrackerMerged.server && _stageTrackerMerged.server.recent) || []).find(e => stageTrackerMergedIdent(e.repo, e.number) === stageTrackerMergedIdent(b.repo, b.number)); - const info = Object.assign({ title: _stageTrackerPRTitle[b.key] || '', merged_by: '', lane: '', url: '' }, recent || {}, b); + const repo = stageTrackerMergeBannerRepo(b); + const recent = repo ? ((_stageTrackerMerged.server && _stageTrackerMerged.server.recent) || []).find(e => stageTrackerMergeBannerRepo(e).toLowerCase() === repo.toLowerCase() && stageTrackerMergeBannerNumber(e) === stageTrackerMergeBannerNumber(b)) : null; + const info = Object.assign({ title: _stageTrackerPRTitle[b.key] || '', merged_by: '', lane: '', url: '' }, recent || {}, b, { repo }); const num = stageTrackerMergeBannerNumber(info); + const repoChip = stageTrackerRepoChipHtml(repo, { repoChips: { primary: stageTrackerPrimaryRepo(), active: _stageTrackerFilter.repo } }); // A live merge the ledger has not listed yet still links: the key carries owner/name. if (!info.url && info.repo && info.repo.indexOf('/') > 0 && num && !info.preview) info.url = `https://github.com/${info.repo}/pull/${num}`; const t = stageTrackerMergeBannerText(info, Date.now()); @@ -980,7 +993,7 @@ el.className = 'merge-banner'; el.setAttribute('role', 'status'); if (b.rowKey) el.setAttribute('data-ham-row', b.rowKey); - el.innerHTML = `
${num ? `#${esc(num)} ` : ''}merged${info.preview ? ' (test)' : ''}
${esc(t.text)}
`; + el.innerHTML = `
${repoChip ? repoChip + ' ' : ''}${num ? `#${esc(num)} ` : ''}merged${info.preview ? ' (test)' : ''}
${esc(t.text)}
`; box.appendChild(el); while (box.children.length > STAGE_TRACKER_MERGE_BANNER_MAX) { toastCountdownCancel(box.children[0]); box.children[0].remove(); } toastCountdownBar(el, stageTrackerMergeBannerMs(), () => stageTrackerMergeBannerDismiss(el)); diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 37431e3ffb..468778b83d 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -24083,6 +24083,17 @@

All labels

const k = String(b.key || '').match(/\/pr#(\d+)$/); return k && Number(k[1]) > 0 ? k[1] : ''; } + // Event identity only: never borrow the currently selected/primary repo. + // Keep an explicit short audit repo when no canonical identity is carried. + function stageTrackerMergeBannerRepo(b) { + if (!b) return ''; + const repo = String(b.repo || (b.pr && b.pr.repo) || ''); + if (repo.indexOf('/') > 0) return repo; + const key = String(b.key || '').match(/^(.+)\/pr#\d+$/); + if (key) return key[1]; + const url = String(b.url || (b.pr && b.pr.url) || '').match(/^https:\/\/github\.com\/([^/]+\/[^/]+)\/pull\/\d+(?:[?#].*)?$/); + return url ? url[1] : repo; + } function stageTrackerMergeBannerText(b, nowMs) { const d = new Date(b.at || nowMs); const hm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`; @@ -24102,9 +24113,11 @@

All labels

if (!document.body) return null; let box = document.getElementById('merge-banners'); if (!box) { box = document.createElement('div'); box.id = 'merge-banners'; box.className = 'merge-banners'; box.setAttribute('aria-live', 'polite'); document.body.appendChild(box); } - const recent = ((_stageTrackerMerged.server && _stageTrackerMerged.server.recent) || []).find(e => stageTrackerMergedIdent(e.repo, e.number) === stageTrackerMergedIdent(b.repo, b.number)); - const info = Object.assign({ title: _stageTrackerPRTitle[b.key] || '', merged_by: '', lane: '', url: '' }, recent || {}, b); + const repo = stageTrackerMergeBannerRepo(b); + const recent = repo ? ((_stageTrackerMerged.server && _stageTrackerMerged.server.recent) || []).find(e => stageTrackerMergeBannerRepo(e).toLowerCase() === repo.toLowerCase() && stageTrackerMergeBannerNumber(e) === stageTrackerMergeBannerNumber(b)) : null; + const info = Object.assign({ title: _stageTrackerPRTitle[b.key] || '', merged_by: '', lane: '', url: '' }, recent || {}, b, { repo }); const num = stageTrackerMergeBannerNumber(info); + const repoChip = stageTrackerRepoChipHtml(repo, { repoChips: { primary: stageTrackerPrimaryRepo(), active: _stageTrackerFilter.repo } }); // A live merge the ledger has not listed yet still links: the key carries owner/name. if (!info.url && info.repo && info.repo.indexOf('/') > 0 && num && !info.preview) info.url = `https://github.com/${info.repo}/pull/${num}`; const t = stageTrackerMergeBannerText(info, Date.now()); @@ -24112,7 +24125,7 @@

All labels

el.className = 'merge-banner'; el.setAttribute('role', 'status'); if (b.rowKey) el.setAttribute('data-ham-row', b.rowKey); - el.innerHTML = `
${num ? `#${esc(num)} ` : ''}merged${info.preview ? ' (test)' : ''}
${esc(t.text)}
`; + el.innerHTML = `
${repoChip ? repoChip + ' ' : ''}${num ? `#${esc(num)} ` : ''}merged${info.preview ? ' (test)' : ''}
${esc(t.text)}
`; box.appendChild(el); while (box.children.length > STAGE_TRACKER_MERGE_BANNER_MAX) { toastCountdownCancel(box.children[0]); box.children[0].remove(); } toastCountdownBar(el, stageTrackerMergeBannerMs(), () => stageTrackerMergeBannerDismiss(el));