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

Open Repository in ext browser with linked branch #280

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

Conversation

aarnavpant
Copy link

Workflow update:

Earlier:

  • On invoking openRepositoryAction the repository link is opened in default external browser

Now

  • On invoking openRepositoryAction link to open in browser link is generated using combination of branch linked to package and repoLink.
  • Removed deprecated URL generation

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.

Please check the comments & counter if needed.
Also add unit tests in the test plugin.

private static final String GITHUB_DOMAIN = "github.com"; //$NON-NLS-1$
private static final String GITLAB_DOMAIN = "gitlab.com"; //$NON-NLS-1$
private static final String GIT_WDF_SAP_DOMAIN = "github.wdf.sap.corp"; //$NON-NLS-1$
private static final String GITHUB_INFRA_DOMAIN = "github.infra.hana.ondemand.com"; //$NON-NLS-1$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename GITHUB_INFRA_DOMAIN to GITHUB_INFRA_HANA_DOMAIN

Copy link
Author

@aarnavpant aarnavpant Nov 18, 2024

Choose a reason for hiding this comment

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

Yes, changed all occurrences

// Get Repository link
String repoLink = getLink(repository);
// Open the link in default external browser
URI uri = new URI(repoLink);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to first create a URI using the link & then fetch the URL ?
Any specific reason?
Is creating a new URL object with the link not sufficient?

Copy link
Author

Choose a reason for hiding this comment

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

The URL() function is deprecated and when I was going through declaration I found it suggests to use URI.toURL()
uriTourl

@@ -22,6 +23,12 @@
*/
public class OpenRepositoryAction extends Action {
private final IViewPart view;
private static final String GITHUB_DOMAIN = "github.com"; //$NON-NLS-1$
private static final String GITLAB_DOMAIN = "gitlab.com"; //$NON-NLS-1$
private static final String GIT_WDF_SAP_DOMAIN = "github.wdf.sap.corp"; //$NON-NLS-1$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename GIT_WDF_SAP_DOMAIN to GITHUB_WDF_SAP_DOMAIN

Copy link
Author

Choose a reason for hiding this comment

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

Yes, changed all occurrences

Comment on lines 60 to 62
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Exceptions should be logged and if required should also provide feedback to users of the error occured

Add the exception to existing clause, where the error message is shown to users in a MessageDialog & the exception is also logged in the plugin.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, took reference from existing code

// Extract domain by splitting with '/'
domain = domain.split("/")[0]; //$NON-NLS-1$
// Get connected branch
String branch = repository.getBranchName();
Copy link
Collaborator

@shubhamWaghmare-sap shubhamWaghmare-sap Nov 14, 2024

Choose a reason for hiding this comment

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

Move line 76 after line 68 & remove comment for better readability.

Comment on lines 70 to 74
// Remove protocol (http:// or https://)
String domain = repoLink.replaceFirst("https?://", ""); //$NON-NLS-1$ //$NON-NLS-2$

// Extract domain by splitting with '/'
domain = domain.split("/")[0]; //$NON-NLS-1$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if you can create a URI using the repoLink & then getHost from the URI as domain.

Copy link
Author

Choose a reason for hiding this comment

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

Changed string based change to URI class to handle url generation

// handle domain based repoLink generation
if (domain.equals(GITHUB_DOMAIN) || domain.equals(GITLAB_DOMAIN) || domain.equals(GITHUB_TOOLS_DOMAIN)
|| domain.equals(GITHUB_INFRA_DOMAIN) || domain.equals(GIT_WDF_SAP_DOMAIN)) {
branch = branch.replace("refs/heads/", "/tree/"); //$NON-NLS-1$//$NON-NLS-2$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extract refs/heads/ as a constant

|| domain.equals(GITHUB_INFRA_DOMAIN) || domain.equals(GIT_WDF_SAP_DOMAIN)) {
branch = branch.replace("refs/heads/", "/tree/"); //$NON-NLS-1$//$NON-NLS-2$
} else if (domain.endsWith(BIT_BUCKET_DOMAIN)) {
repoLink = repoLink.replaceAll("https://.*?@", "https://"); //$NON-NLS-1$ //$NON-NLS-2$
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also remove the username in BitBucket links by using URI to parse the repoLink.
Then rebuild the URI without userInfo & get URL.

Check constructor for URI:
public URI(String scheme,
String userInfo, String host, int port,
String path, String query, String fragment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also check if other GIT providers can have user info.
In such case, we could have a domain agnostic user info handler.

Copy link
Author

Choose a reason for hiding this comment

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

Didn't get any user info in case of git providers.

}

// return the concatenated link that redirects to the branch
return repoLink + branch;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Handle the case when the domain is not the list that is supported for navigation to branch.
Presently, branch name is added to such domains. Instead unsupported domains should just have repository link for navigation without branch name.

Copy link
Author

Choose a reason for hiding this comment

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

default repoLink is the url, now only if we have supported domain then we will add branch else will be simply redirected to the repo.

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