Skip to content

feat: add base_branch input to specify source branch for new Claude branches #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2025

Conversation

ashwin-ant
Copy link
Collaborator

Implements the ability to specify which branch Claude checks out from when creating new branches.

Changes

  • Add base_branch input parameter to action.yml
  • Update setupBranch function to use specified base branch
  • Maintain backward compatibility by defaulting to repository default branch

Usage

Users can now specify a base branch in their workflow:

- uses: anthropics/claude-code-action@main
  with:
    base_branch: "dev"

Closes #62

Generated with Claude Code

…ranches

- 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 <[email protected]>
Copy link
Contributor

claude bot commented May 28, 2025

Claude finished @ashwin-ant's task —— View job


Code Review for PR #72

Reviewing the base_branch input feature implementation.

Tasks:

  • Read and analyze changed files
  • Review code quality and implementation
  • Check for potential bugs or issues
  • Provide comprehensive feedback

Review Summary

This PR successfully implements the base_branch input feature to allow specifying which branch Claude should use as the source when creating new branches. The implementation is clean, well-structured, and maintains backward compatibility.

✅ Strengths

  1. Clear and intuitive API design: The base_branch input in action.yml:15-17 is well-documented with a clear description
  2. Proper backward compatibility: Falls back to repository default branch when no base_branch is specified (branch.ts:40)
  3. Clean parameter threading: The parameter flows properly from action input → environment variable → function parameter
  4. Consistent logging: Good debug output showing which source branch is being used (branch.ts:74)
  5. Maintains existing functionality: No breaking changes to current behavior

🔍 Code Quality Analysis

action.yml changes

  • Input definition follows existing patterns
  • Proper placement in the inputs section
  • Clear description for users

prepare.ts changes

  • Minimal, targeted change to pass the base branch parameter
  • Follows existing pattern for environment variable access

branch.ts changes

  • Clean implementation of the base branch logic
  • Good variable naming (sourceBranch)
  • Proper error handling preserved
  • Logging clearly indicates which branch is being used as source

🎯 Architecture & Design

The design is solid and follows the existing codebase patterns:

  • Input flows: action.yml → environment variable → prepare.ts → setupBranch function
  • Maintains the same branch creation logic for both issues and closed/merged PRs
  • Only affects new branch creation, not existing PR checkout behavior

⚠️ Minor Considerations

  1. Input validation: Consider validating that the specified base_branch exists before attempting to use it. Currently, if a non-existent branch is specified, the error will occur during git.getRef() call (branch.ts:87-91), which provides a reasonable error message but could be more user-friendly.

  2. Documentation: While the action.yml description is clear, consider adding this feature to any user-facing documentation or examples.

🚀 Testing Considerations

The implementation should be tested with:

  • Valid base branch (e.g., "dev", "staging")
  • Invalid/non-existent base branch
  • No base branch specified (default behavior)
  • Both issue and PR scenarios

📋 Final Assessment

This is a well-implemented feature that:

The code is ready for merge. The minor input validation suggestion is optional - the current error handling via Git API calls is adequate.

@@ -34,6 +35,9 @@ export async function setupBranch(
repo,
});
const defaultBranch = repoResponse.data.default_branch;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's a baseBranch provided let's not even fetch the default branch @claude

Copy link
Contributor

@claude claude bot May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude finished @ashwin-ant's task —— View job


Optimizing branch setup logic ✅

Good catch! I optimized the setupBranch function to avoid fetching the default branch when baseBranch is already provided.

Tasks:

  • Read current setupBranch implementation
  • Identify inefficient default branch fetch
  • Refactor to conditionally fetch only when needed
  • Run formatting checks (no Bash access)
  • Commit optimized code

Optimization completed: Modified the function to only fetch the repository default branch when actually needed:

  • When baseBranch is provided, we skip the initial default branch fetch
  • Default branch is only fetched at the very end for return value and GitHub Actions output
  • This eliminates an unnecessary API call in the common case where users specify a base branch

Changes pushed to claude/issue-62-20250527_192138 in commit 1fda575.

claude bot and others added 3 commits May 28, 2025 00:17
Only fetch repository default branch when actually needed:
- Skip initial fetch when baseBranch is provided
- Fetch default branch at end only for return value and GitHub Actions output
- Eliminates unnecessary API call when users specify base branch

Co-authored-by: ashwin-ant <[email protected]>
- Fix TypeScript error where defaultBranch was used before being assigned
- Replace DEFAULT_BRANCH with BASE_BRANCH in subsequent workflow steps
- Update PR creation and branch comparison to use the actual base branch
- Ensure custom base_branch input is respected in all operations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Move BASE_BRANCH environment variable reading into parseGitHubContext for consistency
- Update setupBranch to use context.inputs.baseBranch instead of process.env
- Fix test descriptions to correctly reference BASE_BRANCH instead of DEFAULT_BRANCH
- Update test environment setup to use BASE_BRANCH

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ashwin-ant
Copy link
Collaborator Author

@claude did i miss anything here

@ashwin-ant ashwin-ant marked this pull request as ready for review May 29, 2025 04:38
Copy link
Contributor

claude bot commented May 29, 2025

Claude finished @ashwin-ant's task —— View job


Final Review Analysis

Analyzing your base_branch implementation to check for any missing pieces.

Tasks:

  • Review action.yml input definition
  • Analyze branch.ts implementation
  • Check context and prepare.ts changes
  • Review test coverage and edge cases
  • Provide comprehensive feedback

🎯 Review Summary

After thorough analysis, your base_branch implementation looks comprehensive and well-executed. You haven't missed any critical functionality.

✅ What You Got Right

  1. Complete data flow: action.yml:15-17 → environment variable → context.ts:59branch.ts:29 → implementation
  2. Proper optimization: Only fetch default branch when needed (branch.ts:67-77)
  3. Clean API design: Optional input with sensible fallback behavior
  4. Consistent typing: Added to ParsedGitHubContext type correctly
  5. Good error handling: Leverages existing Git API error handling
  6. Backward compatibility: No breaking changes to existing workflows

🔍 Edge Cases Covered

  • ✅ Valid base branch specified
  • ✅ No base branch specified (falls back to default)
  • ✅ Invalid base branch (will error appropriately at Git API level)
  • ✅ Works for both issues and closed/merged PRs
  • ✅ Open PRs correctly ignore the setting (uses PR's own base)

🎨 Implementation Quality

action.yml - Clean input definition with clear description
context.ts - Proper environment variable parsing and type integration
branch.ts - Well-structured logic with good logging and performance optimization
prepare.ts - Minimal, targeted changes following existing patterns

🚀 What You Could Consider (Optional)

  1. Documentation: Consider updating README/examples to showcase this feature
  2. Branch validation: Currently relies on Git API errors for invalid branches - this is perfectly acceptable
  3. Test coverage: May want to add tests for the new parameter (though existing logic is well-tested)

📋 Final Verdict

You haven't missed anything critical. This is a complete, well-implemented feature that:

The implementation is ready for merge! 🎉


@ashwin-ant ashwin-ant merged commit fcbdac9 into main May 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to Determine the branch that Claude checks out from
2 participants