Files
supabase/apps/studio/data/integrations/github-branches-query.ts
Kevin Grüneberg 15c9a6ced3 perf: pass org slug / project ref to resource warnings endpoint (#39471)
Based on https://github.com/supabase/infrastructure/pull/26483 - pass in project ref / org slug to ensure we filter down and not query across all orgs unnecessarily
2025-10-14 18:27:34 +08:00

43 lines
1.3 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { integrationKeys } from './keys'
export type GitHubBranchesVariables = {
connectionId?: number
}
export async function getGitHubBranches(
{ connectionId }: GitHubBranchesVariables,
signal?: AbortSignal
) {
if (!connectionId) throw new Error('connectionId is required')
const { data, error } = await get(`/platform/integrations/github/branches/{connection_id}`, {
params: { path: { connection_id: connectionId } },
signal,
})
if (error) handleError(error)
return data
}
export type GitHubBranchesData = Awaited<ReturnType<typeof getGitHubBranches>>
export type GitHubBranchesError = ResponseError
export const useGitHubBranchesQuery = <TData = GitHubBranchesData>(
{ connectionId }: GitHubBranchesVariables,
{
enabled = true,
...options
}: UseQueryOptions<GitHubBranchesData, GitHubBranchesError, TData> = {}
) =>
useQuery<GitHubBranchesData, GitHubBranchesError, TData>(
integrationKeys.githubBranchesList(connectionId),
({ signal }) => getGitHubBranches({ connectionId }, signal),
{
enabled: enabled && typeof connectionId !== 'undefined',
...options,
}
)