-
Notifications
You must be signed in to change notification settings - Fork 837
Fix folder workspace PR status icon from branch cache #7449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brennanb2025
merged 2 commits into
main
from
brennanb2025/fix-folder-pr-status-branch-cache
Jul 5, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/renderer/src/components/right-sidebar/parent-pr-checks-github-pr-cache.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type { HostedReviewInfo } from '../../../../shared/hosted-review' | ||
| import type { PRInfo, Repo, Worktree } from '../../../../shared/types' | ||
| import { | ||
| LOCAL_EXECUTION_HOST_ID, | ||
| normalizeExecutionHostId | ||
| } from '../../../../shared/execution-host' | ||
| import { isCachedMergedBranchPRCurrentForWorktree } from '@/components/sidebar/worktree-card-pr-display' | ||
| import type { AppState } from '@/store/types' | ||
| import { getGitHubPRCacheKey, getLegacyGitHubPRCacheKey } from '@/store/slices/github-cache-key' | ||
| import type { ParentPrChecksCacheEntry } from './parent-pr-checks-row-types' | ||
|
|
||
| export function canUseParentPrChecksGitHubPRCacheEntry( | ||
| worktree: Worktree, | ||
| prEntry: ParentPrChecksCacheEntry<PRInfo> | undefined, | ||
| hostedReviewEntry: ParentPrChecksCacheEntry<HostedReviewInfo> | undefined | ||
| ): prEntry is ParentPrChecksCacheEntry<PRInfo> & { | ||
| data: NonNullable<ParentPrChecksCacheEntry<PRInfo>['data']> | ||
| } { | ||
| const pr = prEntry?.data | ||
| if (!pr) { | ||
| return false | ||
| } | ||
| const prFetchedAt = prEntry.fetchedAt | ||
| const hasLinkedGitHubPR = worktree.linkedPR !== null | ||
| if (hasLinkedGitHubPR && pr.number !== worktree.linkedPR) { | ||
| return false | ||
| } | ||
| if (!hasLinkedGitHubPR && hasNonGitHubLinkedReview(worktree)) { | ||
| return false | ||
| } | ||
| const mergedPrMatchesCurrentHead = isCachedMergedBranchPRCurrentForWorktree(pr, worktree) | ||
| if (pr.state === 'merged' && !mergedPrMatchesCurrentHead) { | ||
| return false | ||
| } | ||
| // Why: a newer hosted-review miss should suppress older branch PR cache unless | ||
| // a merged PR is proven to still describe the checked-out worktree head. | ||
| if ( | ||
| hostedReviewEntry?.data === null && | ||
| !mergedPrMatchesCurrentHead && | ||
| prFetchedAt <= hostedReviewEntry.fetchedAt | ||
| ) { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| export function getParentPrChecksGitHubPRCacheEntry({ | ||
| prCache, | ||
| repo, | ||
| branch, | ||
| settings | ||
| }: { | ||
| prCache: Record<string, ParentPrChecksCacheEntry<PRInfo>> | ||
| repo: Repo | ||
| branch: string | ||
| settings: AppState['settings'] | ||
| }): ParentPrChecksCacheEntry<PRInfo> | undefined { | ||
| const currentKey = getGitHubPRCacheKey( | ||
| repo.path, | ||
| repo.id, | ||
| branch, | ||
| settings, | ||
| repo.connectionId, | ||
| repo.executionHostId, | ||
| true | ||
| ) | ||
| const executionHostId = normalizeExecutionHostId(repo.executionHostId) | ||
| const canUseLegacyPRCache = | ||
| !repo.connectionId && (!executionHostId || executionHostId === LOCAL_EXECUTION_HOST_ID) | ||
| const legacyRepoKey = canUseLegacyPRCache | ||
| ? getLegacyGitHubPRCacheKey(repo.path, repo.id, branch) | ||
| : '' | ||
| const legacyPathKey = canUseLegacyPRCache | ||
| ? getLegacyGitHubPRCacheKey(repo.path, undefined, branch) | ||
| : '' | ||
| return ( | ||
| prCache[currentKey] ?? | ||
| (legacyRepoKey ? prCache[legacyRepoKey] : undefined) ?? | ||
| (legacyPathKey ? prCache[legacyPathKey] : undefined) | ||
| ) | ||
| } | ||
|
|
||
| function hasNonGitHubLinkedReview(worktree: Worktree): boolean { | ||
| return ( | ||
| worktree.linkedGitLabMR != null || | ||
| worktree.linkedBitbucketPR != null || | ||
| worktree.linkedAzureDevOpsPR != null || | ||
| worktree.linkedGiteaPR != null | ||
| ) | ||
| } | ||
83 changes: 83 additions & 0 deletions
83
src/renderer/src/components/right-sidebar/parent-pr-checks-hosted-review-cache.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import type { HostedReviewInfo } from '../../../../shared/hosted-review' | ||
| import type { PRInfo, Worktree } from '../../../../shared/types' | ||
| import { | ||
| getWorktreeCardPrDisplay, | ||
| isCachedMergedBranchPRCurrentForWorktree | ||
| } from '@/components/sidebar/worktree-card-pr-display' | ||
| import type { ParentPrChecksCacheEntry } from './parent-pr-checks-row-types' | ||
|
|
||
| export function canUseParentPrChecksHostedReviewCacheEntry( | ||
| worktree: Worktree, | ||
| review: HostedReviewInfo, | ||
| entry: ParentPrChecksCacheEntry<HostedReviewInfo> | ||
| ): boolean { | ||
| if (review.state === 'merged' && !mergedReviewMatchesHead(review, worktree)) { | ||
| return false | ||
| } | ||
| const linkedReviewNumber = getLinkedReviewNumberForProvider(worktree, review.provider) | ||
| if (hasLinkedReview(worktree)) { | ||
| return linkedReviewNumber === review.number | ||
| } | ||
| if ((entry.linkedReviewHintKey ?? '') !== '') { | ||
| return false | ||
| } | ||
| const display = getWorktreeCardPrDisplay( | ||
| review, | ||
| worktree.linkedPR, | ||
| worktree.linkedGitLabMR ?? null, | ||
| worktree.linkedBitbucketPR ?? null, | ||
| worktree.linkedAzureDevOpsPR ?? null, | ||
| worktree.linkedGiteaPR ?? null, | ||
| { reviewHintKey: entry.linkedReviewHintKey } | ||
| ) | ||
| return display?.provider === review.provider && display.number === review.number | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| function mergedReviewMatchesHead(review: HostedReviewInfo, worktree: Worktree): boolean { | ||
| return isCachedMergedBranchPRCurrentForWorktree( | ||
| { | ||
| number: review.number, | ||
| title: review.title, | ||
| state: review.state, | ||
| url: review.url, | ||
| checksStatus: review.status, | ||
| updatedAt: review.updatedAt, | ||
| mergeable: review.mergeable, | ||
| ...(review.headSha ? { headSha: review.headSha } : {}), | ||
| ...(review.confirmedContainedHeadOid | ||
| ? { confirmedContainedHeadOid: review.confirmedContainedHeadOid } | ||
| : {}) | ||
| } satisfies PRInfo, | ||
| worktree | ||
| ) | ||
| } | ||
|
|
||
| function getLinkedReviewNumberForProvider( | ||
| worktree: Worktree, | ||
| provider: HostedReviewInfo['provider'] | ||
| ): number | null { | ||
| switch (provider) { | ||
| case 'github': | ||
| return worktree.linkedPR | ||
| case 'gitlab': | ||
| return worktree.linkedGitLabMR ?? null | ||
| case 'bitbucket': | ||
| return worktree.linkedBitbucketPR ?? null | ||
| case 'azure-devops': | ||
| return worktree.linkedAzureDevOpsPR ?? null | ||
| case 'gitea': | ||
| return worktree.linkedGiteaPR ?? null | ||
| case 'unsupported': | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| function hasLinkedReview(worktree: Worktree): boolean { | ||
| return ( | ||
| worktree.linkedPR != null || | ||
| worktree.linkedGitLabMR != null || | ||
| worktree.linkedBitbucketPR != null || | ||
| worktree.linkedAzureDevOpsPR != null || | ||
| worktree.linkedGiteaPR != null | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.