Skip to content

Commit 10fda29

Browse files
committed
fix(pr): refresh before create, validate base branch, fence comment bodies
- Refresh VCS state before idempotency check in create() to avoid TOCTOU race (anomalyco#4, anomalyco#12) - Use refreshed branch/defaultBranch in fallback PR return (anomalyco#9) - Validate base branch exists before attempting gh pr create (anomalyco#22) - Wrap review comment bodies in fenced blocks for structural separation (anomalyco#8)
1 parent dc594de commit 10fda29

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

packages/app/src/components/dialog-address-comments.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function AddressCommentsDialog() {
9797
if (thread.comments.length === 0) continue
9898
text += `### File: ${thread.path}${thread.line ? ` (line ${thread.line})` : ""}\n`
9999
for (const comment of thread.comments) {
100-
text += `**@${comment.author}** (comment ID: ${comment.id}): ${comment.body}\n`
100+
text += `**@${comment.author}** (comment ID: ${comment.id}):\n\`\`\`\n${comment.body}\n\`\`\`\n`
101101
}
102102
text += "\n"
103103
}

packages/opencode/src/project/pr.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export namespace PR {
204204
}
205205

206206
export async function create(input: CreateInput): Promise<Vcs.PrInfo> {
207+
await Vcs.refresh()
207208
const { info } = await ensureGithub()
208209
const cwd = Instance.worktree
209210

@@ -219,6 +220,13 @@ export namespace PR {
219220
throw new PrError({ code: "CREATE_FAILED", message: sanitizeOutput(errorOutput) })
220221
}
221222

223+
if (input.base) {
224+
const branches = info.branches ?? (await Vcs.fetchBranches())
225+
if (!branches.includes(input.base)) {
226+
throw new PrError({ code: "CREATE_FAILED", message: `Base branch '${input.base}' does not exist` })
227+
}
228+
}
229+
222230
const args = ["gh", "pr", "create", "--title", input.title]
223231
args.push("--body", input.body)
224232
if (input.base) args.push("--base", input.base)
@@ -257,8 +265,8 @@ export namespace PR {
257265
url: prUrl,
258266
title: input.title,
259267
state: "OPEN",
260-
headRefName: info.branch,
261-
baseRefName: input.base ?? info.defaultBranch ?? "main",
268+
headRefName: updated.branch || info.branch,
269+
baseRefName: input.base ?? updated.defaultBranch ?? info.defaultBranch ?? "main",
262270
isDraft: input.draft ?? false,
263271
mergeable: "UNKNOWN",
264272
reviewDecision: null,

0 commit comments

Comments
 (0)