mirror of
https://github.com/github/awesome-copilot.git
synced 2026-10-12 23:04:14 +00:00
fix(canvas): pin PR approval to the reviewed commit
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8045e7e0-dfd7-425a-9131-21ea5ca1553e
This commit is contained in:
co-authored by
Copilot App
parent
e9262f6c98
commit
d63527fe89
@@ -28,7 +28,9 @@ authenticated `gh` CLI.
|
||||
Use Left/Right arrows or Home/End to switch detail tabs.
|
||||
- **GitHub actions** — submit feedback, request changes, close a PR, or approve it and
|
||||
enable auto-merge with a merge commit. Each action needs two clicks to confirm and
|
||||
is also recorded in local board history.
|
||||
is also recorded in local board history. Approval is pinned to the board's commit
|
||||
SHA, and auto-merge requires that same head commit. If the head changes, refresh
|
||||
and review the new commit before approving again.
|
||||
Only one GitHub action can run per PR at a time.
|
||||
- **Reset board** — after a second click to confirm, clear every local AI review,
|
||||
queued review, manual move, recorded action, and history entry, then reload open PRs.
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function applyDecisionOnGitHub({ store, number, kind, comment, refr
|
||||
|
||||
let result;
|
||||
if (kind === "approve") {
|
||||
result = await github.approveAndEnableAutoMerge(store.repo, number, { body });
|
||||
result = await github.approveAndEnableAutoMerge(store.repo, number, { body, headRefOid: item.headRefOid });
|
||||
} else if (kind === "close") {
|
||||
result = await github.closePullRequest(store.repo, number, { body });
|
||||
} else {
|
||||
|
||||
@@ -66,11 +66,18 @@ export async function closePullRequest(repo, number, { body } = {}, runner = run
|
||||
}
|
||||
}
|
||||
|
||||
export async function approveAndEnableAutoMerge(repo, number, { body } = {}, runner = runGh) {
|
||||
await submitPullRequestReview(repo, number, { kind: "approve", body }, runner);
|
||||
export async function approveAndEnableAutoMerge(repo, number, { body, headRefOid } = {}, runner = runGh) {
|
||||
if (!headRefOid) throw new Error("The board has no commit SHA for this pull request. Refresh before approving.");
|
||||
const current = JSON.parse(await runner(["api", `repos/${repo}/pulls/${number}`]));
|
||||
if (current.state !== "open" || current.head?.sha !== headRefOid) {
|
||||
throw new Error("The pull request changed or is no longer open. Refresh and review it again before approving.");
|
||||
}
|
||||
await runner(["api", `repos/${repo}/pulls/${number}/reviews`, "--method", "POST", "--input", "-"], {
|
||||
input: JSON.stringify({ event: "APPROVE", commit_id: headRefOid, body: String(body ?? "").trim() }),
|
||||
});
|
||||
|
||||
try {
|
||||
await runner(["pr", "merge", String(number), "-R", repo, "--auto", "--merge"]);
|
||||
await runner(["pr", "merge", String(number), "-R", repo, "--auto", "--merge", "--match-head-commit", headRefOid]);
|
||||
} catch (error) {
|
||||
return {
|
||||
status: "approval-submitted",
|
||||
|
||||
Reference in New Issue
Block a user