feat: enhance pr dialog base branch selection#489
Conversation
- Updated the list-branches endpoint to accept an optional parameter for including remote branches. - Implemented logic to fetch and deduplicate remote branches alongside local branches. - Modified the CreatePRDialog component to utilize the updated API for branch selection, allowing users to select from both local and remote branches.
Summary of ChangesHello @Shironex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the user experience when creating a pull request by upgrading the base branch selection mechanism. Instead of a simple input field, users now benefit from an autocomplete component that populates with a comprehensive list of both local and remote branches, making it easier to select the correct target for their pull request. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request enhances the 'Create Pull request' dialog by fetching and displaying remote branches for base branch selection. The backend changes in list-branches.ts correctly add an option to include remote branches, and the frontend is updated to use this via a new BranchAutocomplete component.
My review includes two main points:
- A high-severity fix in the backend logic in
list-branches.tsto ensure that remote branches are not incorrectly filtered out when a local branch with the same name exists. This is crucial for allowing users to select common base branches likeorigin/main. - A refactoring suggestion in
create-pr-dialog.tsxto reduce code duplication and improve the maintainability of the state reset logic.
Overall, the changes are well-structured and address the feature requirement effectively. Once the suggested fix is applied, the functionality will be more robust.
| // Extract the branch name without the remote prefix for deduplication | ||
| // e.g., "origin/main" -> "main" | ||
| const branchNameWithoutRemote = cleanName.replace(/^[^/]+\//, ''); | ||
|
|
||
| // Only add remote branches that don't exist locally (to avoid duplicates) | ||
| if (!localBranchNames.has(branchNameWithoutRemote)) { | ||
| branches.push({ | ||
| name: cleanName, // Keep full name like "origin/main" | ||
| isCurrent: false, | ||
| isRemote: true, | ||
| }); | ||
| } |
There was a problem hiding this comment.
The current deduplication logic incorrectly prevents remote branches from being listed if a local branch with the same base name exists. For example, if a local main branch exists, the remote origin/main will be excluded. This is problematic when selecting a base branch for a pull request, as the user is then unable to select common upstream branches like origin/main or origin/develop.
To fix this, the check should compare against the full remote branch name (cleanName) to avoid adding a remote branch only if a local branch with the exact same name exists (e.g., a local branch literally named origin/main). This ensures all valid remote targets are available for selection.
// Only add remote branches if a branch with the exact same name isn't already
// in the list. This avoids duplicates if a local branch is named like a remote one.
// The previous logic incorrectly stripped the remote prefix, which prevented
// `origin/main` from being shown if a local `main` branch existed.
if (!localBranchNames.has(cleanName)) {
branches.push({
name: cleanName, // Keep full name like "origin/main"
isCurrent: false,
isRemote: true,
});
}…nch exists The branch listing logic now correctly shows remote branches (e.g., "origin/main") even if a local branch with the same base name exists, since users need remote branches as PR base targets. Also extracted duplicate state reset logic in create-pr-dialog into a reusable function.
Preview