mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 21:23:07 +00:00
fix: address pr comments
This commit is contained in:
@@ -95,7 +95,7 @@ export function createWorktreeRoutes(events: EventEmitter): Router {
|
|||||||
router.post('/list-dev-servers', createListDevServersHandler());
|
router.post('/list-dev-servers', createListDevServersHandler());
|
||||||
|
|
||||||
// Init script routes
|
// Init script routes
|
||||||
router.post('/init-script', validatePathParams('projectPath'), createGetInitScriptHandler());
|
router.get('/init-script', createGetInitScriptHandler());
|
||||||
router.put('/init-script', validatePathParams('projectPath'), createPutInitScriptHandler());
|
router.put('/init-script', validatePathParams('projectPath'), createPutInitScriptHandler());
|
||||||
router.delete('/init-script', validatePathParams('projectPath'), createDeleteInitScriptHandler());
|
router.delete('/init-script', validatePathParams('projectPath'), createDeleteInitScriptHandler());
|
||||||
router.post(
|
router.post(
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ import {
|
|||||||
} from '../common.js';
|
} from '../common.js';
|
||||||
import { trackBranch } from './branch-tracking.js';
|
import { trackBranch } from './branch-tracking.js';
|
||||||
import { createLogger } from '@automaker/utils';
|
import { createLogger } from '@automaker/utils';
|
||||||
import { runInitScript, getInitScriptPath, hasInitScriptRun } from '../../../services/init-script-service.js';
|
import { runInitScript } from '../../../services/init-script-service.js';
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
const logger = createLogger('Worktree');
|
const logger = createLogger('Worktree');
|
||||||
|
|
||||||
@@ -181,11 +180,6 @@ export function createCreateHandler(events: EventEmitter) {
|
|||||||
// normalizePath converts to forward slashes for API consistency
|
// normalizePath converts to forward slashes for API consistency
|
||||||
const absoluteWorktreePath = path.resolve(worktreePath);
|
const absoluteWorktreePath = path.resolve(worktreePath);
|
||||||
|
|
||||||
// Check if init script exists and should be run (only for new worktrees)
|
|
||||||
const initScriptPath = getInitScriptPath(projectPath);
|
|
||||||
const hasInitScript = fs.existsSync(initScriptPath);
|
|
||||||
const alreadyRan = await hasInitScriptRun(projectPath, branchName);
|
|
||||||
|
|
||||||
// Respond immediately (non-blocking)
|
// Respond immediately (non-blocking)
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -197,8 +191,7 @@ export function createCreateHandler(events: EventEmitter) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Trigger init script asynchronously after response
|
// Trigger init script asynchronously after response
|
||||||
if (hasInitScript && !alreadyRan) {
|
// runInitScript internally checks if script exists and hasn't already run
|
||||||
logger.info(`Triggering init script for worktree: ${branchName}`);
|
|
||||||
runInitScript({
|
runInitScript({
|
||||||
projectPath,
|
projectPath,
|
||||||
worktreePath: absoluteWorktreePath,
|
worktreePath: absoluteWorktreePath,
|
||||||
@@ -207,7 +200,6 @@ export function createCreateHandler(events: EventEmitter) {
|
|||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
logger.error(`Init script failed for ${branchName}:`, err);
|
logger.error(`Init script failed for ${branchName}:`, err);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(error, 'Create worktree failed');
|
logError(error, 'Create worktree failed');
|
||||||
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ function getInitScriptPath(projectPath: string): string {
|
|||||||
export function createGetInitScriptHandler() {
|
export function createGetInitScriptHandler() {
|
||||||
return async (req: Request, res: Response): Promise<void> => {
|
return async (req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectPath } = req.body as { projectPath: string };
|
const projectPath = req.query.projectPath as string;
|
||||||
|
|
||||||
if (!projectPath) {
|
if (!projectPath) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'projectPath is required',
|
error: 'projectPath query parameter is required',
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -142,18 +142,11 @@ export function createDeleteInitScriptHandler() {
|
|||||||
|
|
||||||
const scriptPath = getInitScriptPath(projectPath);
|
const scriptPath = getInitScriptPath(projectPath);
|
||||||
|
|
||||||
try {
|
|
||||||
await secureFs.rm(scriptPath, { force: true });
|
await secureFs.rm(scriptPath, { force: true });
|
||||||
logger.info(`Deleted init script at ${scriptPath}`);
|
logger.info(`Deleted init script at ${scriptPath}`);
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
} catch {
|
|
||||||
// File doesn't exist - still success
|
|
||||||
res.json({
|
|
||||||
success: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(error, 'Delete init script failed');
|
logError(error, 'Delete init script failed');
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
|
|||||||
@@ -150,10 +150,12 @@ export class InitScriptService {
|
|||||||
: 'No shell found (/bin/bash or /bin/sh)';
|
: 'No shell found (/bin/bash or /bin/sh)';
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
|
||||||
// Update metadata with error
|
// Update metadata with error, preserving existing metadata
|
||||||
|
const existingMetadata = await readWorktreeMetadata(projectPath, branch);
|
||||||
await writeWorktreeMetadata(projectPath, branch, {
|
await writeWorktreeMetadata(projectPath, branch, {
|
||||||
branch,
|
branch,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: existingMetadata?.createdAt || new Date().toISOString(),
|
||||||
|
pr: existingMetadata?.pr,
|
||||||
initScriptRan: true,
|
initScriptRan: true,
|
||||||
initScriptStatus: 'failed',
|
initScriptStatus: 'failed',
|
||||||
initScriptError: error,
|
initScriptError: error,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
PanelBottomClose,
|
PanelBottomClose,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { apiPost, apiPut, apiDelete } from '@/lib/api-fetch';
|
import { apiGet, apiPut, apiDelete } from '@/lib/api-fetch';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { useAppStore } from '@/store/app-store';
|
import { useAppStore } from '@/store/app-store';
|
||||||
|
|
||||||
@@ -77,9 +77,9 @@ export function WorktreesSection({ useWorktrees, onUseWorktreesChange }: Worktre
|
|||||||
const loadInitScript = async () => {
|
const loadInitScript = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await apiPost<InitScriptResponse>('/api/worktree/init-script', {
|
const response = await apiGet<InitScriptResponse>(
|
||||||
projectPath: currentProject.path,
|
`/api/worktree/init-script?projectPath=${encodeURIComponent(currentProject.path)}`
|
||||||
});
|
);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
const content = response.content || '';
|
const content = response.content || '';
|
||||||
setScriptContent(content);
|
setScriptContent(content);
|
||||||
|
|||||||
@@ -1613,7 +1613,8 @@ export class HttpApiClient implements ElectronAPI {
|
|||||||
getPRInfo: (worktreePath: string, branchName: string) =>
|
getPRInfo: (worktreePath: string, branchName: string) =>
|
||||||
this.post('/api/worktree/pr-info', { worktreePath, branchName }),
|
this.post('/api/worktree/pr-info', { worktreePath, branchName }),
|
||||||
// Init script methods
|
// Init script methods
|
||||||
getInitScript: (projectPath: string) => this.post('/api/worktree/init-script', { projectPath }),
|
getInitScript: (projectPath: string) =>
|
||||||
|
this.get(`/api/worktree/init-script?projectPath=${encodeURIComponent(projectPath)}`),
|
||||||
setInitScript: (projectPath: string, content: string) =>
|
setInitScript: (projectPath: string, content: string) =>
|
||||||
this.put('/api/worktree/init-script', { projectPath, content }),
|
this.put('/api/worktree/init-script', { projectPath, content }),
|
||||||
deleteInitScript: (projectPath: string) =>
|
deleteInitScript: (projectPath: string) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user