mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-66991 Allow cloning from github using ssh protocol in case if user has write access to the repo
IDEA-66869 Cannot clone watched PRIVATE repository from Github
This commit is contained in:
@@ -68,14 +68,20 @@ public class GithubCheckoutProvider implements CheckoutProvider {
|
||||
|
||||
// All the preliminary work is already done, go and clone the selected repository!
|
||||
final RepositoryInfo selectedRepository = checkoutDialog.getSelectedRepository();
|
||||
final boolean writeAccessAllowed = GithubUtil.isWriteAccessAllowed(project, selectedRepository);
|
||||
if (!writeAccessAllowed){
|
||||
Messages.showErrorDialog(project, "It seems that you have only read access to the selected repository.\n" +
|
||||
"GitHub supports only https protocol for readonly access, which is not supported yet.\n" +
|
||||
"More details are available here: http://youtrack.jetbrains.net/issue/IDEA-55298", "Cannot clone this repository");
|
||||
return;
|
||||
}
|
||||
final String host = writeAccessAllowed ? "git@" + settings.getHost() + ":" : "https://github.com" + settings.getHost() + "/";
|
||||
final String selectedPath = checkoutDialog.getSelectedPath();
|
||||
final VirtualFile selectedPathFile = LocalFileSystem.getInstance().findFileByPath(selectedPath);
|
||||
final String projectName = checkoutDialog.getProjectName();
|
||||
final String repositoryName = selectedRepository.getName();
|
||||
final String repositoryOwner = selectedRepository.getOwner();
|
||||
final String checkoutUrl = settings.getLogin().equals(repositoryOwner)
|
||||
? "git@github.com:" + repositoryOwner + "/" + repositoryName + ".git"
|
||||
: "https://github.com/" + repositoryOwner + "/" + repositoryName + ".git";
|
||||
final String checkoutUrl = host + repositoryOwner + "/" + repositoryName + ".git";
|
||||
GitCheckoutProvider.checkout(project, listener, selectedPathFile, checkoutUrl, projectName, "origin", selectedPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,29 @@ public class GithubUtil {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static boolean isPushableRepo(final String url, final String login, final String password, final RepositoryInfo repositoryInfo) {
|
||||
try {
|
||||
final HttpMethod method = doREST(url, login, password, "/repos/pushable", false);
|
||||
final InputStream stream = method.getResponseBodyAsStream();
|
||||
final Element element = new SAXBuilder(false).build(stream).getRootElement();
|
||||
if ("error".equals(element.getName())){
|
||||
LOG.warn("Got error element by request: " + "/repos/pushable");
|
||||
return false;
|
||||
}
|
||||
final List repositories = element.getChildren();
|
||||
for (int i = 0; i < repositories.size(); i++) {
|
||||
final Element repo = (Element)repositories.get(i);
|
||||
if (repositoryInfo.equals(new RepositoryInfo(repo))){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static RepositoryInfo getDetailedRepoInfo(final String url, final String login, final String password, final String name) {
|
||||
try {
|
||||
@@ -325,4 +348,15 @@ public class GithubUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isWriteAccessAllowed(final Project project, final RepositoryInfo repo) {
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
return accessToGithubWithModalProgress(project, new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Extracting info about pushable repositories");
|
||||
return isPushableRepo(settings.getHost(), settings.getLogin(), settings.getPassword(), repo);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.plugins.github;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
@@ -28,4 +29,14 @@ public class RepositoryInfo {
|
||||
public String getParent() {
|
||||
return myRepository.getChildText("parent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof RepositoryInfo)){
|
||||
return false;
|
||||
}
|
||||
final RepositoryInfo repositoryInfo = (RepositoryInfo)obj;
|
||||
return Comparing.equal(getName(), repositoryInfo.getName()) &&
|
||||
Comparing.equal(getOwner(), repositoryInfo.getOwner());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user