Search in sources :

Example 1 with GithubRepo

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

the class GithubCheckoutProvider method doCheckout.

@Override
public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
    if (!GithubUtil.testGitExecutable(project)) {
        return;
    }
    BasicAction.saveAll();
    List<GithubRepo> availableRepos;
    try {
        availableRepos = GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator, connection -> GithubApiUtil.getAvailableRepos(connection)));
    } catch (IOException e) {
        GithubNotifications.showError(project, "Couldn't get the list of GitHub repositories", e);
        return;
    }
    Collections.sort(availableRepos, (r1, r2) -> {
        final int comparedOwners = r1.getUserName().compareTo(r2.getUserName());
        return comparedOwners != 0 ? comparedOwners : r1.getName().compareTo(r2.getName());
    });
    final GitCloneDialog dialog = new GitCloneDialog(project);
    // Add predefined repositories to history
    dialog.prependToHistory("-----------------------------------------------");
    for (int i = availableRepos.size() - 1; i >= 0; i--) {
        dialog.prependToHistory(GithubUrlUtil.getCloneUrl(availableRepos.get(i).getFullPath()));
    }
    if (!dialog.showAndGet()) {
        return;
    }
    dialog.rememberSettings();
    final VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
    if (destinationParent == null) {
        return;
    }
    final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
    final String directoryName = dialog.getDirectoryName();
    final String parentDirectory = dialog.getParentDirectory();
    Git git = ServiceManager.getService(Git.class);
    GitCheckoutProvider.clone(project, git, listener, destinationParent, sourceRepositoryURL, directoryName, parentDirectory);
}
Also used : Git(git4idea.commands.Git) GitCheckoutProvider(git4idea.checkout.GitCheckoutProvider) GithubUrlUtil(org.jetbrains.plugins.github.util.GithubUrlUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BasicAction(git4idea.actions.BasicAction) File(java.io.File) GithubApiUtil(org.jetbrains.plugins.github.api.GithubApiUtil) GithubNotifications(org.jetbrains.plugins.github.util.GithubNotifications) Nullable(org.jetbrains.annotations.Nullable) GithubUtil(org.jetbrains.plugins.github.util.GithubUtil) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) Project(com.intellij.openapi.project.Project) GitCloneDialog(git4idea.checkout.GitCloneDialog) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) CheckoutProvider(com.intellij.openapi.vcs.CheckoutProvider) GithubAuthDataHolder(org.jetbrains.plugins.github.util.GithubAuthDataHolder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Git(git4idea.commands.Git) GitCloneDialog(git4idea.checkout.GitCloneDialog) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with GithubRepo

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

the class GithubRequestQueringTest method testOwnRepos.

public void testOwnRepos() throws Throwable {
    List<GithubRepo> result = GithubApiUtil.getUserRepos(new GithubConnection(myAuth));
    assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("example")));
    assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("PullRequestTest")));
    assertFalse(ContainerUtil.exists(result, (it) -> it.getName().equals("org_repo")));
}
Also used : GithubApiUtil(org.jetbrains.plugins.github.api.GithubApiUtil) List(java.util.List) GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) ContainerUtil(com.intellij.util.containers.ContainerUtil) GithubTest(org.jetbrains.plugins.github.test.GithubTest) ArrayList(java.util.ArrayList) Assume.assumeNotNull(org.junit.Assume.assumeNotNull) GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo)

Example 3 with GithubRepo

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

the class GithubRequestQueringTest method testPagination.

public void testPagination() throws Throwable {
    GithubConnection connection = new GithubConnection(myGitHubSettings.getAuthData(), true);
    try {
        List<GithubRepo> availableRepos = GithubApiUtil.getUserRepos(connection, myLogin2);
        List<String> realData = new ArrayList<>();
        for (GithubRepo info : availableRepos) {
            realData.add(info.getName());
        }
        List<String> expectedData = new ArrayList<>();
        for (int i = 1; i <= 251; i++) {
            expectedData.add(String.valueOf(i));
        }
        assertContainsElements(realData, expectedData);
    } finally {
        connection.close();
    }
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) ArrayList(java.util.ArrayList)

Example 4 with GithubRepo

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

the class GithubRequestQueringTest method testAllRepos.

public void testAllRepos() throws Throwable {
    List<GithubRepo> result = GithubApiUtil.getUserRepos(new GithubConnection(myAuth), true);
    assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("example")));
    assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("PullRequestTest")));
    assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("org_repo")));
}
Also used : GithubApiUtil(org.jetbrains.plugins.github.api.GithubApiUtil) List(java.util.List) GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) ContainerUtil(com.intellij.util.containers.ContainerUtil) GithubTest(org.jetbrains.plugins.github.test.GithubTest) ArrayList(java.util.ArrayList) Assume.assumeNotNull(org.junit.Assume.assumeNotNull) GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo)

Example 5 with GithubRepo

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

the class GithubShareAction method loadGithubInfoWithModal.

@Nullable
private static GithubInfo loadGithubInfoWithModal(@NotNull final GithubAuthDataHolder authHolder, @NotNull final Project project) {
    try {
        return GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> {
            return GithubUtil.runTask(project, authHolder, indicator, connection -> {
                GithubUserDetailed userInfo = GithubApiUtil.getCurrentUser(connection);
                HashSet<String> names = new HashSet<>();
                for (GithubRepo info : GithubApiUtil.getUserRepos(connection)) {
                    names.add(info.getName());
                }
                return new GithubInfo(userInfo, names);
            });
        });
    } catch (IOException e) {
        GithubNotifications.showErrorDialog(project, "Failed to Connect to GitHub", e);
        return null;
    }
}
Also used : GithubUserDetailed(org.jetbrains.plugins.github.api.data.GithubUserDetailed) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) IOException(java.io.IOException) HashSet(com.intellij.util.containers.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GithubRepo (org.jetbrains.plugins.github.api.data.GithubRepo)6 GithubApiUtil (org.jetbrains.plugins.github.api.GithubApiUtil)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 GithubConnection (org.jetbrains.plugins.github.api.GithubConnection)3 ServiceManager (com.intellij.openapi.components.ServiceManager)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 HashSet (com.intellij.util.containers.HashSet)2 BasicAction (git4idea.actions.BasicAction)2 GithubUserDetailed (org.jetbrains.plugins.github.api.data.GithubUserDetailed)2 GithubTest (org.jetbrains.plugins.github.test.GithubTest)2 Assume.assumeNotNull (org.junit.Assume.assumeNotNull)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