mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-21 11:23:07 +00:00
Improve pull request flow, add branch selection for worktree creation, fix auto-mode concurrency count (#787)
* Changes from fix/fetch-before-pull-fetch * feat: Improve pull request flow, add branch selection for worktree creation, fix for automode concurrency count * feat: Add validation for remote names and improve error handling * Address PR comments and mobile layout fixes * ``` refactor: Extract PR target resolution logic into dedicated service ``` * feat: Add app shell UI and improve service imports. Address PR comments * fix: Improve security validation and cache handling in git operations * feat: Add GET /list endpoint and improve parameter handling * chore: Improve validation, accessibility, and error handling across apps * chore: Format vite server port configuration * fix: Add error handling for gh pr list command and improve offline fallbacks * fix: Preserve existing PR creation time and improve remote handling
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Extracted from worktree merge route to allow internal service calls.
|
||||
*/
|
||||
|
||||
import { createLogger, isValidBranchName } from '@automaker/utils';
|
||||
import { createLogger, isValidBranchName, isValidRemoteName } from '@automaker/utils';
|
||||
import { type EventEmitter } from '../lib/events.js';
|
||||
import { execGitCommand } from '@automaker/git-utils';
|
||||
const logger = createLogger('MergeService');
|
||||
@@ -13,6 +13,8 @@ export interface MergeOptions {
|
||||
squash?: boolean;
|
||||
message?: string;
|
||||
deleteWorktreeAndBranch?: boolean;
|
||||
/** Remote name to fetch from before merging (defaults to 'origin') */
|
||||
remote?: string;
|
||||
}
|
||||
|
||||
export interface MergeServiceResult {
|
||||
@@ -35,7 +37,11 @@ export interface MergeServiceResult {
|
||||
* @param branchName - Source branch to merge
|
||||
* @param worktreePath - Path to the worktree (used for deletion if requested)
|
||||
* @param targetBranch - Branch to merge into (defaults to 'main')
|
||||
* @param options - Merge options (squash, message, deleteWorktreeAndBranch)
|
||||
* @param options - Merge options
|
||||
* @param options.squash - If true, perform a squash merge
|
||||
* @param options.message - Custom merge commit message
|
||||
* @param options.deleteWorktreeAndBranch - If true, delete worktree and branch after merge
|
||||
* @param options.remote - Remote name to fetch from before merging (defaults to 'origin')
|
||||
*/
|
||||
export async function performMerge(
|
||||
projectPath: string,
|
||||
@@ -88,6 +94,33 @@ export async function performMerge(
|
||||
};
|
||||
}
|
||||
|
||||
// Validate the remote name to prevent git option injection.
|
||||
// Reject invalid remote names so the caller knows their input was wrong,
|
||||
// consistent with how invalid branch names are handled above.
|
||||
const remote = options?.remote || 'origin';
|
||||
if (!isValidRemoteName(remote)) {
|
||||
logger.warn('Invalid remote name supplied to merge-service', {
|
||||
remote,
|
||||
projectPath,
|
||||
});
|
||||
return {
|
||||
success: false,
|
||||
error: `Invalid remote name: "${remote}"`,
|
||||
};
|
||||
}
|
||||
|
||||
// Fetch latest from remote before merging to ensure we have up-to-date refs
|
||||
try {
|
||||
await execGitCommand(['fetch', remote], projectPath);
|
||||
} catch (fetchError) {
|
||||
logger.warn('Failed to fetch from remote before merge; proceeding with local refs', {
|
||||
remote,
|
||||
projectPath,
|
||||
error: (fetchError as Error).message,
|
||||
});
|
||||
// Non-fatal: proceed with local refs if fetch fails (e.g. offline)
|
||||
}
|
||||
|
||||
// Emit merge:start after validating inputs
|
||||
emitter?.emit('merge:start', { branchName, targetBranch: mergeTo, worktreePath });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user