feat: link pull requests to threads #8160
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/8160/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/ChatMarkdown.tsx line 1837Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -1760,3 +1818,14 @@17601818 event.stopPropagation();17611819 const api = readLocalApi();17621820 if (!api) return;1821+ const pullRequest = resolveThreadPullRequest(href);1822+ const currentPullRequest =1823+ threadRef === undefined ? null : readThreadShell(threadRef)?.linkedPullRequest;1824+ const threadLinkAction =1825+ pullRequest === null1826+ ? undefined1827+ : currentPullRequest?.projectId === pullRequest.projectId &&1828+ currentPullRequest.repository === pullRequest.repository &&1829+ currentPullRequest.number === pullRequest.number1830+ ? "unlink-from-thread"1831+ : "link-to-thread";apps/mobile/src/state/use-thread-pr.ts line 60Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -31,0 +40,21 @@40+ thread.linkedPullRequest == null41+ ? null42+ : linkedPullRequestDetailAtom({43+ environmentId: thread.environmentId,44+ input: {45+ projectId: thread.linkedPullRequest.projectId,46+ repository: thread.linkedPullRequest.repository,47+ number: thread.linkedPullRequest.number,48+ },49+ }),50+ );51+52+ if (thread.linkedPullRequest != null) {53+ const detail = linkedPullRequest.data;54+ return detail === null55+ ? null56+ : presentThreadPr(pullRequestDetailToVcsStatus(detail), {57+ kind: detail.provider,58+ name: detail.provider,59+ baseUrl: new URL(detail.url).origin,60+ });
- apps/web/src/components/ChatView.tsx line 3428OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3422,4 +3425,4 @@34223425 return;34233426 }34243427 useRightPanelStore.getState().openPullRequest(activeThreadRef, {3425- projectId: activeProject.id,3428+ projectId: linkedThreadPullRequest?.projectId ?? activeProject.id,docs/user/thread-sidebar.md lines 11 to 11OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -7,3 +7,5 @@77 Pinned threads still move to **Settled** when they become inactive. They also move when their pull88 request merges if **Auto-settle merged threads** is enabled.9910+Right-click a pull request link in a thread and choose **Link to thread** to show that pull request11+in the sidebar. The thread settles when the linked pull request merges. Right-click the same linkapps/mobile/src/state/use-thread-pr.ts line 59OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -31,0 +39,21 @@39+ const linkedPullRequest = useEnvironmentQuery(40+ thread.linkedPullRequest == null41+ ? null42+ : linkedPullRequestDetailAtom({43+ environmentId: thread.environmentId,44+ input: {45+ projectId: thread.linkedPullRequest.projectId,46+ repository: thread.linkedPullRequest.repository,47+ number: thread.linkedPullRequest.number,48+ },49+ }),50+ );51+52+ if (thread.linkedPullRequest != null) {53+ const detail = linkedPullRequest.data;54+ return detail === null55+ ? null56+ : presentThreadPr(pullRequestDetailToVcsStatus(detail), {57+ kind: detail.provider,58+ name: detail.provider,59+ baseUrl: new URL(detail.url).origin,apps/web/src/components/LegacySidebar.tsx line 466Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -457,8 +458,9 @@457458 lastVisitedAt,458459 },459460 });460- const pr = resolveThreadPr({461- threadBranch: thread.branch,462- gitStatus: gitStatus.data,463- });464- const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);461+ const linkedPullRequestStatus = useLinkedThreadPullRequest(462+ thread.environmentId,463+ thread.linkedPullRequest,464+ );465+ const pr =466+ thread.linkedPullRequest == nullapps/web/src/components/ChatMarkdown.tsx lines 1576 to 1589Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1530,0 +1562,21 @@1562+ if (project === undefined) return null;1563+ return {1564+ projectId: project.id,1565+ repository: project.repositoryIdentity?.displayName ?? parsed.repository,1566+ number: parsed.number,1567+ url: href,1568+ };1569+ },1570+ [projects, threadRef, threadServerConfig],1571+ );1572+ const updateThreadPullRequestLink = useCallback(1573+ async (href: string, linked: boolean) => {1574+ if (threadRef === undefined) return;1575+ const linkedPullRequest = linked ? resolveThreadPullRequest(href) : null;1576+ if (linked && linkedPullRequest === null) {1577+ throw new Error("The pull request is not available in this environment.");1578+ }1579+ const result = await updateThreadMetadata({1580+ environmentId: threadRef.environmentId,1581+ input: { threadId: threadRef.threadId, linkedPullRequest },1582+ });
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/mobile/src/features/threads/thread-list-v2-items.tsx line 416OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -411,8 +412,5 @@411412 const prUpdatedAt = pr?.updatedAt ?? null;412413 const threadKey = `${thread.environmentId}:${thread.id}`;413414 useEffect(() => {414- onChangeRequestState?.(415- threadKey,416- prState === null ? null : { state: prState, updatedAt: prUpdatedAt },417- );418- }, [onChangeRequestState, prState, prUpdatedAt, threadKey]);415+ const changeRequest = resolveThreadListV2ChangeRequestState({416+ hasLinkedPullRequest: thread.linkedPullRequest != null,
- apps/mobile/src/features/threads/threadListV2.ts line 60Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -30,3 +30,12 @@3030 export type ThreadListV2Status = "approval" | "input" | "working" | "failed" | "ready";3131 export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze";323233+/** Keep the previous linked PR state while its detail query reloads. */34+export function resolveThreadListV2ChangeRequestState(input: {35+ readonly hasLinkedPullRequest: boolean;36+ readonly state: ChangeRequestSettleSource["state"] | null;37+ readonly updatedAt: string | null;38+}): ChangeRequestSettleSource | null | undefined {39+ if (input.state === null) return input.hasLinkedPullRequest ? undefined : null;40+ return { state: input.state, updatedAt: input.updatedAt };41+}
- apps/web/src/components/ChatMarkdown.tsx lines 1576 to 1578Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1530,0 +1558,21 @@1558+ if (parsed === null) return null;1559+ const project = findProjectForChangeRequest(1560+ projects.filter((candidate) => candidate.environmentId === threadRef.environmentId),1561+ parsed,1562+ );1563+ if (project === undefined) return null;1564+ return {1565+ projectId: project.id,1566+ repository: project.repositoryIdentity?.displayName ?? parsed.repository,1567+ number: parsed.number,1568+ url: href,1569+ };1570+ },1571+ [projects, threadRef, threadServerConfig],1572+ );1573+ const updateThreadPullRequestLink = useCallback(1574+ async (href: string, linked: boolean) => {1575+ if (threadRef === undefined) return;1576+ const linkedPullRequest = linked ? resolveThreadPullRequest(href) : null;1577+ if (linked && linkedPullRequest === null) {1578+ throw new Error("The pull request is not available in this environment.");
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
81a60287-bca5-40a4-8091-1f7a998a9f43You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share