import {Fragment, useEffect} from 'react'; import styled from '@emotion/styled'; import {Button} from 'sentry/components/button'; import { type AutofixSetupRepoDefinition, type AutofixSetupResponse, useAutofixSetup, } from 'sentry/components/events/autofix/useAutofixSetup'; import {GuidedSteps} from 'sentry/components/guidedSteps/guidedSteps'; import ExternalLink from 'sentry/components/links/externalLink'; import LoadingError from 'sentry/components/loadingError'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import {IconCheckmark, IconGithub} from 'sentry/icons'; import {t, tct} from 'sentry/locale'; import {space} from 'sentry/styles/space'; import type {Integration} from 'sentry/types/integrations'; import {trackAnalytics} from 'sentry/utils/analytics'; import {useApiQuery} from 'sentry/utils/queryClient'; import useOrganization from 'sentry/utils/useOrganization'; function AutofixIntegrationStep({autofixSetup}: {autofixSetup: AutofixSetupResponse}) { if (autofixSetup.integration.ok) { return ( {tct('The GitHub integration is already installed, [link: view in settings].', { link: , })} ); } if (autofixSetup.integration.reason === 'integration_inactive') { return (

{tct( 'The GitHub integration has been installed but is not active. Navigate to the [integration settings page] and enable it to continue.', { link: , } )}

{tct( 'Once enabled, come back to this page. For more information related to installing the GitHub integration, read the [link:documentation].', { link: ( ), } )}

); } return (

{t( 'Install the GitHub integration on the integration settings page and clicking the "Install" button. Follow the steps provided.' )}

{tct( 'Once installed, come back to this page. For more information related to installing the GitHub integration, read the [link:documentation].', { link: ( ), } )}

); } function AutofixCodeMappingStep() { const organization = useOrganization(); const {data: integrationConfigurations} = useApiQuery( [ `/organizations/${organization.slug}/integrations/?provider_key=github&includeConfig=0`, ], { staleTime: Infinity, } ); const configurationId = integrationConfigurations?.at(0)?.id; const url = `/settings/integrations/github/${configurationId ? configurationId + '/?tab=codeMappings' : ''}`; return (

{t( 'Set up code mappings for the Github repositories you want to run Autofix on for this project.' )}

); } export function GitRepoLink({repo}: {repo: AutofixSetupRepoDefinition}) { if (repo.provider === 'github' || repo.provider.split(':')[1] === 'github') { return ( {repo.owner}/{repo.name} {repo.ok ? : null} ); } return (
  • {repo.owner}/{repo.name}
  • ); } function AutofixSetupSteps({autofixSetup}: {autofixSetup: AutofixSetupResponse}) { return ( ); } export function AutofixSetupContent({ projectId, groupId, }: { groupId: string; projectId: string; }) { const organization = useOrganization(); const {data, isPending, isError} = useAutofixSetup( {groupId}, // Want to check setup status whenever the user comes back to the tab {refetchOnWindowFocus: true} ); useEffect(() => { if (!data) { return; } trackAnalytics('autofix.setup_modal_viewed', { groupId, projectId, organization, setup_gen_ai_consent: data.genAIConsent.ok, setup_integration: data.integration.ok, setup_write_integration: data.githubWriteIntegration?.ok, }); }, [data, groupId, organization, projectId]); if (isPending) { return ; } if (isError) { return ; } return (
    Set up Autofix

    Sentry's AI-enabled Autofix uses all of the contextual data surrounding this error to work with you to find the root cause and create a fix.

    To use Autofix, please follow the instructions below.

    ); } export const AutofixSetupDone = styled('div')` position: relative; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 40px; font-size: ${p => p.theme.fontSizeLarge}; `; const Header = styled('p')` font-size: ${p => p.theme.fontSizeLarge}; font-weight: ${p => p.theme.fontWeightBold}; margin-bottom: ${space(2)}; margin-top: ${space(2)}; `; const RepoLinkItem = styled('li')` display: flex; align-items: center; gap: ${space(0.5)}; `; const GithubLink = styled('div')` display: flex; align-items: center; gap: ${space(0.5)}; `; const Divider = styled('div')` margin: ${space(3)} 0; border-bottom: 2px solid ${p => p.theme.gray100}; `;