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
17 changes: 17 additions & 0 deletions src/automation/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ export async function getCurrentBranch(cwd: string): Promise<string> {
return branch.trim();
}

export async function getDefaultBranch(cwd: string): Promise<string> {
try {
const { stdout } = await execa('git', ['symbolic-ref', 'refs/remotes/origin/HEAD', '--short'], {
cwd,
});
// Returns e.g. "origin/main" — strip the "origin/" prefix
return stdout.trim().replace(/^origin\//, '');
} catch {
// Fallback: check if main or master exists
const git: SimpleGit = simpleGit({ baseDir: cwd });
const branches = await git.branchLocal();
if (branches.all.includes('main')) return 'main';
if (branches.all.includes('master')) return 'master';
return 'main'; // Final fallback
}
}

export async function createBranch(cwd: string, branchName: string): Promise<void> {
const git: SimpleGit = simpleGit({ baseDir: cwd });
await git.checkoutLocalBranch(branchName);
Expand Down
13 changes: 10 additions & 3 deletions src/loop/task-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createBranch,
createPullRequest,
getCurrentBranch,
getDefaultBranch,
gitCommit,
gitPush,
hasUncommittedChanges,
Expand Down Expand Up @@ -91,6 +92,7 @@ export async function executeTaskBatch(options: TaskExecutionOptions): Promise<T

const results: TaskResult[] = [];
const originalBranch = await getCurrentBranch(cwd);
const defaultBranch = await getDefaultBranch(cwd);
let previousBranch = originalBranch; // Track for cascading PRs

for (let i = 0; i < tasks.length; i++) {
Expand Down Expand Up @@ -154,11 +156,16 @@ export async function executeTaskBatch(options: TaskExecutionOptions): Promise<T

if (pr) {
// Create PR with cascading base:
// First PR targets original branch (main)
// First PR targets the default branch (main/master)
// Subsequent PRs target the previous auto branch
const prBase = i === 0 ? originalBranch : previousBranch;
const prBase = i === 0 ? defaultBranch : previousBranch;
// Strip existing conventional commit prefix to avoid duplication (e.g. "feat: feat:")
const cleanTitle = task.title.replace(
/^(feat|fix|chore|docs|refactor|test|style|ci|perf|build):\s*/i,
''
);
const prUrl = await createPullRequest(cwd, {
title: `feat: ${task.title}`,
title: `feat: ${cleanTitle}`,
body: buildPrBody(task, result, prBase),
base: prBase,
});
Expand Down
Loading