From 48ee5659c9b34cf1f283b79f3c04e2a3145e795b Mon Sep 17 00:00:00 2001 From: Rohit Malhotra Date: Tue, 1 Jul 2025 20:56:00 -0400 Subject: [PATCH] Conditionally render 'Add GitHub repos' link based on provider (#9499) Co-authored-by: openhands --- .../features/home/repo-connector.test.tsx | 32 ++++++++++++++++++- .../features/home/repo-provider-links.tsx | 12 +++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/frontend/__tests__/components/features/home/repo-connector.test.tsx b/frontend/__tests__/components/features/home/repo-connector.test.tsx index 3f7c2248e4..908b692cf5 100644 --- a/frontend/__tests__/components/features/home/repo-connector.test.tsx +++ b/frontend/__tests__/components/features/home/repo-connector.test.tsx @@ -119,18 +119,48 @@ describe("RepoConnector", () => { expect(launchButton).toBeEnabled(); }); - it("should render the 'add git(hub|lab) repos' links if saas mode", async () => { + it("should render the 'add github repos' link if saas mode and github provider is set", async () => { const getConfiSpy = vi.spyOn(OpenHands, "getConfig"); // @ts-expect-error - only return the APP_MODE getConfiSpy.mockResolvedValue({ APP_MODE: "saas", }); + const getSettingsSpy = vi.spyOn(OpenHands, "getSettings"); + getSettingsSpy.mockResolvedValue({ + ...MOCK_DEFAULT_USER_SETTINGS, + provider_tokens_set: { + github: "some-token", + gitlab: null, + }, + }); + renderRepoConnector(); await screen.findByText("HOME$ADD_GITHUB_REPOS"); }); + it("should not render the 'add github repos' link if github provider is not set", async () => { + const getConfiSpy = vi.spyOn(OpenHands, "getConfig"); + // @ts-expect-error - only return the APP_MODE + getConfiSpy.mockResolvedValue({ + APP_MODE: "saas", + }); + + const getSettingsSpy = vi.spyOn(OpenHands, "getSettings"); + getSettingsSpy.mockResolvedValue({ + ...MOCK_DEFAULT_USER_SETTINGS, + provider_tokens_set: { + gitlab: "some-token", + github: null, + }, + }); + + renderRepoConnector(); + + expect(screen.queryByText("HOME$ADD_GITHUB_REPOS")).not.toBeInTheDocument(); + }); + it("should not render the 'add git(hub|lab) repos' links if oss mode", async () => { const getConfiSpy = vi.spyOn(OpenHands, "getConfig"); // @ts-expect-error - only return the APP_MODE diff --git a/frontend/src/components/features/home/repo-provider-links.tsx b/frontend/src/components/features/home/repo-provider-links.tsx index 5aa0cf3d49..a99a28cae8 100644 --- a/frontend/src/components/features/home/repo-provider-links.tsx +++ b/frontend/src/components/features/home/repo-provider-links.tsx @@ -1,20 +1,26 @@ import { useTranslation } from "react-i18next"; import { useConfig } from "#/hooks/query/use-config"; import { I18nKey } from "#/i18n/declaration"; +import { useUserProviders } from "#/hooks/use-user-providers"; export function RepoProviderLinks() { const { t } = useTranslation(); const { data: config } = useConfig(); + const { providers } = useUserProviders(); const githubHref = config ? `https://github.com/apps/${config.APP_SLUG}/installations/new` : ""; + const hasGithubProvider = providers.includes("github"); + return (
- - {t(I18nKey.HOME$ADD_GITHUB_REPOS)} - + {hasGithubProvider && ( + + {t(I18nKey.HOME$ADD_GITHUB_REPOS)} + + )}
); }