Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit b9fc12e

Browse files
authored
Fix: resolve SSH url for git menu (#26)
* Fix: resolve ssh url for git menu * Remove utm tags for link sharing * Update to enforce defaultBranch
1 parent 0461c2e commit b9fc12e

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/main/java/CommitViewUriBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ public URI build(String sourcegraphBase, String revisionNumber, RepoInfo repoInf
1515
}
1616

1717
// this is pretty hacky but to try to build the repo string we will just try to naively parse the git remote uri. Worst case scenario this 404s
18-
URI remote = URI.create(repoInfo.remoteURL);
19-
String path = remote.getPath().replace(".git", "");
18+
String remoteURL = repoInfo.remoteURL;
19+
if(remoteURL.startsWith("git")){
20+
remoteURL = repoInfo.remoteURL.replace(".git", "").replaceFirst(":", "/").replace("git@", "https://");;
21+
}
22+
URI remote = URI.create(remoteURL);
23+
String path = remote.getPath();
2024

2125
StringBuilder builder = new StringBuilder();
2226
try {

src/main/java/Copy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ public class Copy extends FileAction {
99

1010
@Override
1111
void handleFileUri(String uri) {
12+
// Remove utm tags for sharing
13+
String shortenURI = uri.replaceAll("(&utm_product_name=)(.*)", "");
1214
// Copy file uri to clipboard
13-
CopyPasteManager.getInstance().setContents(new StringSelection(uri));
15+
CopyPasteManager.getInstance().setContents(new StringSelection(shortenURI));
1416

1517
// Display bubble
1618
Notification notification = new Notification("Sourcegraph", "Sourcegraph",
17-
"File URL copied to clipboard.", NotificationType.INFORMATION);
19+
"File URL copied to clipboard."+shortenURI, NotificationType.INFORMATION);
1820
Notifications.Bus.notify(notification);
1921
}
2022
}

src/main/java/FileAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public void actionPerformed(AnActionEvent e) {
6666
+ "&file=" + URLEncoder.encode(repoInfo.fileRel, "UTF-8")
6767
+ "&editor=" + URLEncoder.encode("JetBrains", "UTF-8")
6868
+ "&version=" + URLEncoder.encode(Util.VERSION, "UTF-8")
69-
+ "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8")
70-
+ "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8")
7169
+ "&start_row=" + URLEncoder.encode(Integer.toString(start.line), "UTF-8")
7270
+ "&start_col=" + URLEncoder.encode(Integer.toString(start.column), "UTF-8")
7371
+ "&end_row=" + URLEncoder.encode(Integer.toString(end.line), "UTF-8")
74-
+ "&end_col=" + URLEncoder.encode(Integer.toString(end.column), "UTF-8");
72+
+ "&end_col=" + URLEncoder.encode(Integer.toString(end.column), "UTF-8")
73+
+ "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8")
74+
+ "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8");
7575
} catch (UnsupportedEncodingException err) {
7676
logger.debug("failed to build URL");
7777
err.printStackTrace();

src/main/java/Util.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ public static RepoInfo repoInfo(String fileName, Project project) {
127127
remoteURL = configuredGitRemoteURL(repoRoot);
128128
branch = Util.setDefaultBranch(project)!=null ? Util.setDefaultBranch(project) : gitBranch(repoRoot);
129129

130-
// If on a branch that does not exist on the remote or if defaultBranch does not exist on the remote,
130+
// If on a branch that does not exist on the remote and no defaultBranch is configured
131131
// use "master" instead.
132-
if (!isRemoteBranch(branch, repoRoot)) {
132+
// This allows users to checkout a branch that does not exist in origin remote by setting defaultBranch
133+
if (!isRemoteBranch(branch, repoRoot) && Util.setDefaultBranch(project)==null) {
133134
branch = "master";
134135
}
135136

136137
// replace remoteURL if config option is not null
137138
String r = Util.setRemoteUrlReplacements(project);
138-
139139
if(r!=null) {
140140
String[] replacements = r.trim().split("\\s*,\\s*");
141141
// Check if the entered values are pairs

0 commit comments

Comments
 (0)