Files
supabase/apps/studio/data/workflow-runs/workflow-run-query.ts
T
ea38c6d153 Review and merge branch (#36795)
* allow creating branching without git

* update branching modals

* add account connections

* edit branch

* copy

* update copy

* enable branch modal changes

* add gitless branching flag

* update account connections

* merge page

* merge experiment

* update merge

* update pull requests empty state

* use diff query

* branch diffing

* diff query

* Clean up

* refinements to gitless branching

* branching merge and status

* link

* branch function diffing

* update styling

* refactor

* remove hook

* error handling

* move

* 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

* style and workflow updates

* fix side panel size

* fix duplicate onerror

* copy changes

* refetch

* merge mutation copy

* remove import

* add cost

* allow connection details on create

* initial queries

* push button

* merge cleanup

* 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

* failed merge

* error positioning

* refactoring merge

* workflow refactor

* hook move

* clarification with github integration

* replace branch dropdown button

* update repo picker

* updates

* remove modal

* fix small nits

* change defaults

* clean up

* disable if not gitless and no connection

* clean up

* always show workflow run id

* optimistic

* fix branch query

* fix issues

* fetch edge diff

* confirm merge

* update edge functions key

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
Co-authored-by: Alaister Young <a@alaisteryoung.com>
2025-07-04 14:57:59 +10:00

53 lines
1.6 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { workflowRunKeys } from './keys'
export type WorkflowRunVariables = {
projectRef?: string
workflowRunId?: string
}
export async function getWorkflowRun(
{ workflowRunId }: WorkflowRunVariables,
signal?: AbortSignal
): Promise<{ logs: string; workflowRunId: string }> {
if (!workflowRunId) throw new Error('workflowRunId is required')
// Use the logs endpoint which fetches workflow run status
const { data, error } = await get('/platform/workflow-runs/{workflow_run_id}/logs', {
params: {
path: {
workflow_run_id: workflowRunId,
},
},
parseAs: 'text',
signal,
})
if (error) {
handleError(error)
}
// Return an object with the logs and we'll extract status from headers if needed
return { logs: data as string, workflowRunId }
}
export type WorkflowRunData = { logs: string; workflowRunId: string }
export type WorkflowRunError = ResponseError
export const useWorkflowRunQuery = <TData = WorkflowRunData>(
{ projectRef, workflowRunId }: WorkflowRunVariables,
{ enabled = true, ...options }: UseQueryOptions<WorkflowRunData, WorkflowRunError, TData> = {}
) =>
useQuery<WorkflowRunData, WorkflowRunError, TData>(
workflowRunKeys.detail(projectRef, workflowRunId),
({ signal }) => getWorkflowRun({ workflowRunId }, signal),
{
enabled: enabled && typeof workflowRunId !== 'undefined',
staleTime: 0,
...options,
}
)