diff --git a/src/config.js b/src/config.js index 8e253129a8..a9733117c7 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1,7 @@ import mapKeys from 'lodash/mapKeys' +export const DEFAULT_GH_APP = 'codecov' + const defaultConfig = { API_URL: '', STRIPE_KEY: '', @@ -8,7 +10,7 @@ const defaultConfig = { SENTRY_PROFILING_SAMPLE_RATE: 0.1, SENTRY_SESSION_SAMPLE_RATE: 0.1, SENTRY_ERROR_SAMPLE_RATE: 1.0, - GH_APP: 'codecov', + GH_APP: DEFAULT_GH_APP, GH_APP_AI: 'codecov-ai', } diff --git a/src/services/navigation/useNavLinks/useStaticNavLinks.test.tsx b/src/services/navigation/useNavLinks/useStaticNavLinks.test.tsx index 2f6bfa106d..03768ec932 100644 --- a/src/services/navigation/useNavLinks/useStaticNavLinks.test.tsx +++ b/src/services/navigation/useNavLinks/useStaticNavLinks.test.tsx @@ -59,8 +59,8 @@ describe('useStaticNavLinks', () => { ${links.uploader} | ${'https://docs.codecov.com/docs/codecov-uploader'} ${links.uploaderCLI} | ${'https://docs.codecov.com/docs/codecov-uploader#using-the-cli-to-upload-reports-with-codecovio-cloud'} ${links.integrityCheck} | ${'https://docs.codecov.com/docs/codecov-uploader#integrity-checking-the-uploader'} - ${links.codecovGithubApp} | ${'https://github.com/apps/codecov'} - ${links.codecovGithubAppSelectTarget} | ${'https://github.com/apps/codecov/installations/select_target'} + ${links.codecovGithubApp} | ${`https://github.com/apps/${config.GH_APP}`} + ${links.codecovGithubAppSelectTarget} | ${`https://github.com/apps/${config.GH_APP}/installations/select_target`} ${links.teamBot} | ${'https://docs.codecov.com/docs/team-bot'} ${links.runtimeInsights} | ${'https://docs.codecov.com/docs/runtime-insights'} ${links.graphAuthorization} | ${'https://docs.codecov.com/reference/authorization#about-graphs'} diff --git a/src/services/navigation/useNavLinks/useStaticNavLinks.ts b/src/services/navigation/useNavLinks/useStaticNavLinks.ts index 033bdc32ad..32a977a626 100644 --- a/src/services/navigation/useNavLinks/useStaticNavLinks.ts +++ b/src/services/navigation/useNavLinks/useStaticNavLinks.ts @@ -200,7 +200,8 @@ export function useStaticNavLinks() { openNewTab: true, }, codecovGithubAppSelectTarget: { - path: () => 'https://github.com/apps/codecov/installations/select_target', + path: () => + `https://github.com/apps/${config.GH_APP}/installations/select_target`, isExternalLink: true, text: 'Codecov Github App', openNewTab: true, diff --git a/src/ui/ContextSwitcher/ContextSwitcher.jsx b/src/ui/ContextSwitcher/ContextSwitcher.jsx index e3818cd2d9..b21f646443 100644 --- a/src/ui/ContextSwitcher/ContextSwitcher.jsx +++ b/src/ui/ContextSwitcher/ContextSwitcher.jsx @@ -5,6 +5,8 @@ import { useParams } from 'react-router-dom' import { useIntersection } from 'react-use' import useClickAway from 'react-use/lib/useClickAway' +import config, { DEFAULT_GH_APP } from 'config' + import { useUpdateDefaultOrganization } from 'services/defaultOrganization' import { providerToName } from 'shared/utils/provider' import A from 'ui/A' @@ -129,6 +131,12 @@ function ContextSwitcher({ const defaultOrgUsername = currentUser?.defaultOrgUsername const isGh = providerToName(provider) === 'Github' + const isSelfHosted = config.IS_SELF_HOSTED + const isCustomGitHubApp = config.GH_APP !== DEFAULT_GH_APP + + // self-hosted cannot use default "codecov" app (must set up custom one) + const shouldShowGitHubInstallLink = + isGh && (isSelfHosted ? isCustomGitHubApp : true) return (
@@ -167,18 +175,14 @@ function ContextSwitcher({ role="listbox" aria-labelledby="listbox-label" > - {isGh ? ( + {shouldShowGitHubInstallLink ? (
  • Install Codecov GitHub app
  • - ) : ( -
  • - Switch context -
  • - )} + ) : null} {contexts.map((context) => ( { }) }) }) + + describe('when on self-hosted', () => { + beforeEach(() => { + config.IS_SELF_HOSTED = true + setup() + }) + + afterEach(() => { + config.GH_APP = DEFAULT_GH_APP + vi.clearAllMocks() + }) + + it('renders the custom app link if set', async () => { + config.GH_APP = 'custom-app' + render( + , + { + wrapper: wrapper(), + } + ) + + const installCopy = await screen.findByText(/Install Codecov GitHub app/) + expect(installCopy).toBeInTheDocument() + expect(installCopy).toHaveAttribute( + 'href', + 'https://github.com/apps/custom-app/installations/new' + ) + expect(installCopy).not.toHaveAttribute( + 'href', + 'https://github.com/apps/codecov/installations/new' + ) + }) + + it('renders no link if custom app env var is not set', async () => { + config.IS_SELF_HOSTED = true + render( + , + { + wrapper: wrapper(), + } + ) + + const installCopy = screen.queryByText(/Install Codecov GitHub app/) + expect(installCopy).not.toBeInTheDocument() + }) + }) })