Skip to content
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

Enhance Branch Creation UX and Refactor Issue Branch Management #6278

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

amrshadid
Copy link

@amrshadid amrshadid commented Oct 13, 2024

This PR introduces significant improvements to the branch creation and management process, focusing on enhancing the user experience and refactoring the existing code for better maintainability and performance. Key changes include:

  • Branch Selection UI Overhaul:

    • Introduced a QuickPick interface for selecting branches, allowing users to choose from existing local/remote branches or create a new one.
    • Visually highlighted branches related to the issue (e.g., branches containing the issue number).
    • Provided a custom branch name option directly in the selection UI for flexible branch creation.

Some Related Issues:

  • #2243: Detect and use already-linked PR branches when starting work on an issue.
  • #4120: Detect branch names referencing an issue and automatically start working on them.
  • #4509: Improve transparency when creating and checking out branches for issues.

These issues are addressed by improving the branch selection experience, handling remote branches more seamlessly, and enhancing error feedback.

Testing and Verification:

  • Manual Testing:

    • Verified that the QuickPick interface correctly displays existing branches and suggested branch names.
    • Tested creation and checkout of local and remote branches.
    • Confirmed proper upstream tracking for remote branches.
    • Ensured that validation errors (e.g., invalid branch names) display appropriate messages.

- Implemented a `QuickPick` menu for smoother branch selection and creation process.
- Highlighted suggested branch names with visual cues for better user experience.
- Enhanced handling of remote branches, ensuring upstream is set automatically when needed.
- Removed unnecessary methods (`offerNewBranch`, `getBranchTitle`) to simplify code and improve maintainability.
- Improved branch name validation and error messages to provide more helpful feedback.
@amrshadid
Copy link
Author

@microsoft-github-policy-service agree

Copy link

@nightscorn nightscorn left a comment

Choose a reason for hiding this comment

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

cxc

Copy link

@nightscorn nightscorn left a comment

Choose a reason for hiding this comment

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

ujghm

Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! It looks like there are a lot of changes in here that aren't strictly related to the feature you're adding, which makes it slow to review. Could you please remove these changes? I've also left a few other comments.

src/issues/currentIssue.ts Show resolved Hide resolved
src/issues/currentIssue.ts Show resolved Hide resolved
amrshadid and others added 2 commits October 18, 2024 17:38
- Refactored getBranchTitle() to correctly apply the ISSUE_BRANCH_TITLE setting by using variableSubstitution().
- Improved handling of the silent flag.
- Cleaned up unrelated code changes.
@amrshadid
Copy link
Author

@alexr00 Thanks for the feedback! I’ve addressed the specific comments and focused on ensuring the necessary changes related to the feature.

@amrshadid amrshadid requested a review from alexr00 October 29, 2024 10:21
@amrshadid amrshadid requested a review from nightscorn October 29, 2024 22:21
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@amrshadid, thanks for your patience! I've left some suggestions and comments.

@@ -130,19 +129,30 @@ export class CurrentIssue extends Disposable {
return undefined;
}

private async createOrCheckoutBranch(branch: string): Promise<boolean> {
private async createOrCheckoutBranch(branch: string, silent: boolean): Promise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

Does this really need a silent? It seems like something that would always be useful to know if it failed.

private showBranchNameError(error: string) {
const editSetting = `Edit Setting`;
vscode.window.showErrorMessage(error, editSetting).then(result => {
private showBranchNameError(error: string, silent: boolean) {
Copy link
Member

Choose a reason for hiding this comment

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

Same for this. I think if the branch name is bad then we should always show an error.

@@ -130,19 +129,30 @@ export class CurrentIssue extends Disposable {
return undefined;
}

Copy link
Member

Choose a reason for hiding this comment

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

Checking that the branch name starts with origin/ isn't enough, as not all remotes will be named origin.

Suggested change
private getRemoteBranchPrefix(branch: string): string | undefined {
const remote = this.manager.repository.state.remotes.find((remote) => {
return branch.startsWith(`${remote.name}/`);
});
return remote ? `${remote.name}/` : undefined;
}

Comment on lines +135 to +137
const isRemoteBranch = branch.startsWith('origin/');
if (isRemoteBranch) {
localBranchName = branch.substring('origin/'.length);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isRemoteBranch = branch.startsWith('origin/');
if (isRemoteBranch) {
localBranchName = branch.substring('origin/'.length);
const remoteBranchPrefix = this.getRemoteBranchPrefix(branch);
if (remoteBranchPrefix) {
localBranchName = branch.substring(remoteBranchPrefix.length);

const localBranch = await this.getBranch(localBranchName);
if (localBranch) {
await this.manager.repository.checkout(localBranchName);
} else if (isRemoteBranch) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else if (isRemoteBranch) {
} else if (remoteBranchPrefix) {

);

// Show QuickPick for branch selection
const quickPick = vscode.window.createQuickPick<vscode.QuickPickItem>();
Copy link
Member

Choose a reason for hiding this comment

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

Can you just use showQuickPick here instead of the more complicated createQuickPick?


// Create QuickPick items
const branchItems: vscode.QuickPickItem[] = [
{ label: 'Suggested branch', kind: vscode.QuickPickItemKind.Separator },
Copy link
Member

Choose a reason for hiding this comment

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

All the strings should be localized with vscode.l10n.t


branchItems.push(
{ label: 'Custom branch name:', kind: vscode.QuickPickItemKind.Separator },
{ label: '$(pencil) Enter a custom branch name...', description: 'Choose this to type your own branch name' }
Copy link
Member

Choose a reason for hiding this comment

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

Since this string is used again further down, it would be better to move it into a const, especially after it's been localized.


this._branchName = customBranchName.trim();
} else {
this._branchName = selectedBranch.label.replace(/^\$\([^\)]+\)\s*/, '').trim();
Copy link
Member

Choose a reason for hiding this comment

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

Instead of futzing with the label after the branch has been picked, you can extend QuickPickItem and add a new property to it to track the actual branch name associated with the quick pick item.

{ label: '$(pencil) Enter a custom branch name...', description: 'Choose this to type your own branch name' }
);

// Show QuickPick for branch selection
Copy link
Member

Choose a reason for hiding this comment

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

We should only show the quick pick if createBranchConfig === 'prompt.

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.

4 participants