123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import type {AutofixRepoDefinition} from 'sentry/components/events/autofix/types';
- import {
- type ApiQueryKey,
- useApiQuery,
- type UseApiQueryOptions,
- } from 'sentry/utils/queryClient';
- import type RequestError from 'sentry/utils/requestError/requestError';
- export interface AutofixSetupRepoDefinition extends AutofixRepoDefinition {
- ok: boolean;
- }
- export type AutofixSetupResponse = {
- genAIConsent: {
- ok: boolean;
- };
- integration: {
- ok: boolean;
- reason: string | null;
- };
- githubWriteIntegration?: {
- ok: boolean;
- repos: AutofixSetupRepoDefinition[];
- } | null;
- };
- export function makeAutofixSetupQueryKey(
- groupId: string,
- checkWriteAccess?: boolean
- ): ApiQueryKey {
- return [
- `/issues/${groupId}/autofix/setup/${checkWriteAccess ? '?check_write_access=true' : ''}`,
- ];
- }
- export function useAutofixSetup(
- {groupId, checkWriteAccess}: {groupId: string; checkWriteAccess?: boolean},
- options: Omit<UseApiQueryOptions<AutofixSetupResponse, RequestError>, 'staleTime'> = {}
- ) {
- const queryData = useApiQuery<AutofixSetupResponse>(
- makeAutofixSetupQueryKey(groupId, checkWriteAccess),
- {
- enabled: Boolean(groupId),
- staleTime: 0,
- retry: false,
- ...options,
- }
- );
- return {
- ...queryData,
- canStartAutofix: Boolean(
- queryData.data?.integration.ok && queryData.data?.genAIConsent.ok
- ),
- canCreatePullRequests: Boolean(queryData.data?.githubWriteIntegration?.ok),
- };
- }
|