mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +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());
|
||||
|
||||
// Init script routes
|
||||
router.post('/init-script', validatePathParams('projectPath'), createGetInitScriptHandler());
|
||||
router.get('/init-script', createGetInitScriptHandler());
|
||||
router.put('/init-script', validatePathParams('projectPath'), createPutInitScriptHandler());
|
||||
router.delete('/init-script', validatePathParams('projectPath'), createDeleteInitScriptHandler());
|
||||
router.post(
|
||||
|
||||
@@ -22,8 +22,7 @@ import {
|
||||
} from '../common.js';
|
||||
import { trackBranch } from './branch-tracking.js';
|
||||
import { createLogger } from '@automaker/utils';
|
||||
import { runInitScript, getInitScriptPath, hasInitScriptRun } from '../../../services/init-script-service.js';
|
||||
import fs from 'fs';
|
||||
import { runInitScript } from '../../../services/init-script-service.js';
|
||||
|
||||
const logger = createLogger('Worktree');
|
||||
|
||||
@@ -181,11 +180,6 @@ export function createCreateHandler(events: EventEmitter) {
|
||||
// normalizePath converts to forward slashes for API consistency
|
||||
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)
|
||||
res.json({
|
||||
success: true,
|
||||
@@ -197,17 +191,15 @@ export function createCreateHandler(events: EventEmitter) {
|
||||
});
|
||||
|
||||
// Trigger init script asynchronously after response
|
||||
if (hasInitScript && !alreadyRan) {
|
||||
logger.info(`Triggering init script for worktree: ${branchName}`);
|
||||
runInitScript({
|
||||
projectPath,
|
||||
worktreePath: absoluteWorktreePath,
|
||||
branch: branchName,
|
||||
emitter: events,
|
||||
}).catch((err) => {
|
||||
logger.error(`Init script failed for ${branchName}:`, err);
|
||||
});
|
||||
}
|
||||
// runInitScript internally checks if script exists and hasn't already run
|
||||
runInitScript({
|
||||
projectPath,
|
||||
worktreePath: absoluteWorktreePath,
|
||||
branch: branchName,
|
||||
emitter: events,
|
||||
}).catch((err) => {
|
||||
logger.error(`Init script failed for ${branchName}:`, err);
|
||||
});
|
||||
} catch (error) {
|
||||
logError(error, 'Create worktree failed');
|
||||
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
||||
|
||||
@@ -33,12 +33,12 @@ function getInitScriptPath(projectPath: string): string {
|
||||
export function createGetInitScriptHandler() {
|
||||
return async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { projectPath } = req.body as { projectPath: string };
|
||||
const projectPath = req.query.projectPath as string;
|
||||
|
||||
if (!projectPath) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'projectPath is required',
|
||||
error: 'projectPath query parameter is required',
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -142,18 +142,11 @@ export function createDeleteInitScriptHandler() {
|
||||
|
||||
const scriptPath = getInitScriptPath(projectPath);
|
||||
|
||||
try {
|
||||
await secureFs.rm(scriptPath, { force: true });
|
||||
logger.info(`Deleted init script at ${scriptPath}`);
|
||||
res.json({
|
||||
success: true,
|
||||
});
|
||||
} catch {
|
||||
// File doesn't exist - still success
|
||||
res.json({
|
||||
success: true,
|
||||
});
|
||||
}
|
||||
await secureFs.rm(scriptPath, { force: true });
|
||||
logger.info(`Deleted init script at ${scriptPath}`);
|
||||
res.json({
|
||||
success: true,
|
||||
});
|
||||
} catch (error) {
|
||||
logError(error, 'Delete init script failed');
|
||||
res.status(500).json({
|
||||
|
||||
Reference in New Issue
Block a user