From db6d3621d7c6a1f33d6a28fc5a03674c54e88e2e Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Tue, 27 May 2025 19:23:38 +0000 Subject: [PATCH] feat: add base_branch input to specify source branch for new Claude branches - Add base_branch input parameter to action.yml allowing users to specify which branch to use as source - Update setupBranch function to accept and use the base branch parameter - Defaults to repository default branch if no base branch is specified - Addresses issue #62 for better branch control Co-authored-by: ashwin-ant --- action.yml | 4 ++++ src/entrypoints/prepare.ts | 3 ++- src/github/operations/branch.ts | 14 +++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 807f351..3d339ed 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,9 @@ inputs: assignee_trigger: description: "The assignee username that triggers the action (e.g. @claude)" required: false + base_branch: + description: "The branch to use as the base/source when creating new branches (defaults to repository default branch)" + required: false # Claude Code configuration model: @@ -85,6 +88,7 @@ runs: env: TRIGGER_PHRASE: ${{ inputs.trigger_phrase }} ASSIGNEE_TRIGGER: ${{ inputs.assignee_trigger }} + BASE_BRANCH: ${{ inputs.base_branch }} ALLOWED_TOOLS: ${{ inputs.allowed_tools }} CUSTOM_INSTRUCTIONS: ${{ inputs.custom_instructions }} DIRECT_PROMPT: ${{ inputs.direct_prompt }} diff --git a/src/entrypoints/prepare.ts b/src/entrypoints/prepare.ts index 1cce680..2708687 100644 --- a/src/entrypoints/prepare.ts +++ b/src/entrypoints/prepare.ts @@ -62,7 +62,8 @@ async function run() { }); // Step 8: Setup branch - const branchInfo = await setupBranch(octokit, githubData, context); + const baseBranch = process.env.BASE_BRANCH; + const branchInfo = await setupBranch(octokit, githubData, context, baseBranch); // Step 9: Update initial comment with branch link (only for issues that created a new branch) if (branchInfo.claudeBranch) { diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index 97bf6e6..c456f96 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -23,6 +23,7 @@ export async function setupBranch( octokits: Octokits, githubData: FetchDataResult, context: ParsedGitHubContext, + baseBranch?: string, ): Promise { const { owner, repo } = context.repository; const entityNumber = context.entityNumber; @@ -34,6 +35,9 @@ export async function setupBranch( repo, }); const defaultBranch = repoResponse.data.default_branch; + + // Use the provided base branch or fall back to default branch + const sourceBranch = baseBranch || defaultBranch; if (isPR) { const prData = githubData.contextData as GitHubPullRequest; @@ -67,7 +71,7 @@ export async function setupBranch( // Creating a new branch for either an issue or closed/merged PR const entityType = isPR ? "pr" : "issue"; - console.log(`Creating new branch for ${entityType} #${entityNumber}...`); + console.log(`Creating new branch for ${entityType} #${entityNumber} from source branch: ${sourceBranch}...`); const timestamp = new Date() .toISOString() @@ -79,14 +83,14 @@ export async function setupBranch( const newBranch = `claude/${entityType}-${entityNumber}-${timestamp}`; try { - // Get the SHA of the default branch - const defaultBranchRef = await octokits.rest.git.getRef({ + // Get the SHA of the source branch + const sourceBranchRef = await octokits.rest.git.getRef({ owner, repo, - ref: `heads/${defaultBranch}`, + ref: `heads/${sourceBranch}`, }); - const currentSHA = defaultBranchRef.data.object.sha; + const currentSHA = sourceBranchRef.data.object.sha; console.log(`Current SHA: ${currentSHA}`);