Skip to content

Commit fde3cd3

Browse files
committed
feat(code): persist PR URLs to backend
1 parent fea8dfe commit fde3cd3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

apps/code/src/renderer/features/git-interaction/hooks/useGitInteraction.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAuthenticatedClient } from "@features/auth/hooks/authClient";
12
import { useGitQueries } from "@features/git-interaction/hooks/useGitQueries";
23
import { computeGitInteractionState } from "@features/git-interaction/state/gitInteractionLogic";
34
import {
@@ -19,6 +20,7 @@ import { getSuggestedBranchName } from "@features/git-interaction/utils/getSugge
1920
import { invalidateGitBranchQueries } from "@features/git-interaction/utils/gitCacheKeys";
2021
import { partitionByStaged } from "@features/git-interaction/utils/partitionByStaged";
2122
import { updateGitCacheFromSnapshot } from "@features/git-interaction/utils/updateGitCache";
23+
import { useSessionStore } from "@features/sessions/stores/sessionStore";
2224
import { trpc, trpcClient } from "@renderer/trpc";
2325
import type { ChangedFile } from "@shared/types";
2426
import { ANALYTICS_EVENTS } from "@shared/types/analytics";
@@ -115,6 +117,21 @@ function trackGitAction(
115117
});
116118
}
117119

120+
function attachPrUrlToTask(taskId: string, prUrl: string) {
121+
const taskRunId = useSessionStore.getState().taskIdIndex[taskId];
122+
if (!taskRunId) return;
123+
124+
getAuthenticatedClient()
125+
.then((client) =>
126+
client?.updateTaskRun(taskId, taskRunId, {
127+
output: { pr_url: prUrl },
128+
}),
129+
)
130+
.catch((err) =>
131+
log.warn("Failed to attach PR URL to task", { taskId, prUrl, err }),
132+
);
133+
}
134+
118135
export function useGitInteraction(
119136
taskId: string,
120137
repoPath?: string,
@@ -255,6 +272,7 @@ export function useGitInteraction(
255272

256273
if (result.prUrl) {
257274
await trpcClient.os.openExternal.mutate({ url: result.prUrl });
275+
attachPrUrlToTask(taskId, result.prUrl);
258276
}
259277

260278
modal.closeCreatePr();

0 commit comments

Comments
 (0)