Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {IconOpen} from 'sentry/icons';
import {t} from 'sentry/locale';
import type {OrganizationIntegration} from 'sentry/types/integrations';

function getProviderConfigUrl(integration: OrganizationIntegration): string | null {
export function getProviderConfigUrl(
integration: OrganizationIntegration
): string | null {
const {externalId, provider, domainName, accountType} = integration;
if (!externalId) {
return null;
Expand Down
10 changes: 7 additions & 3 deletions static/app/components/repositories/scmRepoTreeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import type {ModalRenderProps} from 'sentry/actionCreators/modal';
import {ScmIntegrationTree} from 'sentry/components/repositories/scmIntegrationTree/scmIntegrationTree';
import {ScmTreeFilters} from 'sentry/components/repositories/scmIntegrationTree/scmTreeFilters';
import type {RepoFilter} from 'sentry/components/repositories/scmIntegrationTree/types';
import {t, tct} from 'sentry/locale';
import {tct} from 'sentry/locale';

export function ScmRepoTreeModal({Header, Body}: ModalRenderProps) {
interface Props extends ModalRenderProps {
title: string;
}

export function ScmRepoTreeModal({Header, Body, title}: Props) {
const [search, setSearch] = useState('');
const [repoFilter, setRepoFilter] = useState<RepoFilter>('all');

return (
<Fragment>
<Header closeButton>
<Heading as="h4">{t('Add Repository')}</Heading>
<Heading as="h4">{title}</Heading>
</Header>
<Body>
<Stack gap="2xl">
Expand Down
2 changes: 2 additions & 0 deletions static/app/types/organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface Organization extends OrganizationSummary {
dataScrubberDefaults: boolean;
debugFilesRole: string;
defaultCodeReviewTriggers: CodeReviewTrigger[];
defaultCodingAgent: string | null;
defaultCodingAgentIntegrationId: number | null;
defaultRole: string;
enhancedPrivacy: boolean;
eventsMemberAdmin: boolean;
Expand Down
18 changes: 17 additions & 1 deletion static/app/utils/api/apiFetch.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {useEffect} from 'react';
import type {QueryFunctionContext} from '@tanstack/react-query';

import {parseQueryKey} from 'sentry/utils/api/apiQueryKey';
import type {ApiQueryKey, InfiniteApiQueryKey} from 'sentry/utils/api/apiQueryKey';
import type {ParsedHeader} from 'sentry/utils/parseLinkHeader';
import {QUERY_API_CLIENT} from 'sentry/utils/queryClient';
import {QUERY_API_CLIENT, type UseInfiniteQueryResult} from 'sentry/utils/queryClient';

export type ApiResponse<TResponseData = unknown> = {
headers: {
Expand Down Expand Up @@ -68,3 +69,18 @@ export async function apiFetchInfinite<TQueryFnData = unknown>(
json: json as TQueryFnData,
};
}

export function useFetchAllPages<TQueryFnData = unknown>({
result,
enabled = true,
}: {
result: UseInfiniteQueryResult<TQueryFnData, Error>;
enabled?: boolean;
}) {
const {fetchNextPage, hasNextPage, isError, isFetchingNextPage} = result;
useEffect(() => {
if (enabled && !isError && !isFetchingNextPage && hasNextPage) {
fetchNextPage();
}
}, [enabled, hasNextPage, fetchNextPage, isError, isFetchingNextPage]);
}
205 changes: 205 additions & 0 deletions static/app/views/settings/seer/overview/autofixOverviewSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import {mutationOptions} from '@tanstack/react-query';
import {z} from 'zod';

import {Button} from '@sentry/scraps/button';
import {AutoSaveForm} from '@sentry/scraps/form';
import {Flex} from '@sentry/scraps/layout';
import {Link} from '@sentry/scraps/link';

import {updateOrganization} from 'sentry/actionCreators/organizations';
import {hasEveryAccess} from 'sentry/components/acl/access';
import {organizationIntegrationsCodingAgents} from 'sentry/components/events/autofix/useAutofix';
import {IconSettings} from 'sentry/icons';
import {t, tn} from 'sentry/locale';
import type {Organization} from 'sentry/types/organization';
import {fetchMutation, useQuery} from 'sentry/utils/queryClient';
import {useOrganization} from 'sentry/utils/useOrganization';
import {SeerOverview} from 'sentry/views/settings/seer/overview/components';
import {useSeerOverviewData} from 'sentry/views/settings/seer/overview/useSeerOverviewData';
import {useAgentOptions} from 'sentry/views/settings/seer/seerAgentHooks';

interface Props {
isLoading: boolean;
stats: ReturnType<typeof useSeerOverviewData>['stats'];
}

export function AutofixOverviewSection({stats, isLoading}: Props) {
const organization = useOrganization();
const canWrite = hasEveryAccess(['org:write'], {organization});

const schema = z.object({
defaultCodingAgent: z.string().nullable(),
defaultCodingAgentIntegrationId: z.number().nullable(),
defaultAutofixAutomationTuning: z.enum(['off', 'medium']),
});

const {data: integrations} = useQuery({
...organizationIntegrationsCodingAgents(organization),
select: data => data.json.integrations ?? [],
});
const options = useAgentOptions({integrations: integrations ?? []});

const orgMutationOpts = mutationOptions({
mutationFn: (data: Partial<Organization>) =>
fetchMutation<Organization>({
method: 'PUT',
url: `/organizations/${organization.slug}/`,
data,
}),
onSuccess: updateOrganization,
});
const autofixTuningMutationOpts = mutationOptions({
mutationFn: (data: {defaultAutofixAutomationTuning: boolean}) =>
fetchMutation<Organization>({
method: 'PUT',
url: `/organizations/${organization.slug}/`,
data: {
// All values other than 'off' are converted to 'medium'
defaultAutofixAutomationTuning: data.defaultAutofixAutomationTuning
? 'medium'
: 'off',
},
}),
onSuccess: updateOrganization,
});

return (
<SeerOverview.Section>
<SeerOverview.SectionHeader title={t('Autofix')}>
{isLoading ? null : (
<Link to={`/settings/${organization.slug}/seer/repos/`}>
<Flex align="center" gap="xs">
{t('Configure')} <IconSettings size="xs" />
</Flex>
</Link>
)}
</SeerOverview.SectionHeader>
<SeerOverview.Stat
value={SeerOverview.formatStatValue(
stats.projectsWithReposCount ?? 0,
stats.totalProjects,
isLoading
)}
label={t('Projects with repos')}
/>

<div />
<SeerOverview.ActionButton>
<Button
size="xs"
disabled={stats.projectsWithReposCount === stats.totalProjects}
onClick={() => {
// TODO
}}
>
{t('Connect Projects to Repos')}
</Button>
</SeerOverview.ActionButton>

<SeerOverview.Stat
value={SeerOverview.formatStatValue(
stats.projectsWithAutomationCount ?? 0,
stats.projectsWithReposCount ?? 0,
isLoading
)}
label={t('Projects with Autofix Handoff enabled')}
/>

<AutoSaveForm
name="defaultCodingAgent"
schema={schema}
initialValue={organization.defaultCodingAgent ?? 'seer'}
mutationOptions={orgMutationOpts}
>
{field => (
<field.Layout.Stack
label={t('Autofix Handoff Default')}
hintText={t(
'For all new projects with connected repos, Seer will handoff Autofix to a coding agent.'
)}
>
<field.Select
value={field.state.value}

Check failure on line 122 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / @typescript/native-preview

Type 'ObjectValue<never, { defaultCodingAgent: string | null; defaultCodingAgentIntegrationId: number | null; defaultAutofixAutomationTuning: "medium" | "off"; }, "defaultCodingAgent">' is not assignable to type '"seer" | "seer"[] | null'.

Check failure on line 122 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'ObjectValue<never, { defaultCodingAgent: string | null; defaultCodingAgentIntegrationId: number | null; defaultAutofixAutomationTuning: "off" | "medium"; }, "defaultCodingAgent">' is not assignable to type 'CodingAgentIntegration | CodingAgentIntegration[] | null'.
options={options}

Check failure on line 123 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / @typescript/native-preview

Type '({ value: "seer"; label: string; } | { value: CodingAgentIntegration; label: string; } | { value: "none"; label: string; })[]' is not assignable to type 'readonly SelectValue<"seer">[]'.

Check failure on line 123 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type '({ value: CodingAgentIntegration; label: string; } | { value: "seer"; label: string; } | { value: "none"; label: string; })[]' is not assignable to type 'readonly SelectValue<CodingAgentIntegration>[]'.
onChange={field.handleChange}

Check failure on line 124 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type '(updater: Updater<ObjectValue<never, { defaultCodingAgent: string | null; defaultCodingAgentIntegrationId: number | null; defaultAutofixAutomationTuning: "off" | "medium"; }, "defaultCodingAgent">>) => void' is not assignable to type '((value: CodingAgentIntegration) => void) | ((value: CodingAgentIntegration | null) => void) | ((value: CodingAgentIntegration[]) => void)'.
disabled={!canWrite}
/>
</field.Layout.Stack>
)}
</AutoSaveForm>

{isLoading ? (
<div />
) : (
<SeerOverview.ActionButton>
<Button
size="xs"
disabled={stats.projectsWithReposCount === stats.totalProjects}
onClick={() => {
// TODO
}}
>
{tn('Apply to the project', 'Apply to all %s projects', stats.totalProjects)}
</Button>
</SeerOverview.ActionButton>
)}

<SeerOverview.Stat
value={SeerOverview.formatStatValue(
stats.projectsWithCreatePrCount ?? 0,
stats.projectsWithReposCount ?? 0,
isLoading
)}
label={t('Projects with PR Auto Creation enabled')}
/>

<AutoSaveForm
name="defaultAutofixAutomationTuning"
schema={schema}
initialValue={organization.defaultAutofixAutomationTuning !== 'off'}

Check failure on line 159 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / @typescript/native-preview

Type 'boolean' is not assignable to type '"medium" | "off"'.

Check failure on line 159 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'boolean' is not assignable to type '"off" | "medium"'.
mutationOptions={autofixTuningMutationOpts}

Check failure on line 160 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / @typescript/native-preview

Type 'Omit<UseMutationOptions<Organization, Error, { defaultAutofixAutomationTuning: boolean; }, unknown>, "mutationKey">' is not assignable to type 'UseMutationOptions<Organization, Error, NoInfer<Record<"defaultAutofixAutomationTuning", "medium" | "off">>, unknown>'.

Check failure on line 160 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'Omit<UseMutationOptions<Organization, Error, { defaultAutofixAutomationTuning: boolean; }, unknown>, "mutationKey">' is not assignable to type 'UseMutationOptions<Organization, Error, NoInfer<Record<"defaultAutofixAutomationTuning", "off" | "medium">>, unknown>'.
>
{field => (
<field.Layout.Stack
label={t('Allow Autofix to create PRs by Default')}
hintText={t(
'For all new projects with connected repos, Seer will be able to make pull requests for highly actionable issues.'
)}
>
<field.Switch
checked={field.state.value}

Check failure on line 170 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / @typescript/native-preview

Type 'string' is not assignable to type 'boolean'.

Check failure on line 170 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'string' is not assignable to type 'boolean'.
onChange={field.handleChange}

Check failure on line 171 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / @typescript/native-preview

Type '(updater: Updater<ObjectValue<never, { defaultCodingAgent: string | null; defaultCodingAgentIntegrationId: number | null; defaultAutofixAutomationTuning: "medium" | "off"; }, "defaultAutofixAutomationTuning">>) => void' is not assignable to type '(value: boolean) => void'.

Check failure on line 171 in static/app/views/settings/seer/overview/autofixOverviewSection.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type '(updater: Updater<ObjectValue<never, { defaultCodingAgent: string | null; defaultCodingAgentIntegrationId: number | null; defaultAutofixAutomationTuning: "off" | "medium"; }, "defaultAutofixAutomationTuning">>) => void' is not assignable to type '(value: boolean) => void'.
disabled={!canWrite}
/>
</field.Layout.Stack>
)}
</AutoSaveForm>

{isLoading ? (
<div />
) : (
<SeerOverview.ActionButton>
<Button
size="xs"
disabled={stats.projectsWithReposCount === stats.totalProjects}
onClick={() => {
// TODO
}}
>
{organization.defaultAutofixAutomationTuning === 'off'
? tn(
'Disable for the project',
'Disable for all %s projects',
stats.totalProjects
)
: tn(
'Enable for the project',
'Enable for all %s projects',
stats.totalProjects
)}
</Button>
</SeerOverview.ActionButton>
)}
</SeerOverview.Section>
);
}
Loading
Loading