diff --git a/.changes/review/work-resolve-issue-issue-15696-43324264806-1-093130d9.md b/.changes/review/work-resolve-issue-issue-15696-43324264806-1-093130d9.md new file mode 100644 index 00000000000..80235ee856d --- /dev/null +++ b/.changes/review/work-resolve-issue-issue-15696-43324264806-1-093130d9.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Changed + +- Internal simplification, no behavior change. diff --git a/.changes/work-items/work-resolve-issue-issue-15696-43324264806-1-b9776421.md b/.changes/work-items/work-resolve-issue-issue-15696-43324264806-1-b9776421.md new file mode 100644 index 00000000000..80235ee856d --- /dev/null +++ b/.changes/work-items/work-resolve-issue-issue-15696-43324264806-1-b9776421.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Changed + +- Internal simplification, no behavior change. diff --git a/.github/scripts/lib/lane-binding.mjs b/.github/scripts/lib/lane-binding.mjs index a1ea2c2211d..bfa5dcc6699 100644 --- a/.github/scripts/lib/lane-binding.mjs +++ b/.github/scripts/lib/lane-binding.mjs @@ -73,7 +73,7 @@ export function laneFooter(body) { export function bindingOf(body) { const all = lines(body); const at = nonBlankIndexes(all); - if (at.length < 2 || laneFooter(body) === null) { + if (at.length < 2 || !FOOTER.test(all[at.at(-1)].trim())) { return null; } const match = BINDING.exec(all[at.at(-2)].trim()); @@ -122,10 +122,7 @@ export function wasEdited({ createdAt, updatedAt, lastEditedAt } = {}) { // Whether a comment with no binding still counts. export function legacyCounts(comment, cutoff = LEGACY_CUTOFF) { - if (cutoff === null) { - return true; - } - return Date.parse(comment.createdAt ?? "") <= Date.parse(cutoff) && !wasEdited(comment); + return cutoff === null || (Date.parse(comment.createdAt ?? "") <= Date.parse(cutoff) && !wasEdited(comment)); } // One file's bytes from a zip archive (stored or deflated), or null when the @@ -199,30 +196,24 @@ export function recordEntries(text) { export function laneChecker({ pr, getPull, getRun, listArtifacts, download, workflows = LANE_WORKFLOWS, cutoff = LEGACY_CUTOFF }) { const runs = new Map(); let pull; - const readPull = () => { - pull ??= getPull(Number(pr)); - return pull; + const readPull = () => (pull ??= getPull(Number(pr))); + const loadRun = async (runId) => { + const run = await getRun(runId); + const live = (await listArtifacts(runId)).filter((a) => String(a?.name ?? "").startsWith(RECORD_PREFIX) && a.expired !== true); + const entries = []; + const recorded = new Set(); + for (const artifact of live) { + const record = recordEntries(zipEntry(await download(artifact.id), RECORD_FILE)?.toString("utf8")); + entries.push(...record); + if (record.some((e) => e.complete === true)) { + recorded.add(artifact.name); + } + } + return { run, entries, recorded }; }; const readRun = (runId) => { if (!runs.has(runId)) { - runs.set( - runId, - (async () => { - const run = await getRun(runId); - const records = (await listArtifacts(runId)).filter((a) => String(a?.name ?? "").startsWith(RECORD_PREFIX)); - const live = records.filter((a) => a.expired !== true); - const entries = []; - const recorded = new Set(); - for (const artifact of live) { - const lines = recordEntries(zipEntry(await download(artifact.id), RECORD_FILE)?.toString("utf8")); - entries.push(...lines); - if (lines.some((e) => e.complete === true)) { - recorded.add(artifact.name); - } - } - return { run, entries, recorded }; - })(), - ); + runs.set(runId, loadRun(runId)); } return runs.get(runId); }; diff --git a/plugins/review/lib/lane-binding.mjs b/plugins/review/lib/lane-binding.mjs index c624ff480c6..d57bb9f0f06 100644 --- a/plugins/review/lib/lane-binding.mjs +++ b/plugins/review/lib/lane-binding.mjs @@ -75,7 +75,7 @@ export function laneFooter(body) { export function bindingOf(body) { const all = lines(body); const at = nonBlankIndexes(all); - if (at.length < 2 || laneFooter(body) === null) { + if (at.length < 2 || !FOOTER.test(all[at.at(-1)].trim())) { return null; } const match = BINDING.exec(all[at.at(-2)].trim()); @@ -124,10 +124,7 @@ export function wasEdited({ createdAt, updatedAt, lastEditedAt } = {}) { // Whether a comment with no binding still counts. export function legacyCounts(comment, cutoff = LEGACY_CUTOFF) { - if (cutoff === null) { - return true; - } - return Date.parse(comment.createdAt ?? "") <= Date.parse(cutoff) && !wasEdited(comment); + return cutoff === null || (Date.parse(comment.createdAt ?? "") <= Date.parse(cutoff) && !wasEdited(comment)); } // One file's bytes from a zip archive (stored or deflated), or null when the @@ -201,30 +198,24 @@ export function recordEntries(text) { export function laneChecker({ pr, getPull, getRun, listArtifacts, download, workflows = LANE_WORKFLOWS, cutoff = LEGACY_CUTOFF }) { const runs = new Map(); let pull; - const readPull = () => { - pull ??= getPull(Number(pr)); - return pull; + const readPull = () => (pull ??= getPull(Number(pr))); + const loadRun = async (runId) => { + const run = await getRun(runId); + const live = (await listArtifacts(runId)).filter((a) => String(a?.name ?? "").startsWith(RECORD_PREFIX) && a.expired !== true); + const entries = []; + const recorded = new Set(); + for (const artifact of live) { + const record = recordEntries(zipEntry(await download(artifact.id), RECORD_FILE)?.toString("utf8")); + entries.push(...record); + if (record.some((e) => e.complete === true)) { + recorded.add(artifact.name); + } + } + return { run, entries, recorded }; }; const readRun = (runId) => { if (!runs.has(runId)) { - runs.set( - runId, - (async () => { - const run = await getRun(runId); - const records = (await listArtifacts(runId)).filter((a) => String(a?.name ?? "").startsWith(RECORD_PREFIX)); - const live = records.filter((a) => a.expired !== true); - const entries = []; - const recorded = new Set(); - for (const artifact of live) { - const lines = recordEntries(zipEntry(await download(artifact.id), RECORD_FILE)?.toString("utf8")); - entries.push(...lines); - if (lines.some((e) => e.complete === true)) { - recorded.add(artifact.name); - } - } - return { run, entries, recorded }; - })(), - ); + runs.set(runId, loadRun(runId)); } return runs.get(runId); }; diff --git a/plugins/work-items/lib/lane-binding.mjs b/plugins/work-items/lib/lane-binding.mjs index c624ff480c6..d57bb9f0f06 100644 --- a/plugins/work-items/lib/lane-binding.mjs +++ b/plugins/work-items/lib/lane-binding.mjs @@ -75,7 +75,7 @@ export function laneFooter(body) { export function bindingOf(body) { const all = lines(body); const at = nonBlankIndexes(all); - if (at.length < 2 || laneFooter(body) === null) { + if (at.length < 2 || !FOOTER.test(all[at.at(-1)].trim())) { return null; } const match = BINDING.exec(all[at.at(-2)].trim()); @@ -124,10 +124,7 @@ export function wasEdited({ createdAt, updatedAt, lastEditedAt } = {}) { // Whether a comment with no binding still counts. export function legacyCounts(comment, cutoff = LEGACY_CUTOFF) { - if (cutoff === null) { - return true; - } - return Date.parse(comment.createdAt ?? "") <= Date.parse(cutoff) && !wasEdited(comment); + return cutoff === null || (Date.parse(comment.createdAt ?? "") <= Date.parse(cutoff) && !wasEdited(comment)); } // One file's bytes from a zip archive (stored or deflated), or null when the @@ -201,30 +198,24 @@ export function recordEntries(text) { export function laneChecker({ pr, getPull, getRun, listArtifacts, download, workflows = LANE_WORKFLOWS, cutoff = LEGACY_CUTOFF }) { const runs = new Map(); let pull; - const readPull = () => { - pull ??= getPull(Number(pr)); - return pull; + const readPull = () => (pull ??= getPull(Number(pr))); + const loadRun = async (runId) => { + const run = await getRun(runId); + const live = (await listArtifacts(runId)).filter((a) => String(a?.name ?? "").startsWith(RECORD_PREFIX) && a.expired !== true); + const entries = []; + const recorded = new Set(); + for (const artifact of live) { + const record = recordEntries(zipEntry(await download(artifact.id), RECORD_FILE)?.toString("utf8")); + entries.push(...record); + if (record.some((e) => e.complete === true)) { + recorded.add(artifact.name); + } + } + return { run, entries, recorded }; }; const readRun = (runId) => { if (!runs.has(runId)) { - runs.set( - runId, - (async () => { - const run = await getRun(runId); - const records = (await listArtifacts(runId)).filter((a) => String(a?.name ?? "").startsWith(RECORD_PREFIX)); - const live = records.filter((a) => a.expired !== true); - const entries = []; - const recorded = new Set(); - for (const artifact of live) { - const lines = recordEntries(zipEntry(await download(artifact.id), RECORD_FILE)?.toString("utf8")); - entries.push(...lines); - if (lines.some((e) => e.complete === true)) { - recorded.add(artifact.name); - } - } - return { run, entries, recorded }; - })(), - ); + runs.set(runId, loadRun(runId)); } return runs.get(runId); };