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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed

- Internal simplification, no behavior change.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed

- Internal simplification, no behavior change.
43 changes: 17 additions & 26 deletions .github/scripts/lib/lane-binding.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
};
Expand Down
43 changes: 17 additions & 26 deletions plugins/review/lib/lane-binding.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
};
Expand Down
43 changes: 17 additions & 26 deletions plugins/work-items/lib/lane-binding.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
};
Expand Down
Loading