Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-tracker-copy-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Tracker Copy link now copies the selected issue or PR's canonical URL, including PRs linked or nested under issues, instead of copying the parent issue link.
83 changes: 83 additions & 0 deletions src/pkg/dashboard/stage_tracker_copy_link_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package dashboard

import "testing"

func TestStageTrackerCopyLinkTargets(t *testing.T) {
html := indexHTML(t)
script := stageTrackerRowActionsPreamble(t, html) + "\n" + jsFunc(t, html, "stageTrackerMenuTargets") + `
const issue = { repo: 'acme/console', kind: 'issue', number: 7, url: 'https://github.com/acme/console/issues/7',
linked_prs: [
{ number: 42, url: 'https://github.com/acme/console/pull/42', stage: 50 },
{ number: 43, url: 'https://forge.example/other/project/pull/43', stage: 50 }
] };
const rootPR = { repo: 'acme/console', kind: 'pr', number: 44, url: 'https://github.com/acme/console/pull/44',
linked_issues: [{ number: 7, url: issue.url }] };
_stageTracker = { items: [issue, rootPR] };
const root = { dataset: { hamKey: stageTrackerItemKey(issue) }, parentNode: hamPanel };
const boundary = (key, single) => ({ dataset: single ? { hamTargetKey: key } : { hamSubKey: key }, querySelector() { return null; } });
function eventTarget(row, sub) {
return { closest(selector) {
if (selector === '.ham-row[data-ham-key]') return row;
if (selector.includes('[data-ham-sub-key]')) return sub;
return null;
} };
}
const writes = [], toasts = [];
const navigator = { clipboard: { async writeText(text) { writes.push(text); } } };
global.showToast = (text, kind) => toasts.push({ text, kind });
(async () => {
const cases = [
[eventTarget(root, null), issue.url, 'issue'],
[eventTarget({ dataset: { hamKey: stageTrackerItemKey(rootPR) }, parentNode: hamPanel }, null), rootPR.url, 'pr'],
[eventTarget(root, boundary('acme/console/pr#42', true)), issue.linked_prs[0].url, 'pr'],
[eventTarget(root, boundary('acme/console/pr#42', false)), issue.linked_prs[0].url, 'pr'],
[eventTarget(root, boundary('other/project/pr#43', true)), issue.linked_prs[1].url, 'pr'],
[eventTarget(root, boundary('other/project/pr#43', false)), issue.linked_prs[1].url, 'pr']
];
for (const [target, url, kind] of cases) {
const mapped = stageTrackerMenuTargets(target);
assert.strictEqual(mapped.items.length, 1);
assert.strictEqual(mapped.items[0].kind, kind);
await runRowAction('copy', mapped.items);
assert.strictEqual(toasts.at(-1).kind, 'success', toasts.at(-1).text);
assert.strictEqual(writes.at(-1), url, 'copy follows the exact root, single-linked or nested target');
}
const explicit = stageTrackerLinkedPRItem(issue, { repo: 'other/project', number: 45, url: '' });
assert.strictEqual(explicit.repo, 'other/project', 'explicit linked repo is not replaced by the parent repo');
await runRowAction('copy', [issue, rootPR, stageTrackerItemByKey(_stageTracker, 'other/project/pr#43')]);
assert.strictEqual(writes.at(-1), [issue.url, rootPR.url, issue.linked_prs[1].url].join('\n'));
assert.strictEqual(toasts.at(-1).text, 'Copied 3 links');
const count = writes.length;
for (const bad of [
{ ...rootPR, url: issue.url },
{ ...rootPR, url: 'https://github.com/acme/console/pull/99' },
{ ...rootPR, url: '' },
{ ...rootPR, url: 'javascript:alert(1)' },
{ ...issue, url: rootPR.url }
]) {
await runRowAction('copy', [issue, bad]);
assert.strictEqual(writes.length, count, 'never copy a parent, wrong-kind, wrong-number or partial selection');
assert.strictEqual(toasts.at(-1).kind, 'error');
}
navigator.clipboard.writeText = async () => { throw new Error('denied'); };
await runRowAction('copy', issue);
assert.strictEqual(toasts.at(-1).kind, 'error');
assert.ok(toasts.at(-1).text.includes('denied'), 'clipboard failures use styled app feedback');
})().catch(err => { console.error(err); process.exit(1); });
`
runStageTrackerRowActionsScript(t, script)
}

func TestStageTrackerSingleLinkedPRCopyBoundary(t *testing.T) {
html := indexHTML(t)
script := stageTrackerRowsPreludeJS(t, html) + stageTrackerRowsFixtureJS + `
const issue = { repo: 'acme/console', kind: 'issue', number: 7, title: 'Issue', url: 'https://github.com/acme/console/issues/7',
stage: 40, linked_prs: [{ number: 42, title: 'PR', url: 'https://forge.example/other/project/pull/42', stage: 50 }] };
const row = stageTrackerRowHtml(issue, stages, ctx);
assert.ok(row.includes('<li class="ham-seg ham-head-pr" data-ham-target-key="other/project/pr#42">'), 'the single covering PR cell has its own menu target without changing flex children');
assert.ok(/data-ham-target-key="other\/project\/pr#42">[\s\S]*?href="https:\/\/forge.example\/other\/project\/pull\/42"/.test(row), 'the target surrounds the actual PR reference');
assert.ok(row.includes('href="' + issue.url + '"'), 'the parent issue keeps its own link');
assert.ok(row.includes('aria-label="Actions for acme/console#7"'), 'the issue kebab remains issue-targeted');
`
runStageTrackerRowActionsScript(t, script)
}
1 change: 1 addition & 0 deletions src/pkg/dashboard/stage_tracker_row_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func stageTrackerRowActionsPreamble(t *testing.T, html string) string {
jsFunc(t, html, "stageTrackerAdvisoryCloseHint"),
jsFunc(t, html, "stageTrackerAdvisoryCloseMessage"),
jsFunc(t, html, "stageTrackerNothingToActOn"),
jsFunc(t, html, "stageTrackerCopyLink"),
jsFunc(t, html, "runRowAction"),
jsFunc(t, html, "makeToastSticky"),
stageTrackerDomStubJS,
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/dashboard/stage_tracker_ui_rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ assert.deepStrictEqual(segStates(row), [D, D, D, 'active', T, T, 'todo cap'], 'o
assert.ok(tooltip(row).includes('Covering PR: #102'), tooltip(row));
assert.deepStrictEqual(prCol(row).length, 1, 'the covering PR sits in the PR column of the title line');
assert.strictEqual(subs(row).length, 0, 'no sub-rows for a single covering PR');
const prCell = (html) => (html.slice(0, html.indexOf('aria-label="Pipeline progress"')).match(/<li class="ham-seg ham-head-pr">([\s\S]*?)<\/li>/) || [])[1] || '';
const prCell = (html) => (html.slice(0, html.indexOf('aria-label="Pipeline progress"')).match(/<li class="ham-seg ham-head-pr"[^>]*>([\s\S]*?)<\/li>/) || [])[1] || '';
assert.ok(prCell(row).startsWith(STAGE_TRACKER_LINKED_GLYPH + '<a class="ham-pr-ref"'), 'an in-row PR is led by the linked glyph: ' + prCell(row));
assert.ok(prCell(row).includes('title="Author: hive · ' + esc(STAGE_TRACKER_LINKED_TIP) + '"'), 'the PR link tooltip explains the shared row: ' + prCell(row));
// A PR listed by two open issues shows on both rows; every row but the
Expand Down Expand Up @@ -484,7 +484,7 @@ row = stageTrackerRowHtml({ repo: 'acme/console', number: 9, kind: 'issue', titl
sr = subs(row);
{
const head = sr[0].slice(0, sr[0].indexOf('aria-label="Pipeline progress"'));
const cell = (head.match(/<li class="ham-seg ham-head-pr">([\s\S]*?)<\/li>/) || [])[1] || '';
const cell = (head.match(/<li class="ham-seg ham-head-pr"[^>]*>([\s\S]*?)<\/li>/) || [])[1] || '';
assert.ok(cell, 'sub-row header has one PR cell: ' + head);
assert.ok(!/<br|<div|<p\b/.test(cell), 'no block-level element inside the PR cell: ' + cell);
const order = [cell.indexOf('class="ham-linked-ico"'), cell.indexOf('<a class="ham-pr-ref"'), cell.indexOf('class="ham-badge ham-lineage"'), cell.lastIndexOf('<span class="ham-badge">v5</span>')];
Expand Down
18 changes: 13 additions & 5 deletions src/pkg/dashboard/static-src/js/tracker-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,10 @@
// The row (or nested PR) an event happened on, as the items a menu acts
// on: a selected row with company stands for the whole selection.
function stageTrackerMenuTargets(target) {
const sub = target && target.closest ? target.closest('[data-ham-sub-key]') : null;
const sub = target && target.closest ? target.closest('[data-ham-sub-key], [data-ham-target-key]') : null;
const row = target && target.closest ? target.closest('.ham-row[data-ham-key]') : null;
if (!row && !sub) return null;
const key = sub ? sub.dataset.hamSubKey : row.dataset.hamKey;
const key = sub ? (sub.dataset.hamTargetKey || sub.dataset.hamSubKey) : row.dataset.hamKey;
const list = row ? row.parentNode : sub.closest('#activity-monitor-panel');
const keys = _stageTrackerSel.has(key) && _stageTrackerSel.size > 1 && list ? stageTrackerRowKeys(list).filter(k => _stageTrackerSel.has(k)) : [key];
return { items: stageTrackerItemsForKeys(keys), restore: sub ? (sub.querySelector('.ham-kebab') || row) : row };
Expand Down Expand Up @@ -2307,6 +2307,14 @@
const refs = (rows || []).map(stageTrackerRefOf).filter(Boolean).join(', ');
if (typeof showToast === 'function') showToast(stageTrackerActionLabel(id) + ': nothing to act on' + (refs ? ' — ' + refs + ' is not waiting on that decision' : ''), 'warning');
}
// A copy must identify the selected item, not its parent issue or a
// decision target. Keep the canonical URL (including its forge host).
function stageTrackerCopyLink(item) {
if (!item || (item.kind !== 'issue' && item.kind !== 'pr')) return '';
const url = String(item.url || '');
const m = /^https?:\/\/[^/]+\/[^/]+\/[^/]+\/(issues|pull)\/(\d+)(?:[?#].*)?$/.exec(url);
return m && m[1] === (item.kind === 'pr' ? 'pull' : 'issues') && Number(m[2]) === Number(item.number) && Number(item.number) > 0 ? url : '';
}
async function runRowAction(action, row) {
let items = Array.isArray(row) ? row.slice() : (row ? [row] : []);
const id = action;
Expand All @@ -2327,10 +2335,11 @@
return { toasts: [], pending: [] };
}
if (id === 'copy') {
const text = items.map(it => it.url).filter(Boolean).join('\n');
try {
const links = items.map(stageTrackerCopyLink);
if (links.some(url => !url)) throw new Error('No matching GitHub link for the selected item — refresh the tracker and try again');
if (!navigator.clipboard) throw new Error('clipboard unavailable');
await navigator.clipboard.writeText(text);
await navigator.clipboard.writeText(links.join('\n'));
showToast(items.length > 1 ? 'Copied ' + items.length + ' links' : 'Link copied', 'success');
} catch (e) { showToast('Could not copy: ' + (e && e.message ? e.message : 'clipboard unavailable'), 'error'); }
return { toasts: [], pending: [] };
Expand Down Expand Up @@ -2513,4 +2522,3 @@
// kind → { name, bytes (ArrayBuffer), buffer (AudioBuffer|null), failed }
var _stageTrackerClips = { open: null, merge: null };
var _stageTrackerSettingsReturnFocus = null;

13 changes: 8 additions & 5 deletions src/pkg/dashboard/static-src/js/tracker-row-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// The since column is an empty spacer here (same width as the strip
// row's, which carries the time on step): a wrapped title must not float
// the age away from the chevrons it describes.
function stageTrackerHeadColsHtml(prRefs, leadHtml, chipsHtml) {
function stageTrackerHeadColsHtml(prRefs, leadHtml, chipsHtml, prTargetKey) {
const wide = !(prRefs && prRefs.length);
return `<div class="ham-strip-row ham-head-cols"><ol class="ham-strip"><li class="ham-seg ham-head-lead${wide ? ' ham-head-wide' : ''}">${leadHtml || ''}</li>${wide ? '' : `<li class="ham-seg ham-head-pr">${prRefs.join('')}</li>`}<li class="ham-seg cap"><span class="ham-badges">${chipsHtml || ''}</span></li></ol><span class="ham-since"></span></div>`;
return `<div class="ham-strip-row ham-head-cols"><ol class="ham-strip"><li class="ham-seg ham-head-lead${wide ? ' ham-head-wide' : ''}">${leadHtml || ''}</li>${wide ? '' : `<li class="ham-seg ham-head-pr"${prTargetKey ? ` data-ham-target-key="${esc(prTargetKey)}"` : ''}>${prRefs.join('')}</li>`}<li class="ham-seg cap"><span class="ham-badges">${chipsHtml || ''}</span></li></ol><span class="ham-since"></span></div>`;
}

function stageTrackerSinceHtml(item, nowMs) {
Expand Down Expand Up @@ -59,7 +59,8 @@
// PRs under it (the superseded-by prompt pre-fills the one sibling).
function stageTrackerLinkedPRItem(issue, lp) {
const open = Array.isArray(issue.linked_prs) ? issue.linked_prs.filter(x => x && x.number !== lp.number && stageTrackerLinkedPROpen(x, issue)) : [];
return { repo: issue.repo, number: lp.number, kind: 'pr', title: lp.title || '', url: lp.url || '', author: lp.author || '', author_kind: lp.author_kind || '',
const canonical = /^https?:\/\/[^/]+\/([^/]+\/[^/]+)\/pull\/\d+(?:[?#].*)?$/.exec(String(lp.url || ''));
return { repo: canonical ? canonical[1] : (lp.repo || issue.repo), number: lp.number, kind: 'pr', title: lp.title || '', url: lp.url || '', author: lp.author || '', author_kind: lp.author_kind || '',
stage: lp.stage || 0, stage_since: lp.stage_since || '', stage_slug: lp.stage_slug || '', modifiers: lp.modifiers || [], deferred_modifiers: lp.deferred_modifiers || [], caption: lp.caption || '', reason: lp.reason || '', preparation: lp.preparation || null,
human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', base_ref: lp.base_ref || '', decision_needed: lp.decision_needed || null,
adoption: lp.adoption || null, takeover: lp.takeover || null, superseded: !!lp.superseded, supersedes: lp.supersedes || null, parent: Number(issue.number) || 0, siblings: open.map(x => Number(x.number) || 0),
Expand Down Expand Up @@ -475,12 +476,14 @@
const nowMs = Number(ctx.nowMs) || Date.now();
const isIssue = item.kind === 'issue';
const title = item.title || '';
let prRefs = [], shown = item, range = null, subs = '', subRows = null;
let prRefs = [], shown = item, range = null, subs = '', subRows = null, prTargetKey = '';
if (isIssue) {
const linked = stageTrackerLinkedSorted(item, stages);
if (linked.length === 1) {
// One covering PR: a single entry whose strip the PR's stage drives.
const lp = linked[0];
const pr = stageTrackerLinkedPRItem(item, lp);
prTargetKey = stageTrackerItemKey(pr);
const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : '');
const lineage = (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(lp, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(lp, nowMs) : '');
prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), typeof stageTrackerLinkedChipsHtml === 'function' ? stageTrackerLinkedChipsHtml(lp, lineage) : (lineage || null), lp.base_ref)];
Expand Down Expand Up @@ -540,7 +543,7 @@
${typeof stageTrackerPreparationNodeHtml === 'function' ? stageTrackerPreparationNodeHtml(item, stages, ctx) : ''}
${stageTrackerRowToolsHtml(item)}
<div class="ham-row-head">
${stageTrackerHeadColsHtml(prRefs, leadHtml, stageTrackerActedBadgeHtml(item, nowMs) + stageTrackerChipsHtml(shown) + (typeof stageTrackerLeadButtonHtml === 'function' ? stageTrackerLeadButtonHtml(item, nowMs, subRows) : ''))}
${stageTrackerHeadColsHtml(prRefs, leadHtml, stageTrackerActedBadgeHtml(item, nowMs) + stageTrackerChipsHtml(shown) + (typeof stageTrackerLeadButtonHtml === 'function' ? stageTrackerLeadButtonHtml(item, nowMs, subRows) : ''), prTargetKey)}
</div>
<div class="ham-strip-row">
<ol class="ham-strip" aria-label="Pipeline progress"${stageTrackerMoveAttrs(stageTrackerItemKey(item), ctx)}>${stageTrackerStripItems(shown, stages, range, nowMs, ctx)}</ol>
Expand Down
Loading
Loading