Search in sources :

Example 6 with GithubFullPath

use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.

the class GithubShareAction method checkExistingRemote.

private static boolean checkExistingRemote(@NotNull final Project project, @NotNull final GithubAuthDataHolder authHolder, @NotNull String remote) {
    final GithubFullPath path = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(remote);
    if (path == null) {
        return GithubNotifications.showYesNoDialog(project, "Project Is Already on GitHub", "Can't connect to repository from configured remote. You could want to check .git config.\n" + "Do you want to proceed anyway?");
    }
    try {
        GithubRepo repo = GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> GithubUtil.runTask(project, authHolder, indicator, connection -> GithubApiUtil.getDetailedRepoInfo(connection, path.getUser(), path.getRepository())));
        int result = Messages.showDialog(project, "Successfully connected to " + repo.getHtmlUrl() + ".\n" + "Do you want to proceed anyway?", "Project Is Already on GitHub", new String[] { "Continue", "Open in Browser", Messages.CANCEL_BUTTON }, 2, Messages.getQuestionIcon());
        if (result == 0)
            return true;
        if (result == 1) {
            BrowserUtil.browse(repo.getHtmlUrl());
        }
        return false;
    } catch (GithubStatusCodeException e) {
        if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            return GithubNotifications.showYesNoDialog(project, "Project Is Already on GitHub", "Can't connect to repository from configured remote. You could want to check .git config.\n" + "Do you want to proceed anyway?");
        }
        GithubNotifications.showErrorDialog(project, "Failed to Connect to GitHub", e);
        return false;
    } catch (IOException e) {
        GithubNotifications.showErrorDialog(project, "Failed to Connect to GitHub", e);
        return false;
    }
}
Also used : GithubStatusCodeException(org.jetbrains.plugins.github.exceptions.GithubStatusCodeException) git4idea.commands(git4idea.commands) GithubUrlUtil(org.jetbrains.plugins.github.util.GithubUrlUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) HttpStatus(org.apache.http.HttpStatus) GithubApiUtil(org.jetbrains.plugins.github.api.GithubApiUtil) GitUtil(git4idea.GitUtil) Task(com.intellij.openapi.progress.Task) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) GitRepository(git4idea.repo.GitRepository) GithubUserDetailed(org.jetbrains.plugins.github.api.data.GithubUserDetailed) GithubAuthDataHolder(org.jetbrains.plugins.github.util.GithubAuthDataHolder) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) GitBundle(git4idea.i18n.GitBundle) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) BrowserUtil(com.intellij.ide.BrowserUtil) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ServiceManager(com.intellij.openapi.components.ServiceManager) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) GitFileUtils(git4idea.util.GitFileUtils) DataProvider(com.intellij.openapi.actionSystem.DataProvider) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) SelectFilesDialog(com.intellij.openapi.vcs.changes.ui.SelectFilesDialog) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) GitRepositoryManager(git4idea.repo.GitRepositoryManager) NonNls(org.jetbrains.annotations.NonNls) GitUIUtil(git4idea.util.GitUIUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) GithubNotifications(org.jetbrains.plugins.github.util.GithubNotifications) GitInit(git4idea.actions.GitInit) Project(com.intellij.openapi.project.Project) VcsFileUtil(com.intellij.vcsUtil.VcsFileUtil) DialogManager(git4idea.DialogManager) GitLocalBranch(git4idea.GitLocalBranch) GithubShareDialog(org.jetbrains.plugins.github.ui.GithubShareDialog) Splitter(com.intellij.openapi.ui.Splitter) GitRemote(git4idea.repo.GitRemote) IOException(java.io.IOException) BasicAction(git4idea.actions.BasicAction) GithubUtil(org.jetbrains.plugins.github.util.GithubUtil) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) VcsDataKeys(com.intellij.openapi.vcs.VcsDataKeys) GithubIcons(icons.GithubIcons) CommitMessage(com.intellij.openapi.vcs.ui.CommitMessage) javax.swing(javax.swing) GithubStatusCodeException(org.jetbrains.plugins.github.exceptions.GithubStatusCodeException) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) IOException(java.io.IOException) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath)

Example 7 with GithubFullPath

use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.

the class GithubCreatePullRequestWorker method doAddFork.

@Nullable
private ForkInfo doAddFork(@NotNull GithubRepo repo, @NotNull ProgressIndicator indicator) {
    GithubFullPath path = repo.getFullPath();
    for (ForkInfo fork : myForks) {
        if (fork.getPath().equals(path)) {
            return fork;
        }
    }
    try {
        List<String> branches = loadBranches(path, indicator);
        String defaultBranch = repo.getDefaultBranch();
        ForkInfo fork = new ForkInfo(path, branches, defaultBranch);
        myForks.add(fork);
        return fork;
    } catch (IOException e) {
        GithubNotifications.showWarning(myProject, "Can't load branches for " + path.getFullName(), e);
        return null;
    }
}
Also used : IOException(java.io.IOException) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GithubFullPath

use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.

the class GithubCreatePullRequestWorker method create.

@Nullable
public static GithubCreatePullRequestWorker create(@NotNull final Project project, @Nullable final VirtualFile file) {
    return GithubUtil.computeValueInModal(project, "Loading data...", indicator -> {
        Git git = ServiceManager.getService(Git.class);
        GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
        if (gitRepository == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find git repository");
            return null;
        }
        gitRepository.update();
        Pair<GitRemote, String> remote = GithubUtil.findGithubRemote(gitRepository);
        if (remote == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find GitHub remote");
            return null;
        }
        String remoteName = remote.getFirst().getName();
        String remoteUrl = remote.getSecond();
        GithubFullPath path = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(remoteUrl);
        if (path == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't process remote: " + remoteUrl);
            return null;
        }
        GitLocalBranch currentBranch = gitRepository.getCurrentBranch();
        if (currentBranch == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "No current branch");
            return null;
        }
        GithubAuthDataHolder authHolder;
        try {
            authHolder = GithubUtil.getValidAuthDataHolderFromConfig(project, AuthLevel.LOGGED, indicator);
        } catch (IOException e) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
            return null;
        }
        GithubCreatePullRequestWorker worker = new GithubCreatePullRequestWorker(project, git, gitRepository, authHolder, path, remoteName, remoteUrl, currentBranch.getName());
        try {
            worker.initForks(indicator);
        } catch (IOException e) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
            return null;
        }
        return worker;
    });
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository) GitLocalBranch(git4idea.GitLocalBranch) Git(git4idea.commands.Git) IOException(java.io.IOException) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with GithubFullPath

use of org.jetbrains.plugins.github.api.GithubFullPath in project intellij-community by JetBrains.

the class GithubCreatePullRequestWorker method doCreatePullRequest.

@Nullable
private GithubPullRequest doCreatePullRequest(@NotNull ProgressIndicator indicator, @NotNull final BranchInfo branch, @NotNull final String title, @NotNull final String description) {
    final GithubFullPath forkPath = branch.getForkInfo().getPath();
    final String head = myPath.getUser() + ":" + myCurrentBranch;
    final String base = branch.getRemoteName();
    try {
        return GithubUtil.runTask(myProject, myAuthHolder, indicator, connection -> GithubApiUtil.createPullRequest(connection, forkPath.getUser(), forkPath.getRepository(), title, description, head, base));
    } catch (IOException e) {
        GithubNotifications.showError(myProject, CANNOT_CREATE_PULL_REQUEST, e);
        return null;
    }
}
Also used : IOException(java.io.IOException) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) Nullable(org.jetbrains.annotations.Nullable)

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