feat(pull-requests): link a PR to its thread from the PR action menu #8488
Closedmfattakhov(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/8488/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 1419OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1350,3 +1413,7 @@13501413 <HammerIcon className="size-3.5" />13511414 {handoff === "findings" ? "Preparing..." : handoffLabels.fixFindings}13521415 </MenuItem>1416+ {/* Pinning from the pull-request side: where the panel sits beside a thread,1417+ that thread is one press away from following this pull request's state.1418+ Unlink takes the item's place once this is the linked one. */}1419+ {attachThreadRef !== null && detail !== null ? (apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 734OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -709,3 +716,19 @@709716 const attachTarget = pullRequestComposerTarget(context, composerDraftTarget);710717 const handoffLabels = pullRequestHandoffLabels(attachTarget !== null);711718719+ // Linking from the pull-request side needs a real thread to pin, and that is720+ // the open thread — not the handoff attach target. Gating on thread context721+ // would strand the reader: once they unlink, the thread stops matching this722+ // pull request by branch, the panel falls back to page context, and the way723+ // back would vanish with it.724+ const attachThreadRef =725+ composerDraftTarget !== undefined &&726+ composerDraftTarget !== null &&727+ typeof composerDraftTarget !== "string"728+ ? composerDraftTarget729+ : null;730+ const attachThread = useThreadShell(attachThreadRef);731+ const { linkPullRequest, unlinkPullRequest } = useThreadPullRequestLinkActions();732+ const threadLinkedPullRequest = attachThread?.linkedPullRequest ?? null;733+ const isLinkedToThisPullRequest =734+ threadLinkedPullRequest !== null &&
- apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx lines 733 to 737OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -710,2 +717,21 @@710717 const handoffLabels = pullRequestHandoffLabels(attachTarget !== null);711718719+ // Linking from the pull-request side needs a real thread to pin, and that is720+ // the open thread — not the handoff attach target. Gating on thread context721+ // would strand the reader: once they unlink, the thread stops matching this722+ // pull request by branch, the panel falls back to page context, and the way723+ // back would vanish with it.724+ const attachThreadRef =725+ composerDraftTarget !== undefined &&726+ composerDraftTarget !== null &&727+ typeof composerDraftTarget !== "string"728+ ? composerDraftTarget729+ : null;730+ const attachThread = useThreadShell(attachThreadRef);731+ const { linkPullRequest, unlinkPullRequest } = useThreadPullRequestLinkActions();732+ const threadLinkedPullRequest = attachThread?.linkedPullRequest ?? null;733+ const isLinkedToThisPullRequest =734+ threadLinkedPullRequest !== null &&735+ detail !== null &&736+ threadLinkedPullRequest.number === detail.number &&737+ threadLinkedPullRequest.url === detail.url;apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx lines 1419 to 1431OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1350,3 +1413,19 @@13501413 <HammerIcon className="size-3.5" />13511414 {handoff === "findings" ? "Preparing..." : handoffLabels.fixFindings}13521415 </MenuItem>1416+ {/* Pinning from the pull-request side: where the panel sits beside a thread,1417+ that thread is one press away from following this pull request's state.1418+ Unlink takes the item's place once this is the linked one. */}1419+ {attachThreadRef !== null && detail !== null ? (1420+ isLinkedToThisPullRequest ? (1421+ <MenuItem onClick={unlinkPullRequestFromThread}>1422+ <UnlinkIcon className="size-3.5" />1423+ Unlink PR from this thread1424+ </MenuItem>1425+ ) : (1426+ <MenuItem onClick={linkPullRequestToThread}>1427+ <Link2Icon className="size-3.5" />1428+ Link PR to this thread1429+ </MenuItem>1430+ )1431+ ) : null}
- apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 1479Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1350,3 +1413,19 @@13501413 <HammerIcon className="size-3.5" />13511414 {handoff === "findings" ? "Preparing..." : handoffLabels.fixFindings}13521415 </MenuItem>1416+ {/* Pinning from the pull-request side: where the panel sits beside a thread,1417+ that thread is one press away from following this pull request's state.1418+ Unlink takes the item's place once this is the linked one. */}1419+ {attachThreadRef !== null && detail !== null ? (1420+ isLinkedToThisPullRequest ? (1421+ <MenuItem onClick={unlinkPullRequestFromThread}>1422+ <UnlinkIcon className="size-3.5" />1423+ Unlink PR from this thread1424+ </MenuItem>1425+ ) : (1426+ <MenuItem onClick={linkPullRequestToThread}>1427+ <Link2Icon className="size-3.5" />1428+ Link PR to this thread1429+ </MenuItem>1430+ )1431+ ) : null}apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 737OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -710,2 +717,21 @@710717 const handoffLabels = pullRequestHandoffLabels(attachTarget !== null);711718719+ // Linking from the pull-request side needs a real thread to pin, and that is720+ // the open thread — not the handoff attach target. Gating on thread context721+ // would strand the reader: once they unlink, the thread stops matching this722+ // pull request by branch, the panel falls back to page context, and the way723+ // back would vanish with it.724+ const attachThreadRef =725+ composerDraftTarget !== undefined &&726+ composerDraftTarget !== null &&727+ typeof composerDraftTarget !== "string"728+ ? composerDraftTarget729+ : null;730+ const attachThread = useThreadShell(attachThreadRef);731+ const { linkPullRequest, unlinkPullRequest } = useThreadPullRequestLinkActions();732+ const threadLinkedPullRequest = attachThread?.linkedPullRequest ?? null;733+ const isLinkedToThisPullRequest =734+ threadLinkedPullRequest !== null &&735+ detail !== null &&736+ threadLinkedPullRequest.number === detail.number &&737+ threadLinkedPullRequest.url === detail.url;
- apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 797Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -711,0 +754,21 @@754+ number: detail.number,755+ url: detail.url,756+ };757+ void linkPullRequest(attachThreadRef, link).then((result) => {758+ if (result._tag === "Failure") {759+ if (!isAtomCommandInterrupted(result)) {760+ toastManager.add({ type: "error", title: "Could not link the pull request" });761+ }762+ return;763+ }764+ toastManager.add({765+ type: "success",766+ title: "Linked to this thread",767+ description: `#${detail.number} now drives this thread's badge and settle-on-merge.`,768+ });769+ });770+ };771+772+ const unlinkPullRequestFromThread = () => {773+ if (attachThreadRef === null) return;774+ void unlinkPullRequest(attachThreadRef).then((result) => {
- apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 739OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -711,0 +719,21 @@719+ // Linking from the pull-request side needs a real thread to pin, and that is720+ // the open thread — not the handoff attach target. Gating on thread context721+ // would strand the reader: once they unlink, the thread stops matching this722+ // pull request by branch, the panel falls back to page context, and the way723+ // back would vanish with it.724+ const attachThreadRef =725+ composerDraftTarget !== undefined &&726+ composerDraftTarget !== null &&727+ typeof composerDraftTarget !== "string"728+ ? composerDraftTarget729+ : null;730+ const attachThread = useThreadShell(attachThreadRef);731+ const { linkPullRequest, unlinkPullRequest } = useThreadPullRequestLinkActions();732+ const threadLinkedPullRequest = attachThread?.linkedPullRequest ?? null;733+ // The stored link keeps whatever URL it was created from, which for an734+ // agent-written href is often a subpage. Same match the thread side uses, so735+ // an already-linked pull request offers Unlink rather than a second Link.736+ const isLinkedToThisPullRequest =737+ threadLinkedPullRequest !== null &&738+ detail !== null &&739+ matchesLinkedPullRequestUrl(threadLinkedPullRequest, detail.url);
- apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 1478Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1356,3 +1442,21 @@13561442 <HammerIcon className="size-3.5" />13571443 {handoff === "findings" ? "Preparing..." : handoffLabels.fixFindings}13581444 </MenuItem>1445+ {/* Pinning from the pull-request side: where the panel sits beside a thread,1446+ that thread is one press away from following this pull request's state.1447+ Unlink takes the item's place once this is the linked one. */}1448+ {attachThreadRef !== null && detail !== null && supportsPullRequestLink ? (1449+ isLinkedToThisPullRequest ? (1450+ <MenuItem1451+ disabled={pullRequestLinkPending}1452+ onClick={unlinkPullRequestFromThread}1453+ >1454+ <UnlinkIcon className="size-3.5" />1455+ {pullRequestLinkPending ? "Unlinking..." : "Unlink PR from this thread"}1456+ </MenuItem>1457+ ) : (1458+ <MenuItem disabled={pullRequestLinkPending} onClick={linkPullRequestToThread}>1459+ <Link2Icon className="size-3.5" />1460+ {pullRequestLinkPending ? "Linking..." : "Link PR to this thread"}1461+ </MenuItem>1462+ )
juliusmarminge 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:
91c91b7e-4b9d-4814-8d90-e89940008e25You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.