| |
| |
| |
| |
| |
|
|
| import { useMutation, useQueryClient } from '@tanstack/react-query'; |
| import { getElectronAPI, GitHubIssue, GitHubComment } from '@/lib/electron'; |
| import { queryKeys } from '@/lib/query-keys'; |
| import { toast } from 'sonner'; |
| import type { LinkedPRInfo, ModelId, ThinkingLevel, ReasoningEffort } from '@automaker/types'; |
| import { resolveModelString } from '@automaker/model-resolver'; |
|
|
| |
| |
| |
| interface ValidateIssueInput { |
| issue: GitHubIssue; |
| model?: ModelId; |
| thinkingLevel?: ThinkingLevel; |
| reasoningEffort?: ReasoningEffort; |
| providerId?: string; |
| comments?: GitHubComment[]; |
| linkedPRs?: LinkedPRInfo[]; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function useValidateIssue(projectPath: string) { |
| return useMutation({ |
| mutationFn: async (input: ValidateIssueInput) => { |
| const { issue, model, thinkingLevel, reasoningEffort, providerId, comments, linkedPRs } = |
| input; |
|
|
| const api = getElectronAPI(); |
| if (!api.github?.validateIssue) { |
| throw new Error('Validation API not available'); |
| } |
|
|
| const validationInput = { |
| issueNumber: issue.number, |
| issueTitle: issue.title, |
| issueBody: issue.body || '', |
| issueLabels: issue.labels.map((l) => l.name), |
| comments, |
| linkedPRs, |
| }; |
|
|
| |
| const resolvedModel = model ? resolveModelString(model) : undefined; |
|
|
| const result = await api.github.validateIssue( |
| projectPath, |
| validationInput, |
| resolvedModel, |
| thinkingLevel, |
| reasoningEffort, |
| providerId |
| ); |
|
|
| if (!result.success) { |
| throw new Error(result.error || 'Failed to start validation'); |
| } |
|
|
| return { issueNumber: issue.number }; |
| }, |
| onSuccess: (_, variables) => { |
| toast.info(`Starting validation for issue #${variables.issue.number}`, { |
| description: 'You will be notified when the analysis is complete', |
| }); |
| }, |
| onError: (error) => { |
| toast.error('Failed to validate issue', { |
| description: error instanceof Error ? error.message : 'Unknown error', |
| }); |
| }, |
| |
| |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function useMarkValidationViewed(projectPath: string) { |
| const queryClient = useQueryClient(); |
|
|
| return useMutation({ |
| mutationFn: async (issueNumber: number) => { |
| const api = getElectronAPI(); |
| if (!api.github?.markValidationViewed) { |
| throw new Error('Mark viewed API not available'); |
| } |
|
|
| const result = await api.github.markValidationViewed(projectPath, issueNumber); |
|
|
| if (!result.success) { |
| throw new Error(result.error || 'Failed to mark as viewed'); |
| } |
|
|
| return { issueNumber }; |
| }, |
| onSuccess: () => { |
| |
| queryClient.invalidateQueries({ |
| queryKey: queryKeys.github.validations(projectPath), |
| }); |
| }, |
| |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function useResolveReviewThread(projectPath: string, prNumber: number) { |
| const queryClient = useQueryClient(); |
|
|
| return useMutation({ |
| mutationFn: async ({ threadId, resolve }: { threadId: string; resolve: boolean }) => { |
| const api = getElectronAPI(); |
| if (!api.github?.resolveReviewThread) { |
| throw new Error('Resolve review thread API not available'); |
| } |
|
|
| const result = await api.github.resolveReviewThread(projectPath, threadId, resolve); |
|
|
| if (!result.success) { |
| throw new Error(result.error || 'Failed to resolve review thread'); |
| } |
|
|
| return { isResolved: result.isResolved ?? resolve }; |
| }, |
| onSuccess: (_, variables) => { |
| const action = variables.resolve ? 'resolved' : 'unresolved'; |
| toast.success(`Comment ${action}`, { |
| description: `The review thread has been ${action} on GitHub`, |
| }); |
| |
| queryClient.invalidateQueries({ |
| queryKey: queryKeys.github.prReviewComments(projectPath, prNumber), |
| }); |
| }, |
| onError: (error) => { |
| toast.error('Failed to update comment', { |
| description: error instanceof Error ? error.message : 'Unknown error', |
| }); |
| }, |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function useGetValidationStatus(projectPath: string) { |
| return useMutation({ |
| mutationFn: async () => { |
| const api = getElectronAPI(); |
| if (!api.github?.getValidationStatus) { |
| throw new Error('Validation status API not available'); |
| } |
|
|
| const result = await api.github.getValidationStatus(projectPath); |
|
|
| if (!result.success) { |
| throw new Error(result.error || 'Failed to get validation status'); |
| } |
|
|
| return result.runningIssues ?? []; |
| }, |
| }); |
| } |
|
|