Search in sources :

Example 1 with GithubFullPath

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;
    }
}
Also used : IOException(java.io.IOException) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GithubFullPath

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());
    }
}
Also used : GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath)

Example 3 with GithubFullPath

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);
}
Also used : GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath)

Example 4 with GithubFullPath

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);
        }
    });
}
Also used : UsefulTestCase(com.intellij.testFramework.UsefulTestCase) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with GithubFullPath

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();
}
Also used : GitRepository(git4idea.repo.GitRepository) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath)

Aggregations

GithubFullPath (org.jetbrains.plugins.github.api.GithubFullPath)9 Nullable (org.jetbrains.annotations.Nullable)6 IOException (java.io.IOException)5 GitRepository (git4idea.repo.GitRepository)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 GitLocalBranch (git4idea.GitLocalBranch)2 GitRemote (git4idea.repo.GitRemote)2 BrowserUtil (com.intellij.ide.BrowserUtil)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 DataProvider (com.intellij.openapi.actionSystem.DataProvider)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 Splitter (com.intellij.openapi.ui.Splitter)1 Ref (com.intellij.openapi.util.Ref)1