use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.
the class GithubRebaseAction method loadRepositoryInfo.
@Nullable
private static GithubRepoDetailed loadRepositoryInfo(@NotNull Project project, @NotNull GitRepository gitRepository, @NotNull ProgressIndicator indicator) {
final String remoteUrl = GithubUtil.findGithubRemoteUrl(gitRepository);
if (remoteUrl == null) {
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, "Can't find GitHub remote");
return null;
}
final GithubFullPath userAndRepo = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(remoteUrl);
if (userAndRepo == null) {
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, "Can't process remote: " + remoteUrl);
return null;
}
try {
return GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator, connection -> GithubApiUtil.getDetailedRepoInfo(connection, userAndRepo.getUser(), userAndRepo.getRepository()));
} catch (IOException e) {
GithubNotifications.showError(project, "Can't load repository info", e);
return null;
}
}
use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.
the class GithubCreatePullRequestWorker method doConfigureRemote.
private void doConfigureRemote(@NotNull ForkInfo fork) {
if (fork.getRemoteName() != null)
return;
GithubFullPath path = fork.getPath();
String url = GithubUrlUtil.getCloneUrl(path);
if (GithubUtil.addGithubRemote(myProject, myGitRepository, path.getUser(), url)) {
fork.setRemoteName(path.getUser());
}
}
use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.
the class GithubOpenInBrowserAction method openCommitInBrowser.
protected static void openCommitInBrowser(@NotNull Project project, @NotNull GitRepository repository, @NotNull String revisionHash) {
String url = GithubUtil.findGithubRemoteUrl(repository);
if (url == null) {
LOG.info(String.format("Repository is not under GitHub. Root: %s, Remotes: %s", repository.getRoot(), GitUtil.getPrintableRemotes(repository.getRemotes())));
return;
}
GithubFullPath userAndRepository = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(url);
if (userAndRepository == null) {
GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, "Can't extract info about repository: " + url);
return;
}
String githubUrl = GithubUrlUtil.getGithubHost() + '/' + userAndRepository.getUser() + '/' + userAndRepository.getRepository() + "/commit/" + revisionHash;
BrowserUtil.browse(githubUrl);
}
use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.
the class GithubUrlUtilTest method testGetUserAndRepositoryFromRemoteUrl.
public void testGetUserAndRepositoryFromRemoteUrl() throws Throwable {
TestCase<GithubFullPath> tests = new TestCase<>();
tests.add("http://github.com/username/reponame/", new GithubFullPath("username", "reponame"));
tests.add("https://github.com/username/reponame/", new GithubFullPath("username", "reponame"));
tests.add("git://github.com/username/reponame/", new GithubFullPath("username", "reponame"));
tests.add("git@github.com:username/reponame/", new GithubFullPath("username", "reponame"));
tests.add("https://github.com/username/reponame", new GithubFullPath("username", "reponame"));
tests.add("https://github.com/username/reponame.git", new GithubFullPath("username", "reponame"));
tests.add("https://github.com/username/reponame.git/", new GithubFullPath("username", "reponame"));
tests.add("git@github.com:username/reponame.git/", new GithubFullPath("username", "reponame"));
tests.add("http://login:passsword@github.com/username/reponame/", new GithubFullPath("username", "reponame"));
tests.add("HTTPS://GitHub.com/username/reponame/", new GithubFullPath("username", "reponame"));
tests.add("https://github.com/UserName/RepoName/", new GithubFullPath("UserName", "RepoName"));
tests.add("https://github.com/RepoName/", null);
tests.add("git@github.com:user/", null);
tests.add("https://user:pass@github.com/", null);
runTestCase(tests, new Convertor<String, GithubFullPath>() {
@Override
@Nullable
public GithubFullPath convert(String in) {
return getUserAndRepositoryFromRemoteUrl(in);
}
});
}
use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.
the class GithubRebaseAction method rebaseMyGithubFork.
private static void rebaseMyGithubFork(@NotNull final Project project, @Nullable final VirtualFile file) {
final GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
if (gitRepository == null) {
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, "Can't find git repository");
return;
}
BasicAction.saveAll();
new Task.Backgroundable(project, "Rebasing GitHub Fork...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
gitRepository.update();
String upstreamRemoteUrl = GithubUtil.findUpstreamRemote(gitRepository);
if (upstreamRemoteUrl == null) {
LOG.info("Configuring upstream remote");
indicator.setText("Configuring upstream remote...");
upstreamRemoteUrl = configureUpstreamRemote(project, gitRepository, indicator);
if (upstreamRemoteUrl == null) {
return;
}
}
if (!GithubUrlUtil.isGithubUrl(upstreamRemoteUrl)) {
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, "Configured upstream is not a GitHub repository: " + upstreamRemoteUrl);
return;
} else {
final GithubFullPath userAndRepo = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(upstreamRemoteUrl);
final String login = GithubSettings.getInstance().getLogin();
if (userAndRepo != null) {
if (userAndRepo.getUser().equals(login)) {
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, "Configured upstream seems to be your own repository: " + upstreamRemoteUrl);
return;
}
}
}
LOG.info("Fetching upstream");
indicator.setText("Fetching upstream...");
if (!fetchParent(project, gitRepository, indicator)) {
return;
}
LOG.info("Rebasing current branch");
indicator.setText("Rebasing current branch...");
rebaseCurrentBranch(project, gitRepository, indicator);
}
}.queue();
}
Aggregations