-
Notifications
You must be signed in to change notification settings - Fork 16
fix(code): cloud repo picker fetches when only team GitHub integration exists #1989
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
Closed
Closed
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions
37
apps/code/src/renderer/features/task-detail/components/CloudRepoFallbackNotice.tsx
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,37 @@ | ||
| import { useConnectUserGithub } from "@hooks/useConnectUserGithub"; | ||
| import { ArrowSquareOut, Info } from "@phosphor-icons/react"; | ||
| import { Button, Callout, Flex, Spinner, Text } from "@radix-ui/themes"; | ||
|
|
||
| export function CloudRepoFallbackNotice() { | ||
| const { connect, isConnecting, canConnect } = useConnectUserGithub(); | ||
|
|
||
| return ( | ||
| <Callout.Root color="amber" variant="soft" size="1"> | ||
| <Flex align="center" gap="2" justify="between" wrap="wrap"> | ||
| <Flex align="start" gap="2" className="min-w-0 flex-1"> | ||
| <Callout.Icon> | ||
| <Info size={14} /> | ||
| </Callout.Icon> | ||
| <Callout.Text> | ||
| <Text size="1"> | ||
| Using your team's GitHub integration. Link your personal GitHub so | ||
| cloud PRs are authored as you. | ||
| </Text> | ||
| </Callout.Text> | ||
| </Flex> | ||
| <Button | ||
| size="1" | ||
| variant="soft" | ||
| color="amber" | ||
| disabled={!canConnect || isConnecting} | ||
| onClick={() => { | ||
| void connect(); | ||
| }} | ||
| > | ||
| {isConnecting ? <Spinner size="1" /> : <ArrowSquareOut size={12} />} | ||
| {isConnecting ? "Waiting…" : "Connect GitHub"} | ||
| </Button> | ||
| </Flex> | ||
| </Callout.Root> | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { useOptionalAuthenticatedClient } from "@features/auth/hooks/authClient"; | ||
| import { useAuthStateValue } from "@features/auth/hooks/authQueries"; | ||
| import { trpcClient } from "@renderer/trpc/client"; | ||
| import { toast } from "@renderer/utils/toast"; | ||
| import { useQueryClient } from "@tanstack/react-query"; | ||
| import { useCallback, useEffect, useRef, useState } from "react"; | ||
|
|
||
| interface UseConnectUserGithubResult { | ||
| connect: () => Promise<void>; | ||
| isConnecting: boolean; | ||
| canConnect: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Starts the GitHub user-integration install flow and refreshes the relevant | ||
| * query caches once the user returns to the window. Shared between the inbox | ||
| * banner and the cloud-task fallback notice; onboarding has its own polling | ||
| * state machine and uses the underlying API directly. | ||
| */ | ||
| export function useConnectUserGithub(): UseConnectUserGithubResult { | ||
| const apiClient = useOptionalAuthenticatedClient(); | ||
| const projectId = useAuthStateValue((s) => s.projectId); | ||
| const cloudRegion = useAuthStateValue((s) => s.cloudRegion); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const [isConnecting, setIsConnecting] = useState(false); | ||
| const awaitingLink = useRef(false); | ||
| const inFlight = useRef(false); | ||
|
|
||
| const canConnect = | ||
| apiClient != null && projectId != null && cloudRegion != null; | ||
|
|
||
| useEffect(() => { | ||
| const onFocus = () => { | ||
| if (!awaitingLink.current) return; | ||
| awaitingLink.current = false; | ||
| void queryClient.invalidateQueries({ queryKey: ["github_login"] }); | ||
| void queryClient.invalidateQueries({ | ||
| queryKey: ["integrations", "list"], | ||
| }); | ||
| void queryClient.invalidateQueries({ | ||
| queryKey: ["user-github-integrations"], | ||
| }); | ||
| }; | ||
| window.addEventListener("focus", onFocus); | ||
| return () => window.removeEventListener("focus", onFocus); | ||
| }, [queryClient]); | ||
|
|
||
| const connect = useCallback(async () => { | ||
| if (!canConnect || inFlight.current || !apiClient || !projectId) return; | ||
| inFlight.current = true; | ||
| awaitingLink.current = true; | ||
| setIsConnecting(true); | ||
| try { | ||
| const res = await apiClient.startGithubUserIntegrationConnect(projectId); | ||
| const installUrl = res.install_url?.trim() ?? ""; | ||
| if (!installUrl) { | ||
| awaitingLink.current = false; | ||
| toast.error( | ||
| "GitHub connection did not return a URL. Please try again.", | ||
| ); | ||
| return; | ||
| } | ||
| await trpcClient.os.openExternal.mutate({ url: installUrl }); | ||
| } catch (error) { | ||
| awaitingLink.current = false; | ||
| toast.error( | ||
| error instanceof Error | ||
| ? error.message | ||
| : "Failed to start GitHub connection", | ||
| ); | ||
| } finally { | ||
| inFlight.current = false; | ||
| setIsConnecting(false); | ||
| } | ||
| }, [apiClient, canConnect, projectId]); | ||
|
|
||
| return { connect, isConnecting, canConnect }; | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.openfallback removedThe original
openUrlInBrowserhelper silently fell back towindow.openwhentrpcClient.os.openExternal.mutatethrew. The new code lets the throw propagate to the outercatch, so the user sees an error toast instead of the URL opening. In non-Electron environments (tests, browser builds) or if the IPC channel is unavailable, the install flow now silently fails rather than opening the tab. Consider restoring the fallback:Prompt To Fix With AI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm maybe we don;t need this