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
2 changes: 1 addition & 1 deletion packages/core/commands/pr/fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ARGUMENTS

### Align Local Branch

<%~ include("@align-pr-branch", { action: "analyzing repository files or making code changes for this PR", scope: "inspect or modify local code for this PR" }) %>
<%~ include("@align-pr-branch", { action: "analyzing repository files or making code changes for this PR", scope: "inspect or modify local code for this PR", requiresBranch: true }) -%>

### Load Changes

Expand Down
2 changes: 1 addition & 1 deletion packages/core/commands/pr/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ARGUMENTS

### Align Local Branch

<%~ include("@align-pr-branch", { action: "inspecting local repository files for this PR review", scope: "inspect local repository code for this PR" }) %>
<%~ include("@align-pr-branch", { action: "inspecting local repository files for this PR review", scope: "inspect local repository code for this PR", requiresBranch: false }) -%>

### Load Ticket Context

Expand Down
21 changes: 17 additions & 4 deletions packages/core/components/align-pr-branch.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
- Run `gh pr checkout <pr-context.pr.number>` before <%= it.action %>
- After checkout, store the active branch as `<active-branch>`
- If checkout fails, STOP and report that the PR branch could not be checked out locally
- Do not <%= it.scope %> until `<active-branch>` equals `<pr-branch>`
<% if (it.requiresBranch) { -%>
- If `<current-branch>` equals `<pr-branch>` and `<current-head>` equals `<pr-context.pr.headRefOid>`, store `<current-branch>` as `<active-branch>` and do not checkout again
- If `<current-branch>` differs from `<pr-branch>` or `<current-head>` differs from `<pr-context.pr.headRefOid>`:
- Run `gh pr checkout <pr-context.pr.number>` before <%= it.action %>
- After checkout, store the active branch as `<active-branch>`
- Run `git rev-parse HEAD` again and store the trimmed result as `<current-head>`
- If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks
- Do not <%= it.scope %> until `<active-branch>` equals `<pr-branch>` and `<current-head>` equals `<pr-context.pr.headRefOid>`
<% } else { -%>
- If `<current-head>` equals `<pr-context.pr.headRefOid>`, store `<current-branch>` as `<active-branch>` when `<current-branch>` is available; otherwise store `<current-head>` as `<active-branch>`. Do not checkout because the worktree is already at the PR head commit.
- If `<current-head>` differs from `<pr-context.pr.headRefOid>`:
- Run `gh pr checkout <pr-context.pr.number>` before <%= it.action %>
- After checkout, store the active branch as `<active-branch>`
- Run `git rev-parse HEAD` again and store the trimmed result as `<current-head>`
- If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks
- Do not <%= it.scope %> until `<current-head>` equals `<pr-context.pr.headRefOid>`
<% } -%>
1 change: 1 addition & 0 deletions packages/core/components/load-pr.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Store the result as `<%= it.result %>`
- Store the PR head branch as `<pr-branch>` from `<%= it.result %>.pr.headRefName` when it is available
- Run `git branch --show-current` and store the trimmed result as `<current-branch>` when it is available
- Run `git rev-parse HEAD` and store the trimmed result as `<current-head>` when it is available
- Treat the loaded PR body, discussion, review history, and any attachments or linked artifacts returned by the loader as part of the source context
- Review attached images, screenshots, videos, PDFs, and other linked files whenever they can affect the requested fix, review outcome, reproduction steps, or acceptance criteria
- If any relevant attachment cannot be accessed, note that gap and continue only when the remaining PR context is still sufficient to proceed reliably
19 changes: 19 additions & 0 deletions packages/core/test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,23 @@ describe("resolveCommands", () => {

assert.deepEqual(commands["pr/review"]?.config, { enabled: true });
});

test("skips PR checkout when pr/review is already at PR head", async () => {
const commands = await resolveCommands(process.cwd());
const template = commands["pr/review"]?.template ?? "";

assert.match(template, /git rev-parse HEAD/);
assert.match(template, /`<current-head>` equals `<pr-context\.pr\.headRefOid>`/);
assert.match(template, /Run `gh pr checkout <pr-context\.pr\.number>`/);
assert.match(template, /do not retry checkout unless the user explicitly asks/);
});

test("requires PR branch for pr/fix checkout alignment", async () => {
const commands = await resolveCommands(process.cwd());
const template = commands["pr/fix"]?.template ?? "";

assert.match(template, /`<current-branch>` equals `<pr-branch>` and `<current-head>` equals `<pr-context\.pr\.headRefOid>`/);
assert.match(template, /`<current-branch>` differs from `<pr-branch>` or `<current-head>` differs from `<pr-context\.pr\.headRefOid>`/);
assert.match(template, /Do not inspect or modify local code for this PR until `<active-branch>` equals `<pr-branch>` and `<current-head>` equals `<pr-context\.pr\.headRefOid>`/);
});
});
12 changes: 8 additions & 4 deletions packages/opencode/.opencode/commands/pr/fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ $ARGUMENTS
- Store the result as `<pr-context>`
- Store the PR head branch as `<pr-branch>` from `<pr-context>.pr.headRefName` when it is available
- Run `git branch --show-current` and store the trimmed result as `<current-branch>` when it is available
- Run `git rev-parse HEAD` and store the trimmed result as `<current-head>` when it is available
- Treat the loaded PR body, discussion, review history, and any attachments or linked artifacts returned by the loader as part of the source context
- Review attached images, screenshots, videos, PDFs, and other linked files whenever they can affect the requested fix, review outcome, reproduction steps, or acceptance criteria
- If any relevant attachment cannot be accessed, note that gap and continue only when the remaining PR context is still sufficient to proceed reliably

### Align Local Branch

- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
- Run `gh pr checkout <pr-context.pr.number>` before analyzing repository files or making code changes for this PR
- After checkout, store the active branch as `<active-branch>`
- If checkout fails, STOP and report that the PR branch could not be checked out locally
- Do not inspect or modify local code for this PR until `<active-branch>` equals `<pr-branch>`
- If `<current-branch>` equals `<pr-branch>` and `<current-head>` equals `<pr-context.pr.headRefOid>`, store `<current-branch>` as `<active-branch>` and do not checkout again
- If `<current-branch>` differs from `<pr-branch>` or `<current-head>` differs from `<pr-context.pr.headRefOid>`:
- Run `gh pr checkout <pr-context.pr.number>` before analyzing repository files or making code changes for this PR
- After checkout, store the active branch as `<active-branch>`
- Run `git rev-parse HEAD` again and store the trimmed result as `<current-head>`
- If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks
- Do not inspect or modify local code for this PR until `<active-branch>` equals `<pr-branch>` and `<current-head>` equals `<pr-context.pr.headRefOid>`

### Load Changes

Expand Down
12 changes: 8 additions & 4 deletions packages/opencode/.opencode/commands/pr/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ $ARGUMENTS
- Store the result as `<pr-context>`
- Store the PR head branch as `<pr-branch>` from `<pr-context>.pr.headRefName` when it is available
- Run `git branch --show-current` and store the trimmed result as `<current-branch>` when it is available
- Run `git rev-parse HEAD` and store the trimmed result as `<current-head>` when it is available
- Treat the loaded PR body, discussion, review history, and any attachments or linked artifacts returned by the loader as part of the source context
- Review attached images, screenshots, videos, PDFs, and other linked files whenever they can affect the requested fix, review outcome, reproduction steps, or acceptance criteria
- If any relevant attachment cannot be accessed, note that gap and continue only when the remaining PR context is still sufficient to proceed reliably

### Align Local Branch

- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
- Run `gh pr checkout <pr-context.pr.number>` before inspecting local repository files for this PR review
- After checkout, store the active branch as `<active-branch>`
- If checkout fails, STOP and report that the PR branch could not be checked out locally
- Do not inspect local repository code for this PR until `<active-branch>` equals `<pr-branch>`
- If `<current-head>` equals `<pr-context.pr.headRefOid>`, store `<current-branch>` as `<active-branch>` when `<current-branch>` is available; otherwise store `<current-head>` as `<active-branch>`. Do not checkout because the worktree is already at the PR head commit.
- If `<current-head>` differs from `<pr-context.pr.headRefOid>`:
- Run `gh pr checkout <pr-context.pr.number>` before inspecting local repository files for this PR review
- After checkout, store the active branch as `<active-branch>`
- Run `git rev-parse HEAD` again and store the trimmed result as `<current-head>`
- If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks
- Do not inspect local repository code for this PR until `<current-head>` equals `<pr-context.pr.headRefOid>`

### Load Ticket Context

Expand Down
Loading