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 6030bd3f41ed..9314984ac40e 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -231,8 +231,8 @@ public class GithubApiUtil { } private static class ResponsePage { - @Nullable private JsonElement response; - @Nullable private String nextPage; + @Nullable private final JsonElement response; + @Nullable private final String nextPage; public ResponsePage() { this(null, null); @@ -272,21 +272,20 @@ public class GithubApiUtil { } } - static class PagedRequest { - @NotNull private GithubAuthData myAuth; + public static class PagedRequest { @Nullable private String myNextPage; - @NotNull private Class myResult; - @NotNull private Class myRawArray; + @NotNull private final Class myResult; + @NotNull private final Class myRawArray; - public PagedRequest(@NotNull GithubAuthData auth, @NotNull String path, @NotNull Class result, @NotNull Class rawArray) { - myAuth = auth; + @SuppressWarnings("NullableProblems") + public PagedRequest(@NotNull String path, @NotNull Class result, @NotNull Class rawArray) { myNextPage = path; myResult = result; myRawArray = rawArray; } @NotNull - public List next() throws IOException { + public List next(@NotNull GithubAuthData auth) throws IOException { if (myNextPage == null) { throw new NoSuchElementException(); } @@ -294,7 +293,7 @@ public class GithubApiUtil { String page = myNextPage; myNextPage = null; - ResponsePage response = request(myAuth, page, null, HttpVerb.GET); + ResponsePage response = request(auth, page, null, HttpVerb.GET); if (response.getJsonElement() == null) { throw new HttpException("Empty response"); @@ -307,7 +306,7 @@ public class GithubApiUtil { myNextPage = response.getNextPage(); List result = new ArrayList(); - for (R raw : fromJson(response.getJsonElement().getAsJsonArray(), myRawArray)) { + for (DataConstructor raw : fromJson(response.getJsonElement().getAsJsonArray(), myRawArray)) { result.add(createDataFromRaw(raw, myResult)); } return result; @@ -318,10 +317,10 @@ public class GithubApiUtil { } @NotNull - public List getAll() throws IOException { + public List getAll(@NotNull GithubAuthData auth) throws IOException { List result = new ArrayList(); while (hasNext()) { - result.addAll(next()); + result.addAll(next(auth)); } return result; } @@ -420,10 +419,9 @@ public class GithubApiUtil { String path = user == null ? "/user/repos" : "/users/" + user + "/repos?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubRepo.class, GithubRepoRaw[].class); + PagedRequest request = new PagedRequest(path, GithubRepo.class, GithubRepoRaw[].class); - return request.getAll(); + return request.getAll(auth); } @NotNull @@ -500,10 +498,9 @@ public class GithubApiUtil { path = "/repos/" + user + "/" + repo + "/issues?assignee=" + assigned + "&per_page=100"; } - PagedRequest request = - new PagedRequest(auth, path, GithubIssue.class, GithubIssueRaw[].class); + PagedRequest request = new PagedRequest(path, GithubIssue.class, GithubIssueRaw[].class); - return request.getAll(); + return request.getAll(auth); } @NotNull @@ -535,10 +532,10 @@ public class GithubApiUtil { throws IOException { String path = "/repos/" + user + "/" + repo + "/issues/" + id + "/comments?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubIssueComment.class, GithubIssueCommentRaw[].class); + PagedRequest request = + new PagedRequest(path, GithubIssueComment.class, GithubIssueCommentRaw[].class); - return request.getAll(); + return request.getAll(auth); } @NotNull @@ -564,10 +561,17 @@ public class GithubApiUtil { throws IOException { String path = "/repos/" + user + "/" + repo + "/pulls?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubPullRequest.class, GithubPullRequestRaw[].class); + PagedRequest request = + new PagedRequest(path, GithubPullRequest.class, GithubPullRequestRaw[].class); - return request.getAll(); + return request.getAll(auth); + } + + @NotNull + public static PagedRequest getPullRequests(@NotNull String user, @NotNull String repo) { + String path = "/repos/" + user + "/" + repo + "/pulls?per_page=100"; + + return new PagedRequest(path, GithubPullRequest.class, GithubPullRequestRaw[].class); } @NotNull @@ -575,10 +579,9 @@ public class GithubApiUtil { throws IOException { String path = "/repos/" + user + "/" + repo + "/pulls/" + id + "/commits?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubCommit.class, GithubCommitRaw[].class); + PagedRequest request = new PagedRequest(path, GithubCommit.class, GithubCommitRaw[].class); - return request.getAll(); + return request.getAll(auth); } @NotNull @@ -586,10 +589,9 @@ public class GithubApiUtil { throws IOException { String path = "/repos/" + user + "/" + repo + "/pulls/" + id + "/files?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubFile.class, GithubFileRaw[].class); + PagedRequest request = new PagedRequest(path, GithubFile.class, GithubFileRaw[].class); - return request.getAll(); + return request.getAll(auth); } @NotNull @@ -597,10 +599,9 @@ public class GithubApiUtil { throws IOException { String path = "/repos/" + user + "/" + repo + "/branches?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubBranch.class, GithubBranchRaw[].class); + PagedRequest request = new PagedRequest(path, GithubBranch.class, GithubBranchRaw[].class); - return request.getAll(); + return request.getAll(auth); } @Nullable @@ -610,11 +611,10 @@ public class GithubApiUtil { @NotNull String forkUser) throws IOException { String path = "/repos/" + user + "/" + repo + "/forks?per_page=100"; - PagedRequest request = - new PagedRequest(auth, path, GithubRepo.class, GithubRepoRaw[].class); + PagedRequest request = new PagedRequest(path, GithubRepo.class, GithubRepoRaw[].class); while (request.hasNext()) { - for (GithubRepo fork : request.next()) { + for (GithubRepo fork : request.next(auth)) { if (StringUtil.equalsIgnoreCase(fork.getUserName(), forkUser)) { return fork; }