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
---

### Fixed

- The issue lane's already-done evidence (`done-evidence.mjs`) now counts a merged pull request whose merge commit is on the default branch even when its `base.ref` is another branch: an upper layer of a native stack keeps the lower layer's branch as its base when the stack lands together. Its merge commit must still close the issue.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Fixed

- A demotion record's lift by a referencing pull request now also counts an upper layer of a native stack into main. Such a layer keeps the lower layer's branch as its base when the stack lands together, so the lift reads its `stack.baseRefName` beside `baseRefName`; its merge commit must still be on main.
14 changes: 11 additions & 3 deletions .github/scripts/lib/done-evidence.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,23 @@ export async function doneEvidence(github, repo, reason, issueNumber) {
return false;
}
const tied = (commit, at) => Date.parse(at) > opened && closesIssue(String(commit?.commit?.message ?? ""), issueNumber);
// Whether `sha` is on the default branch: its compare with the branch reads
// ahead (the branch moved past it) or identical.
const onBase = async (sha) => {
const comparison = await github("GET", `${repo}/compare/${encodeURIComponent(sha)}...${encodeURIComponent(base)}`).catch(() => null);
return comparison?.status === "ahead" || comparison?.status === "identical";
};
for (const pr of prs) {
if (
await github("GET", `${repo}/pulls/${pr}`)
.then(
async (pull) =>
Boolean(pull?.merged_at) &&
pull.base?.ref === base &&
/^[0-9a-f]{40}$/.test(pull.merge_commit_sha ?? "") &&
// An upper layer of a native stack keeps the lower layer's branch
// as its base when the stack lands together; its merge commit on
// the default branch is what counts.
(pull.base?.ref === base || (await onBase(pull.merge_commit_sha))) &&
tied(await github("GET", `${repo}/commits/${pull.merge_commit_sha}`), pull.merged_at),
)
.catch(() => false)
Expand All @@ -72,9 +81,8 @@ export async function doneEvidence(github, repo, reason, issueNumber) {
}
}
for (const sha of shas) {
const comparison = await github("GET", `${repo}/compare/${encodeURIComponent(sha)}...${encodeURIComponent(base)}`).catch(() => null);
if (
(comparison?.status === "ahead" || comparison?.status === "identical") &&
(await onBase(sha)) &&
(await github("GET", `${repo}/commits/${encodeURIComponent(sha)}`)
.then((commit) => tied(commit, commit?.commit?.committer?.date))
.catch(() => false))
Expand Down
17 changes: 16 additions & 1 deletion .github/scripts/work-resolve-issue/report-outcome.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4957,9 +4957,12 @@ const MERGE_SHA = "cafe".repeat(10);
// A merged pull request #5 whose merge commit says `message`; its title and
// body, which stay editable after the merge, say `body` (by default the same).
// A null message leaves the merge commit unreadable.
const evidencePull = (message, { body = message, base = "main", mergedAt = "2026-10-29T14:07:27Z", files = [{ filename: "docs/lanes.md" }] } = {}) =>
// `onMain`, when set, is the status GitHub's compare of the merge commit with
// the default branch answers; unset, that compare has no route and fails.
const evidencePull = (message, { body = message, base = "main", mergedAt = "2026-10-29T14:07:27Z", files = [{ filename: "docs/lanes.md" }], onMain } = {}) =>
evidenceClient([
[/\/repos\/o\/r$/, { default_branch: "main" }],
...(onMain === undefined ? [] : [[new RegExp(`/compare/${MERGE_SHA}\\.\\.\\.main$`), { status: onMain }]]),
[/\/pulls\/5$/, { merged_at: mergedAt, merge_commit_sha: MERGE_SHA, base: { ref: base }, title: "fix: tidy", body }],
[/\/pulls\/5\/files/, files],
...(message === null ? [] : [[new RegExp(`/commits/${MERGE_SHA}$`), { commit: { message, committer: { date: mergedAt } } }]]),
Expand Down Expand Up @@ -5010,6 +5013,18 @@ test("doneEvidence takes a merged pull request only into the default branch and
assert.equal(await doneEvidence(evidencePull("Closes #77", { mergedAt: "not a date" }), "/repos/o/r", reason, 77), false, "an unreadable merge time");
});

// An upper layer of a native stack merges with the layers below it and keeps
// the lower layer's branch as its base.ref, while its merge commit lands on the
// default branch; that commit on the default branch is what counts.
test("doneEvidence takes a stack layer whose merge commit is on the default branch", async () => {
const reason = "already-done: #5 shipped it";
const layer = { base: "feat/lower-layer" };
assert.equal(await doneEvidence(evidencePull("Closes #77", { ...layer, onMain: "ahead" }), "/repos/o/r", reason, 77), true, "merge commit behind main's tip");
assert.equal(await doneEvidence(evidencePull("Closes #77", { ...layer, onMain: "identical" }), "/repos/o/r", reason, 77), true, "merge commit is main's tip");
assert.equal(await doneEvidence(evidencePull("Closes #77", { ...layer, onMain: "diverged" }), "/repos/o/r", reason, 77), false, "merge commit off main");
assert.equal(await doneEvidence(evidencePull("Closes #77", layer), "/repos/o/r", reason, 77), false, "an unreadable compare");
});

// Re-review on #10978: lane pull requests carry `Closes #N`, so a change to a
// path the issue names is no evidence of its own.
test("doneEvidence takes no change to a path the issue names as evidence", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ def is_human(
# A pull request's merge and the agent identity's pin read-back over its first
# 100 comments; a longer thread proves no read-back.
LIFT_PULL = (
"number merged mergedAt baseRefName headRefOid mergeCommit{oid} "
"number merged mergedAt baseRefName stack{baseRefName} headRefOid mergeCommit{oid} "
"repository{nameWithOwner} comments(first:100){pageInfo{hasNextPage} "
"nodes{author{__typename login} body createdAt lastEditedAt}}"
)
Expand Down Expand Up @@ -2523,7 +2523,13 @@ def _lift(
if (
pull.get("__typename") != "PullRequest"
or not pull.get("merged")
or pull.get("baseRefName") != "main"
# Into main, or an upper layer of a native stack into main, which
# keeps the lower layer's branch as its base when the stack lands.
or "main"
not in (
pull.get("baseRefName"),
json_object(pull.get("stack")).get("baseRefName"),
)
or str(json_object(pull.get("repository")).get("nameWithOwner") or "").casefold()
!= f"{owner}/{name}".casefold()
or not SHA_RE.fullmatch(oid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ def test_a_lifted_record_is_commented_unlabeled_and_closed(self) -> None:
self.assertIn("state_reason=completed", gh.writes[2])
self.assertIn(f"pull request #7 merged at {FIX_MERGE}", gh.writes[0][-1])

def test_a_stack_layer_merged_into_main_lifts_the_record(self) -> None:
# An upper layer of a native stack lands with the layers below it and
# keeps the lower layer's branch as its base; its stack's base is main.
layer = merged_pull() | {"baseRefName": "feat/lower", "stack": {"baseRefName": "main"}}
gh = Gh({9: REVERT}, [layer])
self.assertEqual(self.run_close(gh), 1)
self.assertIn(f"pull request #7 merged at {FIX_MERGE}", gh.writes[0][-1])

def test_a_pull_request_into_another_branch_lifts_nothing(self) -> None:
for other in (
{"baseRefName": "feat/lower"},
{"baseRefName": "feat/lower", "stack": None},
{"baseRefName": "feat/lower", "stack": {"baseRefName": "release"}},
):
gh = Gh({9: REVERT}, [merged_pull() | other])
self.assertEqual((self.run_close(gh), gh.writes), (0, []), other)

def test_a_field_repository_close_removes_a_legacy_label(self) -> None:
# A record filed before the repository set models.issue-status still
# carries the label; post-merge-demotion-alert.yml removes it on close.
Expand Down
Loading