Use GitHub merge method metadata for PR actions
This commit is contained in:
@@ -305,6 +305,69 @@ describe('getPRForBranch', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('hydrates repository merge method settings for exact PR lookups', async () => {
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })
|
||||
ghExecFileAsyncMock
|
||||
.mockResolvedValueOnce({
|
||||
stdout: JSON.stringify({
|
||||
number: 99,
|
||||
title: 'Linked PR',
|
||||
state: 'OPEN',
|
||||
url: 'https://github.com/acme/widgets/pull/99',
|
||||
statusCheckRollup: [],
|
||||
updatedAt: '2026-03-28T00:00:00Z',
|
||||
isDraft: false,
|
||||
mergeable: 'MERGEABLE',
|
||||
reviewDecision: 'APPROVED',
|
||||
mergeStateStatus: 'CLEAN',
|
||||
autoMergeRequest: null,
|
||||
baseRefName: 'main',
|
||||
headRefName: 'someone/fix',
|
||||
baseRefOid: 'base-oid',
|
||||
headRefOid: 'linked-head-oid'
|
||||
})
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
stdout: JSON.stringify({
|
||||
data: {
|
||||
repository: {
|
||||
viewerDefaultMergeMethod: 'REBASE',
|
||||
mergeCommitAllowed: false,
|
||||
rebaseMergeAllowed: true,
|
||||
squashMergeAllowed: true,
|
||||
mergeQueue: null
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const pr = await getPRForBranch('/repo-root', 'feature/local-worktree', 99)
|
||||
|
||||
expect(pr?.mergeMethodSettings).toEqual({
|
||||
defaultMethod: 'rebase',
|
||||
allowedMethods: {
|
||||
squash: true,
|
||||
merge: false,
|
||||
rebase: true
|
||||
}
|
||||
})
|
||||
expect(pr?.mergeQueueRequired).toBe(false)
|
||||
expect(ghExecFileAsyncMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.arrayContaining([
|
||||
'api',
|
||||
'graphql',
|
||||
'-f',
|
||||
'owner=acme',
|
||||
'-f',
|
||||
'repo=widgets',
|
||||
'-f',
|
||||
'branch=main'
|
||||
]),
|
||||
{ cwd: '/repo-root' }
|
||||
)
|
||||
})
|
||||
|
||||
it('treats linked PR metadata as authoritative even when the branch head differs', async () => {
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })
|
||||
gitExecFileAsyncMock.mockResolvedValueOnce({ stdout: 'current-worktree-head\n', stderr: '' })
|
||||
|
||||
Reference in New Issue
Block a user