Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/ipc/githubIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as fs from 'fs';
import * as crypto from 'crypto';
import { homedir } from 'os';
import { quoteShellArg } from '../utils/shellEscape';
import { getAppSettings } from '../settings';

const execAsync = promisify(exec);
const githubService = new GitHubService();
Expand Down Expand Up @@ -285,13 +286,15 @@ export function registerGithubIpc() {
? args.taskName.trim()
: `pr-${prNumber}-${defaultSlug}`;
const branchName = args.branchName || `pr/${prNumber}`;
const reviewProvider = getAppSettings().defaultProvider || 'claude';
const buildTaskInfo = (taskPath: string, name: string) => ({
id: crypto.randomUUID(),
projectId,
name,
branch: branchName,
path: taskPath,
status: 'active' as const,
agentId: reviewProvider,
useWorktree: true,
metadata: {
prNumber,
Expand All @@ -305,9 +308,12 @@ export function registerGithubIpc() {

if (existing) {
const persistedTask = await databaseService.getTaskByPath(existing.path);
const existingTask = persistedTask ?? buildTaskInfo(existing.path, existing.name);
let existingTask = persistedTask ?? buildTaskInfo(existing.path, existing.name);

if (!persistedTask) {
if (!persistedTask || !persistedTask.agentId) {
if (persistedTask && !persistedTask.agentId) {
existingTask = { ...persistedTask, agentId: reviewProvider };
}
try {
await databaseService.saveTask(existingTask);
} catch (dbError) {
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/OpenPrsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button } from './ui/button';
import { Input } from './ui/input';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip';
import { useToast } from '../hooks/use-toast';
import { rpc } from '../lib/rpc';
import { ArrowUpRight, ChevronDown, ChevronRight, Github, Loader2, Search } from 'lucide-react';
import type { Task } from '../types/app';

Expand Down Expand Up @@ -50,6 +51,8 @@ const OpenPrsSection: React.FC<OpenPrsSectionProps> = ({ projectPath, projectId,
const handleReviewPr = async (pr: PullRequestSummary) => {
setCreatingForPr(pr.number);
try {
const settings = await rpc.appSettings.get();
const defaultProvider = settings?.defaultProvider || 'claude';
const result = await window.electronAPI.githubCreatePullRequestWorktree({
projectPath,
projectId,
Expand All @@ -58,16 +61,21 @@ const OpenPrsSection: React.FC<OpenPrsSectionProps> = ({ projectPath, projectId,
});

if (result.success && result.task) {
const taskAgentId = (result.task as { agentId?: string | null }).agentId || defaultProvider;
const task: Task = {
id: result.task.id,
projectId: result.task.projectId,
name: result.task.name,
branch: result.task.branch,
path: result.task.path,
status: result.task.status as Task['status'],
agentId: taskAgentId,
useWorktree: true,
metadata: result.task.metadata,
};
if (!(result.task as { agentId?: string | null }).agentId) {
void rpc.db.saveTask(task).catch(() => {});
}
onReviewPr(task);
} else if (result.success && result.worktree) {
// Fallback: worktree was created but task came from an existing match
Expand All @@ -78,9 +86,11 @@ const OpenPrsSection: React.FC<OpenPrsSectionProps> = ({ projectPath, projectId,
branch: result.branchName || '',
path: result.worktree.path || '',
status: 'active',
agentId: defaultProvider,
useWorktree: true,
metadata: { prNumber: pr.number, prTitle: pr.title },
};
void rpc.db.saveTask(task).catch(() => {});
onReviewPr(task);
} else {
toast({
Expand Down
Loading