github: fix 'open in browser' url
authorAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Fri, 21 Feb 2014 13:59:54 +0000 (17:59 +0400)
committerAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Fri, 21 Feb 2014 15:39:19 +0000 (19:39 +0400)
/tree/ - for directories
/blob/ - fol files
GitHub automatically converts one to another

Except one case: root folder. /blob/master -> 404, not into /tree/master

plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java

index f587d44c8cb6352e607e9d89f6c5ee97158feb76..cec5ba26972167303758956de392861f1e585332 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.SelectionModel;
 import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.changes.Change;
 import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -156,7 +157,12 @@ public class GithubOpenInBrowserAction extends DumbAwareAction {
     if (githubRepoUrl == null) {
       return null;
     }
-    builder.append(githubRepoUrl).append("/blob/").append(branch).append(relativePath);
+    if (StringUtil.isEmptyOrSpaces(relativePath)) {
+      builder.append(githubRepoUrl).append("/tree/").append(branch);
+    }
+    else {
+      builder.append(githubRepoUrl).append("/blob/").append(branch).append(relativePath);
+    }
 
     if (editor != null && editor.getDocument().getLineCount() >= 1) {
       // lines are counted internally from 0, but from 1 on github