Skip to content

Commit adc0f52

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(pi): accept renamed update PR repositories
1 parent 217ea51 commit adc0f52

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

apps/sim/executor/handlers/pi/github-pr.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ describe('findOpenPrForBranch', () => {
145145
)
146146
})
147147

148+
it('accepts a renamed same-repository pull request by comparing head to base', async () => {
149+
mockExecuteTool.mockResolvedValueOnce(list([{ number: 7 }])).mockResolvedValueOnce({
150+
success: true,
151+
output: snapshot({
152+
head: {
153+
sha: HEAD_SHA,
154+
ref: 'feature/existing',
155+
repo_full_name: 'octo-renamed/demo',
156+
},
157+
base: { sha: BASE_SHA, ref: 'staging', repo_full_name: 'octo-renamed/demo' },
158+
}),
159+
})
160+
161+
await expect(findOpenPrForBranch(params)).resolves.toMatchObject({
162+
pullNumber: 7,
163+
snapshot: { headRepoFullName: 'octo-renamed/demo' },
164+
})
165+
})
166+
148167
it('returns no match so Update PR can create it, but fails when ambiguous', async () => {
149168
mockExecuteTool.mockResolvedValueOnce(list([]))
150169
await expect(findOpenPrForBranch(params)).resolves.toBeUndefined()

apps/sim/executor/handlers/pi/github-pr.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ export async function fetchOpenPrForBranch(
136136
signal?: AbortSignal
137137
): Promise<BranchPullRequest> {
138138
const snapshot = await fetchOpenPrSnapshot(params, signal)
139-
const expectedRepo = `${params.owner}/${params.repo}`.toLowerCase()
140139
if (
141140
snapshot.headRef !== params.branch ||
142-
snapshot.headRepoFullName?.toLowerCase() !== expectedRepo
141+
!snapshot.headRepoFullName ||
142+
!snapshot.baseRepoFullName ||
143+
snapshot.headRepoFullName.toLowerCase() !== snapshot.baseRepoFullName.toLowerCase()
143144
) {
144145
throw new Error(
145146
`PR #${params.pullNumber} no longer points to ${params.owner}/${params.repo}:${params.branch}`

0 commit comments

Comments
 (0)