mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## Problem When workflow runs for branches fail due to stuck tasks, they can sit idle indefinitely. Users are unaware that they need to make a new commit to retrigger the workflow — leading to confusion, wasted time, and silent failures going unnoticed. ## Solution Provide a button that allows users to retrigger a workflow when it is not being removed. ## How to test - Create a branch - Wait for its row to appear on the branch management page - Click the _View logs_ button - You should see a _Retrigger_ button - Clicking it should make a new row appear in those logs <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Retrigger previously executed workflows directly from branch preview actions. * Confirmation dialog added for retrigger actions. * **Improvements** * Toast-style error notifications when retriggering fails. * Workflow run list layout updated for a more flexible horizontal display. * After retriggering, workflow and action lists refresh so updates appear promptly. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { actionKeys } from '../actions/keys'
|
|
import { branchKeys } from './keys'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type BranchPushVariables = {
|
|
branchRef: string
|
|
projectRef: string
|
|
}
|
|
|
|
export async function pushBranch({ branchRef }: Pick<BranchPushVariables, 'branchRef'>) {
|
|
const { data, error } = await post('/v1/branches/{branch_id_or_ref}/push', {
|
|
params: { path: { branch_id_or_ref: branchRef } },
|
|
body: {},
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type BranchPushData = Awaited<ReturnType<typeof pushBranch>>
|
|
|
|
export const useBranchPushMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<BranchPushData, ResponseError, BranchPushVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation<BranchPushData, ResponseError, BranchPushVariables>({
|
|
mutationFn: (vars) => pushBranch(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await queryClient.invalidateQueries({ queryKey: branchKeys.list(projectRef) })
|
|
await queryClient.invalidateQueries({ queryKey: actionKeys.list(projectRef) })
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to push branch: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|