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
7 changes: 1 addition & 6 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11893,16 +11893,11 @@ var METRICS_REASON_KEYS = [
[/^no Project: /, "this Project has nothing to read yet"]
];
var READ_FAILED = /^read-failed:\s*(.+)$/;
var READ_DETAIL_MAX = 60;
var shortDetail = (detail) => {
const line2 = text(detail);
return line2.length <= READ_DETAIL_MAX ? line2 : line2.slice(0, READ_DETAIL_MAX - 1) + "…";
};
function metricsReasonText(reason) {
const code = text(reason);
if (code === "" || !language().startsWith("zh")) return hostText(code);
const readFailed = READ_FAILED.exec(code);
if (readFailed !== null) return t("reading GitHub failed ({detail})", { detail: shortDetail(readFailed[1]) });
if (readFailed !== null) return t("reading GitHub failed ({detail})", { detail: readFailed[1] });
const named = METRICS_REASON_KEYS.find(([pattern]) => pattern.test(code));
return named === void 0 ? hostText(code) : t(named[1]);
}
Expand Down
10 changes: 3 additions & 7 deletions core/src/client/project-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ export function metricsView(metrics, { tasks } = {}) {
// #2985: a failed metrics read answers a machine reason, and the note printed it raw beside a
// translated prefix. A zh window reads a sentence; an English window keeps the host's own token
// exactly as it did, and a reason this client cannot name stays the host's words rather than a
// guessed sentence. The detail of `read-failed:` rides in the sentence, cut short.
// guessed sentence. The detail of `read-failed:` rides in the sentence whole: a cut line hid the
// reason the note exists to give.
const METRICS_REASON_KEYS = [
[/^no-credentials$/, 'this machine has no GitHub token yet'],
[/^no-fetch$/, 'this machine has no way to read GitHub yet'],
Expand All @@ -509,17 +510,12 @@ const METRICS_REASON_KEYS = [
[/^no Project: /, 'this Project has nothing to read yet'],
]
const READ_FAILED = /^read-failed:\s*(.+)$/
const READ_DETAIL_MAX = 60
const shortDetail = (detail) => {
const line = text(detail)
return line.length <= READ_DETAIL_MAX ? line : line.slice(0, READ_DETAIL_MAX - 1) + '\u2026'
}

function metricsReasonText(reason) {
const code = text(reason)
if (code === '' || !language().startsWith('zh')) return hostText(code)
const readFailed = READ_FAILED.exec(code)
if (readFailed !== null) return t('reading GitHub failed ({detail})', { detail: shortDetail(readFailed[1]) })
if (readFailed !== null) return t('reading GitHub failed ({detail})', { detail: readFailed[1] })
const named = METRICS_REASON_KEYS.find(([pattern]) => pattern.test(code))
return named === undefined ? hostText(code) : t(named[1])
}
Expand Down
23 changes: 21 additions & 2 deletions core/test/project-board-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,12 @@ function fakeLocale(active) {
}
}

const metricsNote = (metrics) => {
const metricsNoteNode = (metrics) => {
const drawn = all(ProjectBoardPane({ project: { id: 'project-1', name: 'FlyBot' }, rows: [], metrics }))
const note = drawn.find(node => node.props?.className === 'bt-project-metrics-note')
return drawn.find(node => node.props?.className === 'bt-project-metrics-note') ?? null
}
const metricsNote = (metrics) => {
const note = metricsNoteNode(metrics)
return note ? textOf(note) : ''
}

Expand Down Expand Up @@ -748,6 +751,22 @@ test('#2985: a zh window reads the metrics reason as a sentence, never the host
}
})

// #3157: the note cut a long read-failed detail at 60 characters and appended `…`, so the reason
// the note exists to give could not be read anywhere. The note now draws the whole sentence.
test('a long read-failed detail is readable in full in the note', () => {
const detail = '/pulls answered 403: the token this Project reads with cannot list pull requests on the source repository'
const metrics = { ok: false, reason: `read-failed: ${detail}`, metrics: {}, running: [] }
const off = installLocale(fakeLocale('zh'))
try {
const note = metricsNoteNode(metrics)
assert.ok(note, 'a failed read draws the note')
assert.equal(textOf(note), `指标不可用:读取 GitHub 失败(${detail})`, 'the note reads the whole reason')
assert.ok(!textOf(note).includes('\u2026'), 'the note never cuts the reason it reports')
} finally {
off()
}
})

test('a running row carries who, claim age, source and activity, and opens its board', () => {
const now = Date.now()
const view = metricsView({ ok: true, metrics: {}, running: [{ id: 'task-1', title: 'Ship it', status: 'claimed', who: 'Dev', sinceMs: 3 * 60 * 60 * 1000, source: 'group', lastActivityAt: now - 60000 }] })
Expand Down
Loading
Loading