diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 20ba58c85a2a..85eb2bfabf2d 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -244,8 +244,14 @@ public class GithubApiUtil { @NotNull public static List getUserRepos(@NotNull GithubConnection connection) throws IOException { + return getUserRepos(connection, false); + } + + @NotNull + public static List getUserRepos(@NotNull GithubConnection connection, boolean allAssociated) throws IOException { try { - String path = "/user/repos?" + PER_PAGE; + String type = allAssociated ? "" : "type=owner&"; + String path = "/user/repos?" + type + PER_PAGE; return loadAll(connection, path, GithubRepo[].class, ACCEPT_V3_JSON); } catch (GithubConfusingException e) { @@ -257,7 +263,7 @@ public class GithubApiUtil { @NotNull public static List getUserRepos(@NotNull GithubConnection connection, @NotNull String user) throws IOException { try { - String path = "/users/" + user + "/repos?" + PER_PAGE; + String path = "/users/" + user + "/repos?type=owner&" + PER_PAGE; return loadAll(connection, path, GithubRepo[].class, ACCEPT_V3_JSON); } catch (GithubConfusingException e) { @@ -271,15 +277,10 @@ public class GithubApiUtil { try { List repos = new ArrayList<>(); - repos.addAll(getUserRepos(connection)); + repos.addAll(getUserRepos(connection, true)); // We already can return something useful from getUserRepos, so let's ignore errors. // One of this may not exist in GitHub enterprise - try { - repos.addAll(getMembershipRepos(connection)); - } - catch (GithubAuthenticationException | GithubStatusCodeException ignore) { - } try { repos.addAll(getWatchedRepos(connection)); } @@ -295,21 +296,7 @@ public class GithubApiUtil { } @NotNull - public static List getMembershipRepos(@NotNull GithubConnection connection) throws IOException { - String orgsPath = "/user/orgs?" + PER_PAGE; - List orgs = loadAll(connection, orgsPath, GithubOrg[].class); - - List repos = new ArrayList<>(); - for (GithubOrg org : orgs) { - String path = "/orgs/" + org.getLogin() + "/repos?type=member&" + PER_PAGE; - repos.addAll(loadAll(connection, path, GithubRepoOrg[].class, ACCEPT_V3_JSON)); - } - - return repos; - } - - @NotNull - public static List getWatchedRepos(@NotNull GithubConnection connection) throws IOException { + private static List getWatchedRepos(@NotNull GithubConnection connection) throws IOException { String pathWatched = "/user/subscriptions?" + PER_PAGE; return loadAll(connection, pathWatched, GithubRepo[].class, ACCEPT_V3_JSON); } diff --git a/plugins/github/test/org/jetbrains/plugins/github/GithubRequestPagingTest.java b/plugins/github/test/org/jetbrains/plugins/github/GithubRequestQueringTest.java similarity index 63% rename from plugins/github/test/org/jetbrains/plugins/github/GithubRequestPagingTest.java rename to plugins/github/test/org/jetbrains/plugins/github/GithubRequestQueringTest.java index fe205e2f4269..a85fee484d2c 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/GithubRequestPagingTest.java +++ b/plugins/github/test/org/jetbrains/plugins/github/GithubRequestQueringTest.java @@ -15,6 +15,7 @@ */ package org.jetbrains.plugins.github; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.plugins.github.api.GithubApiUtil; import org.jetbrains.plugins.github.api.GithubConnection; import org.jetbrains.plugins.github.api.data.GithubRepo; @@ -28,15 +29,14 @@ import static org.junit.Assume.assumeNotNull; /** * @author Aleksey Pivovarov */ -public class GithubRequestPagingTest extends GithubTest { +public class GithubRequestQueringTest extends GithubTest { @Override protected void beforeTest() throws Exception { assumeNotNull(myLogin2); } - public void testAvailableRepos() throws Throwable { - + public void testPagination() throws Throwable { GithubConnection connection = new GithubConnection(myGitHubSettings.getAuthData(), true); try { List availableRepos = GithubApiUtil.getUserRepos(connection, myLogin2); @@ -56,4 +56,20 @@ public class GithubRequestPagingTest extends GithubTest { connection.close(); } } + + public void testOwnRepos() throws Throwable { + List 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"))); + } + + public void testAllRepos() throws Throwable { + List 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"))); + } }