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 5 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.

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.

Comment on lines +5 to +6
public PackageRefNotFoundException(String message) {
super(message);
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 taking any parameters, the message can be directly set here itself.

Comment on lines +42 to +46
if (getPackageAndRepoType(destination)) {
WizardDialog dialog = new WizardDialog(this.AbapGitView.getViewSite().getShell(),
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination));
dialog.open();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (getPackageAndRepoType(destination)) {
WizardDialog dialog = new WizardDialog(this.AbapGitView.getViewSite().getShell(),
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination));
dialog.open();
}
try {
WizardDialog dialog = new WizardDialog(this.AbapGitView.getViewSite().getShell(),
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination));
dialog.open();
} catch (PackageRefNotFoundException | ResourceException e) {
MessageDialog.openError(this.AbapGitView.getViewSite().getShell(), "Switch Branch Wizard Error",
e.getLocalizedMessage());
}
  • The idea is that the repo type and package info is retrieved while creating the object of the wizard
  • This wizard also sends the new exception for package ref not found
  • Also, the post call to backend can possibly throw a ResourceException, in case there is an issue in backend. This can be explicitly handled here.
  • The shell to we can get from the abapgit view

Comment on lines +60 to +81
private void getPackageRef(String packageName, String destination, IProgressMonitor monitor) {
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI();
if (!packageServiceUI.packageExists(destination, packageName, monitor)) {
// Throw PackageRefNotFound Exception if packagerServiceUI can't find package
String error = NLS.bind(Messages.AbapGitWizardSwitch_branch_package_ref_not_found_error, packageName);
throw new PackageRefNotFoundException(error);
}
}

public boolean getPackageAndRepoType(String destination) {
try {
String packageName = this.selRepo.getPackage();
// checking if the package ref exsist
getPackageRef(packageName, destination, null);
return true;
} catch (PackageRefNotFoundException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
String message = (cause.getMessage() != null) ? cause.getMessage() : "An unknown error has occurred"; //$NON-NLS-1$
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.openError(shell, "Error", message); //$NON-NLS-1$
return false;
}
Copy link
Collaborator

@shubhamWaghmare-sap shubhamWaghmare-sap May 15, 2025

Choose a reason for hiding this comment

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

This could be considered redundant as the creation of the wizard already gets the required info and performs the required checks about the package and repository type.
We can remove this logic.

Comment on lines +66 to +72
private void getPackageRef(String packageName, IProgressMonitor monitor) {
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI();
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.

  • From here itself we can throw the exception if package does not exist
  • Also the progress monitor is not needed much here as the wizard is not yet started. So we can pass a null progress monitor

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
private void getPackageRef(String packageName, IProgressMonitor monitor) {
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI();
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);
}
}
private void getPackageRef(String packageName) throws PackageRefNotFoundException {
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI();
if (packageServiceUI.packageExists(AbapGitWizardSwitchBranch.this.destination, packageName, new NullProgressMonitor())) {
List<IAdtObjectReference> packageRefs = packageServiceUI.find(AbapGitWizardSwitchBranch.this.destination, packageName,
new NullProgressMonitor());
AbapGitWizardSwitchBranch.this.cloneData.packageRef = packageRefs.stream().findFirst().orElse(null);
}
else {
throw new PackageRefNotFoundException("Package not found"); //$NON-NLS-1$
}
}

Comment on lines +74 to +100
public boolean getPackageAndRepoType() {

try {
String packageName = AbapGitWizardSwitchBranch.this.selRepoData.getPackage();
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.AbapGitWizardPageBranchAndPackage_task_package_validation_message, IProgressMonitor.UNKNOWN);

// fetches wether the repository is PUBLIC or PRIVATE from external repo info
getRepositoryAccessMode();

// fetches associated package
getPackageRef(packageName, monitor);

}
});
// returns false in case of missing package reference
return this.cloneData.packageRef != null;
} catch (InterruptedException | InvocationTargetException e) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.openError(shell, "Error", e.getMessage()); //$NON-NLS-1$
return false;
}

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The idea is to not handle any exception here.
All exceptions should be handled by the caller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public boolean getPackageAndRepoType() {
try {
String packageName = AbapGitWizardSwitchBranch.this.selRepoData.getPackage();
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.AbapGitWizardPageBranchAndPackage_task_package_validation_message, IProgressMonitor.UNKNOWN);
// fetches wether the repository is PUBLIC or PRIVATE from external repo info
getRepositoryAccessMode();
// fetches associated package
getPackageRef(packageName, monitor);
}
});
// returns false in case of missing package reference
return this.cloneData.packageRef != null;
} catch (InterruptedException | InvocationTargetException e) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.openError(shell, "Error", e.getMessage()); //$NON-NLS-1$
return false;
}
}
public void getPackageAndRepoType() throws PackageRefNotFoundException {
String packageName = AbapGitWizardSwitchBranch.this.selRepoData.getPackage();
// fetches wether the repository is PUBLIC or PRIVATE from external repo info
getRepositoryAccessMode();
// fetches associated package
getPackageRef(packageName);
}

AbapGitWizardPageRepositoryAndCredentials pageCredentials;
AbapGitWizardPageSwitchBranchAndPackage pageBranchAndPackage;

public AbapGitWizardSwitchBranch(IProject project, IRepository selRepo, String destination) {
Copy link
Collaborator

@shubhamWaghmare-sap shubhamWaghmare-sap May 15, 2025

Choose a reason for hiding this comment

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

We will add a throws declaration to the constructor for PackageRefNotFoundException.

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