diff --git a/addons/isl/src/Commit.tsx b/addons/isl/src/Commit.tsx index be439c140ed63..2f1902de05c1a 100644 --- a/addons/isl/src/Commit.tsx +++ b/addons/isl/src/Commit.tsx @@ -9,7 +9,7 @@ import type {JSX, ReactNode} from 'react'; import type {ContextMenuItem} from 'shared/ContextMenu'; import type {UICodeReviewProvider} from './codeReview/UICodeReviewProvider'; import type {DagCommitInfo} from './dag/dag'; -import type {CommitInfo, MergeConflicts, SuccessorInfo, WorktreeEntry} from './types'; +import type {CommitInfo, DiffId, MergeConflicts, SuccessorInfo, WorktreeEntry} from './types'; import {succeedableRevset, WarningCheckResult} from './types'; import {Button} from 'isl-components/Button'; @@ -48,6 +48,7 @@ import { allDiffSummaries, branchingDiffInfos, codeReviewProvider, + diffIdsByBranchName, diffSummary, latestCommitTitles, } from './codeReview/CodeReviewInfo'; @@ -762,7 +763,9 @@ export const Commit = memo( )} - {!isPublic && } + {!isPublic && ( + + )} }) { +function BranchingPrs({bookmarks, diffId}: {bookmarks: ReadonlyArray; diffId?: DiffId}) { const provider = useAtomValue(codeReviewProvider); if (provider == null || !provider.supportBranchingPrs) { // If we don't have a provider, just render them as bookmarks so they don't get hidden. return ; } return bookmarks.map(bookmark => ( - + )); } -function BranchingPr({bookmark, provider}: {bookmark: string; provider: UICodeReviewProvider}) { +function BranchingPr({ + bookmark, + provider, + diffId, +}: { + bookmark: string; + provider: UICodeReviewProvider; + diffId?: DiffId; +}) { const branchName = nullthrows(provider.branchNameForRemoteBookmark)(bookmark); const info = useAtomValue(branchingDiffInfos(branchName)); + // `sl pr submit` pushes each commit to its PR's head branch, so that bookmark resolves to the + // commit's own PR, whose badge `DiffInfo` already shows. + const branchDiffId = useAtomValue(diffIdsByBranchName).get(branchName); + const isOwnPr = diffId != null && branchDiffId === diffId; return ( <> {bookmark} - {info.value == null ? null : ( + {info.value == null || isOwnPr ? null : ( )} diff --git a/addons/isl/src/__tests__/GitHubPRBadge.test.tsx b/addons/isl/src/__tests__/GitHubPRBadge.test.tsx index 56eb939942911..112be5d9d1586 100644 --- a/addons/isl/src/__tests__/GitHubPRBadge.test.tsx +++ b/addons/isl/src/__tests__/GitHubPRBadge.test.tsx @@ -249,6 +249,72 @@ describe('GitHubPRBadge', () => { }); }); + describe('commit on its own PR branch', () => { + beforeEach(() => { + act(() => { + simulateCommits({ + value: [ + COMMIT('1', 'some public base', '0', {phase: 'public'}), + COMMIT('a', 'Commit A', '1', { + isDot: true, + diffId: '10', + remoteBookmarks: ['origin/pr10', 'origin/feature'], + }), + ], + }); + simulateMessageFromServer({ + type: 'fetchedDiffSummaries', + summaries: { + value: new Map([ + [ + '10', + { + number: '10', + state: PullRequestState.Open, + title: 'PR A', + type: 'github', + url: 'https://github.com/myusername/testrepo/pull/10', + anyUnresolvedComments: false, + commentCount: 0, + commitMessage: 'PR A', + base: '1', + head: 'a', + branchName: 'pr10', + }, + ], + [ + '12', + { + number: '12', + state: PullRequestState.Closed, + title: 'Feature PR', + type: 'github', + url: 'https://github.com/myusername/testrepo/pull/12', + anyUnresolvedComments: false, + commentCount: 0, + commitMessage: 'Feature PR', + base: '1', + head: 'a', + branchName: 'feature', + }, + ], + ]), + }, + }); + }); + }); + + it('renders its own PR badge once', () => { + const commitA = screen.getByTestId('commit-a'); + expect(within(commitA).getByText('origin/pr10')).toBeInTheDocument(); + expect(within(commitA).queryAllByText('Open')).toHaveLength(1); + }); + + it('still renders badges for other PR branches', () => { + expect(within(screen.getByTestId('commit-a')).queryAllByText('Closed')).toHaveLength(1); + }); + }); + describe('after error', () => { suppressReactErrorBoundaryErrorMessages();