Keep PR refreshes anchored to cached review numbers (#2541)
- Use fallback PR numbers after branch lookup misses, including detached HEAD - Preserve review cards for forked or deleted-head PRs across manual refreshes - Clear stale GitHub PR cache entries when unlinking worktree review metadata
This commit is contained in:
@@ -242,6 +242,7 @@ export async function getHostedReviewCreationEligibility(
|
||||
repoPath: args.repoPath,
|
||||
branch,
|
||||
linkedGitHubPR: args.linkedGitHubPR ?? null,
|
||||
fallbackGitHubPR: args.linkedGitHubPR == null ? (args.fallbackGitHubPR ?? null) : null,
|
||||
linkedGitLabMR: args.linkedGitLabMR ?? null,
|
||||
linkedBitbucketPR: args.linkedBitbucketPR ?? null,
|
||||
linkedAzureDevOpsPR: args.linkedAzureDevOpsPR ?? null,
|
||||
|
||||
@@ -123,6 +123,33 @@ describe('getHostedReviewForBranch', () => {
|
||||
expect(getPRForBranchMock).toHaveBeenCalledWith('/repo', 'feature', 3, undefined)
|
||||
})
|
||||
|
||||
it('uses fallback GitHub PR when branch is empty', async () => {
|
||||
getProjectSlugMock.mockResolvedValue(null)
|
||||
getRepoSlugMock.mockResolvedValue({ owner: 'o', repo: 'r' })
|
||||
getPRForBranchMock.mockResolvedValue({
|
||||
number: 42,
|
||||
title: 'Detached GitHub branch',
|
||||
state: 'open',
|
||||
url: 'https://github.com/o/r/pull/42',
|
||||
checksStatus: 'success',
|
||||
updatedAt: '2026-05-10T00:00:00.000Z',
|
||||
mergeable: 'MERGEABLE'
|
||||
})
|
||||
|
||||
await expect(
|
||||
getHostedReviewForBranch({
|
||||
repoPath: '/repo',
|
||||
branch: '',
|
||||
fallbackGitHubPR: 42
|
||||
})
|
||||
).resolves.toMatchObject({
|
||||
provider: 'github',
|
||||
number: 42,
|
||||
status: 'success'
|
||||
})
|
||||
expect(getPRForBranchMock).toHaveBeenCalledWith('/repo', '', null, undefined, 42)
|
||||
})
|
||||
|
||||
it('falls through to Bitbucket when origin is not GitLab or GitHub', async () => {
|
||||
getProjectSlugMock.mockResolvedValue(null)
|
||||
getRepoSlugMock.mockResolvedValue(null)
|
||||
|
||||
@@ -95,15 +95,19 @@ export async function getHostedReviewForBranch(input: {
|
||||
connectionId?: string | null
|
||||
branch: string
|
||||
linkedGitHubPR?: number | null
|
||||
fallbackGitHubPR?: number | null
|
||||
linkedGitLabMR?: number | null
|
||||
linkedBitbucketPR?: number | null
|
||||
linkedAzureDevOpsPR?: number | null
|
||||
linkedGiteaPR?: number | null
|
||||
}): Promise<HostedReviewInfo | null> {
|
||||
const branchName = input.branch.replace(/^refs\/heads\//, '')
|
||||
// Why: detached HEAD cannot use branch lookup, but provider-specific exact
|
||||
// ids can still resolve the review without probing an empty branch name.
|
||||
if (
|
||||
!branchName &&
|
||||
input.linkedGitHubPR == null &&
|
||||
input.fallbackGitHubPR == null &&
|
||||
input.linkedGitLabMR == null &&
|
||||
input.linkedBitbucketPR == null &&
|
||||
input.linkedAzureDevOpsPR == null &&
|
||||
@@ -125,12 +129,22 @@ export async function getHostedReviewForBranch(input: {
|
||||
|
||||
const githubRepo = await getRepoSlug(input.repoPath, input.connectionId)
|
||||
if (githubRepo) {
|
||||
const pr = await getPRForBranch(
|
||||
input.repoPath,
|
||||
branchName,
|
||||
input.linkedGitHubPR ?? null,
|
||||
input.connectionId
|
||||
)
|
||||
const fallbackGitHubPR = input.linkedGitHubPR == null ? (input.fallbackGitHubPR ?? null) : null
|
||||
const pr =
|
||||
fallbackGitHubPR !== null
|
||||
? await getPRForBranch(
|
||||
input.repoPath,
|
||||
branchName,
|
||||
input.linkedGitHubPR ?? null,
|
||||
input.connectionId,
|
||||
fallbackGitHubPR
|
||||
)
|
||||
: await getPRForBranch(
|
||||
input.repoPath,
|
||||
branchName,
|
||||
input.linkedGitHubPR ?? null,
|
||||
input.connectionId
|
||||
)
|
||||
return pr ? mapGitHubReview(pr) : null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user