fix: reopen pull requests with gh pr (#3980)

This commit is contained in:
Jinjing 2026-05-30 21:14:08 -07:00 committed by GitHub
parent 761b56508b
commit 1d9aefe021
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 9 deletions

View File

@ -98,6 +98,7 @@ import {
mergePR,
resolveReviewThread,
setPRAutoMerge,
updatePRState,
updatePRTitle,
_resetOwnerRepoCache,
_resetMergeQueueCacheForTests
@ -1278,6 +1279,65 @@ describe('getPRForBranch', () => {
})
})
describe('updatePRState', () => {
beforeEach(() => {
ghExecFileAsyncMock.mockReset()
getOwnerRepoMock.mockReset()
ghRepoExecOptionsMock.mockClear()
githubRepoContextMock.mockClear()
acquireMock.mockReset()
releaseMock.mockReset()
acquireMock.mockResolvedValue(undefined)
_resetOwnerRepoCache()
})
it('reopens pull requests through the gh PR command', async () => {
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
ghExecFileAsyncMock.mockResolvedValueOnce({ stdout: '', stderr: '' })
await expect(updatePRState('/repo-root', 3977, { state: 'open' })).resolves.toEqual({
ok: true
})
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['pr', 'reopen', '3977', '--repo', 'stablyai/orca'],
{ cwd: '/repo-root' }
)
expect(acquireMock).toHaveBeenCalledTimes(1)
expect(releaseMock).toHaveBeenCalledTimes(1)
})
it('closes pull requests through the gh PR command', async () => {
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
ghExecFileAsyncMock.mockResolvedValueOnce({ stdout: '', stderr: '' })
await expect(updatePRState('/repo-root', 3977, { state: 'closed' })).resolves.toEqual({
ok: true
})
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['pr', 'close', '3977', '--repo', 'stablyai/orca'],
{ cwd: '/repo-root' }
)
})
it('reopens SSH-backed pull requests without local cwd options', async () => {
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
ghExecFileAsyncMock.mockResolvedValueOnce({ stdout: '', stderr: '' })
await expect(
updatePRState('/remote/repo-root', 3977, { state: 'open' }, 'ssh-1')
).resolves.toEqual({
ok: true
})
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['pr', 'reopen', '3977', '--repo', 'stablyai/orca'],
{}
)
})
})
describe('GitHub GraphQL rate-limit guard', () => {
beforeEach(() => {
execFileAsyncMock.mockReset()

View File

@ -3254,16 +3254,14 @@ export async function updatePRState(
await acquire()
try {
const cmd = updates.state === 'closed' ? 'close' : 'reopen'
// Why: GitHub can reject REST pull state PATCHes for reopen paths with a
// generic 422; gh's PR commands use GitHub's supported reopen flow.
await ghExecFileAsync(
[
'api',
'-X',
'PATCH',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}`,
'--raw-field',
`state=${updates.state}`
],
ghOptions
['pr', cmd, String(prNumber), '--repo', `${ownerRepo.owner}/${ownerRepo.repo}`],
{
...ghOptions
}
)
return { ok: true }
} catch (err) {