Files
supabase/apps/studio/data/integrations/github-branch-check-query.ts
Saxon Fletcher 3f3ed433fc Remove enable branching modal (#36458)
* remove enable branching modal

* re-add github linker

* abstract away enable and disable

* toggle fixes

* update logic to lean on connection status

* update form logic

* sheet layout

* gitless flag

* fix side panel size

* copy changes

* remove import

* add cost

* allow connection details on create

* Fix TS issues

* Fix TS issues

* Couple of clean ups

* Revert hardcode in useFlag

* Fix TS

* layout issues and github check

* refactor

* refactor to use new field

* cleanup

* style

* clarification with github integration

* replace branch dropdown button

* update repo picker

* remove modal

* change defaults

* disable if not gitless and no connection

* fixes

* prevent editing on child branch

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2025-07-02 21:58:45 +10:00

60 lines
1.5 KiB
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { toast } from 'sonner'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
export type GithubBranchVariables = {
repositoryId: number
branchName: string
}
export async function checkGithubBranchValidity(
{ repositoryId, branchName }: GithubBranchVariables,
signal?: AbortSignal
) {
const { data, error } = await get(
'/platform/integrations/github/repositories/{repositoryId}/branches/{branchName}',
{
params: {
path: {
repositoryId,
branchName,
},
},
signal,
}
)
if (error) handleError(error)
return data
}
type GitHubIntegrationCreateData = Awaited<ReturnType<typeof checkGithubBranchValidity>>
export const useCheckGithubBranchValidity = ({
onSuccess,
onError,
...options
}: Omit<
UseMutationOptions<GitHubIntegrationCreateData, ResponseError, GithubBranchVariables>,
'mutationFn'
> = {}) => {
return useMutation<GitHubIntegrationCreateData, ResponseError, GithubBranchVariables>(
(vars) => checkGithubBranchValidity(vars),
{
async onSuccess(data, variables, context) {
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to check Github branch: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
}
)
}