mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
github: fix repository list loading
* fix "repository already exists" check because of the organisation repository with the same name * behavior of the API changed some time ago
This commit is contained in:
committed by
Aleksey Pivovarov
parent
28ef6a3669
commit
1b2dbea09f
@@ -244,8 +244,14 @@ public class GithubApiUtil {
|
||||
|
||||
@NotNull
|
||||
public static List<GithubRepo> getUserRepos(@NotNull GithubConnection connection) throws IOException {
|
||||
return getUserRepos(connection, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<GithubRepo> 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<GithubRepo> 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<GithubRepo> 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<GithubRepoOrg> getMembershipRepos(@NotNull GithubConnection connection) throws IOException {
|
||||
String orgsPath = "/user/orgs?" + PER_PAGE;
|
||||
List<GithubOrg> orgs = loadAll(connection, orgsPath, GithubOrg[].class);
|
||||
|
||||
List<GithubRepoOrg> 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<GithubRepo> getWatchedRepos(@NotNull GithubConnection connection) throws IOException {
|
||||
private static List<GithubRepo> getWatchedRepos(@NotNull GithubConnection connection) throws IOException {
|
||||
String pathWatched = "/user/subscriptions?" + PER_PAGE;
|
||||
return loadAll(connection, pathWatched, GithubRepo[].class, ACCEPT_V3_JSON);
|
||||
}
|
||||
|
||||
+19
-3
@@ -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<GithubRepo> availableRepos = GithubApiUtil.getUserRepos(connection, myLogin2);
|
||||
@@ -56,4 +56,20 @@ public class GithubRequestPagingTest extends GithubTest {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
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")));
|
||||
}
|
||||
|
||||
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")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user