mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 15:04:13 +08:00
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 <ashwin-ant@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,9 @@ inputs:
|
|||||||
assignee_trigger:
|
assignee_trigger:
|
||||||
description: "The assignee username that triggers the action (e.g. @claude)"
|
description: "The assignee username that triggers the action (e.g. @claude)"
|
||||||
required: false
|
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
|
# Claude Code configuration
|
||||||
model:
|
model:
|
||||||
@@ -85,6 +88,7 @@ runs:
|
|||||||
env:
|
env:
|
||||||
TRIGGER_PHRASE: ${{ inputs.trigger_phrase }}
|
TRIGGER_PHRASE: ${{ inputs.trigger_phrase }}
|
||||||
ASSIGNEE_TRIGGER: ${{ inputs.assignee_trigger }}
|
ASSIGNEE_TRIGGER: ${{ inputs.assignee_trigger }}
|
||||||
|
BASE_BRANCH: ${{ inputs.base_branch }}
|
||||||
ALLOWED_TOOLS: ${{ inputs.allowed_tools }}
|
ALLOWED_TOOLS: ${{ inputs.allowed_tools }}
|
||||||
CUSTOM_INSTRUCTIONS: ${{ inputs.custom_instructions }}
|
CUSTOM_INSTRUCTIONS: ${{ inputs.custom_instructions }}
|
||||||
DIRECT_PROMPT: ${{ inputs.direct_prompt }}
|
DIRECT_PROMPT: ${{ inputs.direct_prompt }}
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ async function run() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Step 8: Setup branch
|
// 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)
|
// Step 9: Update initial comment with branch link (only for issues that created a new branch)
|
||||||
if (branchInfo.claudeBranch) {
|
if (branchInfo.claudeBranch) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export async function setupBranch(
|
|||||||
octokits: Octokits,
|
octokits: Octokits,
|
||||||
githubData: FetchDataResult,
|
githubData: FetchDataResult,
|
||||||
context: ParsedGitHubContext,
|
context: ParsedGitHubContext,
|
||||||
|
baseBranch?: string,
|
||||||
): Promise<BranchInfo> {
|
): Promise<BranchInfo> {
|
||||||
const { owner, repo } = context.repository;
|
const { owner, repo } = context.repository;
|
||||||
const entityNumber = context.entityNumber;
|
const entityNumber = context.entityNumber;
|
||||||
@@ -35,6 +36,9 @@ export async function setupBranch(
|
|||||||
});
|
});
|
||||||
const defaultBranch = repoResponse.data.default_branch;
|
const defaultBranch = repoResponse.data.default_branch;
|
||||||
|
|
||||||
|
// Use the provided base branch or fall back to default branch
|
||||||
|
const sourceBranch = baseBranch || defaultBranch;
|
||||||
|
|
||||||
if (isPR) {
|
if (isPR) {
|
||||||
const prData = githubData.contextData as GitHubPullRequest;
|
const prData = githubData.contextData as GitHubPullRequest;
|
||||||
const prState = prData.state;
|
const prState = prData.state;
|
||||||
@@ -67,7 +71,7 @@ export async function setupBranch(
|
|||||||
|
|
||||||
// Creating a new branch for either an issue or closed/merged PR
|
// Creating a new branch for either an issue or closed/merged PR
|
||||||
const entityType = isPR ? "pr" : "issue";
|
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()
|
const timestamp = new Date()
|
||||||
.toISOString()
|
.toISOString()
|
||||||
@@ -79,14 +83,14 @@ export async function setupBranch(
|
|||||||
const newBranch = `claude/${entityType}-${entityNumber}-${timestamp}`;
|
const newBranch = `claude/${entityType}-${entityNumber}-${timestamp}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the SHA of the default branch
|
// Get the SHA of the source branch
|
||||||
const defaultBranchRef = await octokits.rest.git.getRef({
|
const sourceBranchRef = await octokits.rest.git.getRef({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
ref: `heads/${defaultBranch}`,
|
ref: `heads/${sourceBranch}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentSHA = defaultBranchRef.data.object.sha;
|
const currentSHA = sourceBranchRef.data.object.sha;
|
||||||
|
|
||||||
console.log(`Current SHA: ${currentSHA}`);
|
console.log(`Current SHA: ${currentSHA}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user