Skip to content

Switch branch Action #286

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aarnapant-sap
Copy link
Contributor

@aarnapant-sap aarnapant-sap commented Jan 3, 2025

Switch Branch Functionality in AbapGit

  • User can now switch branch for the linked repository without explicitly unlinking and relinking.
  • SwitchBranchAction is added to context menu in AbapGitRepository view.
  • added pde tests for switchBranchWizard

@shubhamWaghmare-sap
Copy link
Collaborator

Remove the backlog link from the description. Instead add some description of what the pull request solves.

  • backlog link click here support for branch switching for a linked repository

@shubhamWaghmare-sap
Copy link
Collaborator

@aarnapant-sap Please also test the solution in a ABAP Cloud system, involving transport requests.

Copy link
Collaborator

@shubhamWaghmare-sap shubhamWaghmare-sap left a comment

Choose a reason for hiding this comment

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

Hi Aarnav,
Overall looks good.
I have added some comments and questions. Please check them.

public class SwitchbranchAction extends Action {

private IRepository selRepo;
private final IViewPart AbapGitView;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can keep this view variable typed to AbapGitView itself i.e. private final AbapGitView view.

Comment on lines +9 to +10
public AbapGitWizardPageSwitchBranchAndPackage(IProject project, String destination, CloneData cloneData, Boolean pullAction) {
super(project, destination, cloneData, pullAction);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Like in case of credentials page, here as well the pullAction will be false always.
We can remove the parameter pullAction in the constructor and set pullAction as false for the super constructor.

Comment on lines +53 to +57
if (!getPackageAndRepoType()) {
this.isPackageValid = false;
this.packageErrorMessage = NLS.bind(Messages.AbapGitWizardSwitch_branch_package_ref_not_found_error,
this.selRepoData.getPackage());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error message will be set even in case there was an exception from backend while fetching the repo type as the logic depends only on whether the method getPackageAndRepoType returns false.

Comment on lines +102 to +103
((WizardPage) getContainer().getCurrentPage()).setPageComplete(false);
((WizardPage) getContainer().getCurrentPage()).setMessage(e.getMessage(), DialogPage.ERROR);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will lead to runtime error as there is no Wizard yet initialized, similar to the package error handling.
So in this case as well, better to show the error in MessageDialog.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of handling the exception here, let's propagate the exception to caller & handle the exception where we open the wizard i.e. in SwitchBranchAction.
So even before opening the wizard, if there is an exception while creating the object of AbapGitWizardSwitchBranch we show error in MessageDialog.

Comment on lines +75 to +78
if (packageServiceUI.packageExists(AbapGitWizardSwitchBranch.this.destination, packageName, monitor)) {
List<IAdtObjectReference> packageRefs = packageServiceUI.find(AbapGitWizardSwitchBranch.this.destination, packageName, monitor);
AbapGitWizardSwitchBranch.this.cloneData.packageRef = packageRefs.stream().findFirst().orElse(null);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case the package does not exist, let's create new exception class and throw this new exception. Check more comment below.

Comment on lines +125 to +134
if (!this.isPackageValid) {
// show error message
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.openError(shell, "Error", this.packageErrorMessage != null ? this.packageErrorMessage : "Unknown error"); //$NON-NLS-1$ //$NON-NLS-2$

if (getContainer() instanceof WizardDialog) {
((WizardDialog) getContainer()).close();
}
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of handling the package validation in addPages, it would make more sense if we performed the validation before even opening the wizard.
Hence, the new exception mentioned above.

In case the package ref is initial, instead of handling it in addPages, an exception would be thrown that can be handled in SwitchBranchAction & this logic can be moved to SwitchBranchAction to handle the new exception.

This is a cleaner approach.

Comment on lines +17 to +18
public class TestPdeAbapGitRepositoriesSelectionWizard {

Copy link
Collaborator

Choose a reason for hiding this comment

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

  • More test cases can be covered like invalid package or exception while fetching repo type.
  • Also a UI test can be added to open the wizard, validate the fields in first page, then navigate to next page and validate if the branches are correctly set as input for combo viewer, and switch the branch in combo viewer. The Finish action can be skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants