diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 311dfccc1..0ed19cc39 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -180,7 +180,8 @@ public class GHApp extends GHObject { public PagedIterable listInstallations() { return root.createRequest() .withPreview(MACHINE_MAN) - .asPagedIterable("/app/installations", GHAppInstallation[].class, item -> item.wrapUp(root)); + .withUrlPath("/app/installations") + .toIterable(GHAppInstallation[].class, item -> item.wrapUp(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 515410a37..e5d696569 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -442,10 +442,9 @@ public class GHCommit { */ public PagedIterable listComments() { return owner.root.createRequest() - .asPagedIterable( - String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), - GHCommitComment[].class, - item -> item.wrap(owner)); + .withUrlPath( + String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha)) + .toIterable(GHCommitComment[].class, item -> item.wrap(owner)); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index b3da925c8..ac68e28fb 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -138,7 +138,8 @@ public class GHCommitComment extends GHObject implements Reactable { public PagedIterable listReactions() { return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) - .asPagedIterable(getApiTail() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); + .withUrlPath(getApiTail() + "/reactions") + .toIterable(GHReaction[].class, item -> item.wrap(owner.root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java index 0350ec4a3..579a812dc 100644 --- a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java @@ -127,6 +127,6 @@ public class GHCommitQueryBuilder { * @return the paged iterable */ public PagedIterable list() { - return req.asPagedIterable(repo.getApiTailUrl("commits"), GHCommit[].class, item -> item.wrapUp(repo)); + return req.withUrlPath(repo.getApiTailUrl("commits")).toIterable(GHCommit[].class, item -> item.wrapUp(repo)); } } diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 77e25233c..ce1c6553d 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -237,9 +237,7 @@ public class GHContent implements Refreshable { if (!isDirectory()) throw new IllegalStateException(path + " is not a directory"); - return root.createRequest() - .setRawUrlPath(url) - .asPagedIterable(GHContent[].class, item -> item.wrap(repository)); + return root.createRequest().setRawUrlPath(url).toIterable(GHContent[].class, item -> item.wrap(repository)); } /** diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index 01451cf9f..d2489a6f8 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -131,7 +131,9 @@ public class GHDeployment extends GHObject { * @return the paged iterable */ public PagedIterable listStatuses() { - return root.createRequest().asPagedIterable(statuses_url, GHDeploymentStatus[].class, item -> item.wrap(owner)); + return root.createRequest() + .withUrlPath(statuses_url) + .toIterable(GHDeploymentStatus[].class, item -> item.wrap(owner)); } } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index 86365b1c3..5d550235d 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -223,7 +223,9 @@ public class GHGist extends GHObject { * @return the paged iterable */ public PagedIterable listForks() { - return root.createRequest().asPagedIterable(getApiTailUrl("forks"), GHGist[].class, item -> item.wrapUp(root)); + return root.createRequest() + .withUrlPath(getApiTailUrl("forks")) + .toIterable(GHGist[].class, item -> item.wrapUp(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index b3951f371..9bb5b7ecd 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -446,9 +446,8 @@ public class GHIssue extends GHObject implements Reactable { */ public PagedIterable listComments() throws IOException { return root.createRequest() - .asPagedIterable(getIssuesApiRoute() + "/comments", - GHIssueComment[].class, - item -> item.wrapUp(GHIssue.this)); + .withUrlPath(getIssuesApiRoute() + "/comments") + .toIterable(GHIssueComment[].class, item -> item.wrapUp(this)); } @Preview @@ -468,7 +467,8 @@ public class GHIssue extends GHObject implements Reactable { public PagedIterable listReactions() { return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) - .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); + .withUrlPath(getApiRoute() + "/reactions") + .toIterable(GHReaction[].class, item -> item.wrap(owner.root)); } /** @@ -716,8 +716,7 @@ public class GHIssue extends GHObject implements Reactable { */ public PagedIterable listEvents() throws IOException { return root.createRequest() - .asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)), - GHIssueEvent[].class, - item -> item.wrapUp(GHIssue.this)); + .withUrlPath(owner.getApiTailUrl(String.format("/issues/%s/events", number))) + .toIterable(GHIssueEvent[].class, item -> item.wrapUp(this)); } } diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 1a174f2c5..722e0a987 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -143,7 +143,8 @@ public class GHIssueComment extends GHObject implements Reactable { public PagedIterable listReactions() { return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) - .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); + .withUrlPath(getApiRoute() + "/reactions") + .toIterable(GHReaction[].class, item -> item.wrap(owner.root)); } private String getApiRoute() { diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java b/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java index 0f109b57f..5df0feabe 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java @@ -64,9 +64,8 @@ public class GHMarketplaceListAccountBuilder { * on error */ public PagedIterable createRequest() throws IOException { - return builder.asPagedIterable(String.format("/marketplace_listing/plans/%d/accounts", this.planId), - GHMarketplaceAccountPlan[].class, - item -> item.wrapUp(root)); + return builder.withUrlPath(String.format("/marketplace_listing/plans/%d/accounts", this.planId)) + .toIterable(GHMarketplaceAccountPlan[].class, item -> item.wrapUp(root)); } } diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 1a83ff0d2..37989c9b9 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -178,7 +178,8 @@ public class GHMyself extends GHUser { public PagedIterable listRepositories(final int pageSize, final RepositoryListFilter repoType) { return root.createRequest() .with("type", repoType) - .asPagedIterable("/user/repos", GHRepository[].class, item -> item.wrap(root)) + .withUrlPath("/user/repos") + .toIterable(GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); } @@ -211,7 +212,8 @@ public class GHMyself extends GHUser { public PagedIterable listOrgMemberships(final GHMembership.State state) { return root.createRequest() .with("state", state) - .asPagedIterable("/user/memberships/orgs", GHMembership[].class, item -> item.wrap(root)); + .withUrlPath("/user/memberships/orgs") + .toIterable(GHMembership[].class, item -> item.wrap(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index dac65cb53..0f85137ef 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -122,9 +122,8 @@ public class GHOrganization extends GHPerson { */ public PagedIterable listTeams() throws IOException { return root.createRequest() - .asPagedIterable(String.format("/orgs/%s/teams", login), - GHTeam[].class, - item -> item.wrapUp(GHOrganization.this)); + .withUrlPath(String.format("/orgs/%s/teams", login)) + .toIterable(GHTeam[].class, item -> item.wrapUp(this)); } /** @@ -301,9 +300,8 @@ public class GHOrganization extends GHPerson { private PagedIterable listMembers(final String suffix, final String filter) throws IOException { String filterParams = (filter == null) ? "" : ("?filter=" + filter); return root.createRequest() - .asPagedIterable(String.format("/orgs/%s/%s%s", login, suffix, filterParams), - GHUser[].class, - item -> item.wrapUp(root)); + .withUrlPath(String.format("/orgs/%s/%s%s", login, suffix, filterParams)) + .toIterable(GHUser[].class, item -> item.wrapUp(root)); } /** @@ -331,7 +329,8 @@ public class GHOrganization extends GHPerson { return root.createRequest() .withPreview(INERTIA) .with("state", status) - .asPagedIterable(String.format("/orgs/%s/projects", login), GHProject[].class, item -> item.wrap(root)); + .withUrlPath(String.format("/orgs/%s/projects", login)) + .toIterable(GHProject[].class, item -> item.wrap(root)); } /** @@ -498,9 +497,8 @@ public class GHOrganization extends GHPerson { */ public PagedIterable listEvents() throws IOException { return root.createRequest() - .asPagedIterable(String.format("/orgs/%s/events", login), - GHEventInfo[].class, - item -> item.wrapUp(root)); + .withUrlPath(String.format("/orgs/%s/events", login)) + .toIterable(GHEventInfo[].class, item -> item.wrapUp(root)); } /** @@ -514,7 +512,8 @@ public class GHOrganization extends GHPerson { @Override public PagedIterable listRepositories(final int pageSize) { return root.createRequest() - .asPagedIterable("/orgs/" + login + "/repos", GHRepository[].class, item -> item.wrap(root)) + .withUrlPath("/orgs/" + login + "/repos") + .toIterable(GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); } diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 9b253db86..407136083 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -90,7 +90,8 @@ public abstract class GHPerson extends GHObject { */ public PagedIterable listRepositories(final int pageSize) { return root.createRequest() - .asPagedIterable("/users/" + login + "/repos", GHRepository[].class, item -> item.wrap(root)) + .withUrlPath("/users/" + login + "/repos") + .toIterable(GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); } diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index 56714ffac..344984711 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -290,9 +290,8 @@ public class GHProject extends GHObject { final GHProject project = this; return root.createRequest() .withPreview(INERTIA) - .asPagedIterable(String.format("/projects/%d/columns", id), - GHProjectColumn[].class, - item -> item.wrap(project)); + .withUrlPath(String.format("/projects/%d/columns", id)) + .toIterable(GHProjectColumn[].class, item -> item.wrap(project)); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index b561f6f90..0db0ba40c 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -139,9 +139,8 @@ public class GHProjectColumn extends GHObject { final GHProjectColumn column = this; return root.createRequest() .withPreview(INERTIA) - .asPagedIterable(String.format("/projects/columns/%d/cards", id), - GHProjectCard[].class, - item -> item.wrap(column)); + .withUrlPath(String.format("/projects/columns/%d/cards", id)) + .toIterable(GHProjectCard[].class, item -> item.wrap(column)); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index fb891f713..ed076c97d 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -394,7 +394,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { */ public PagedIterable listFiles() { return root.createRequest() - .asPagedIterable(String.format("%s/files", getApiRoute()), GHPullRequestFileDetail[].class, null); + .withUrlPath(String.format("%s/files", getApiRoute())) + .toIterable(GHPullRequestFileDetail[].class, null); } /** @@ -404,9 +405,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { */ public PagedIterable listReviews() { return root.createRequest() - .asPagedIterable(String.format("%s/reviews", getApiRoute()), - GHPullRequestReview[].class, - item -> item.wrapUp(GHPullRequest.this)); + .withUrlPath(String.format("%s/reviews", getApiRoute())) + .toIterable(GHPullRequestReview[].class, item -> item.wrapUp(this)); } /** @@ -418,9 +418,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { */ public PagedIterable listReviewComments() throws IOException { return root.createRequest() - .asPagedIterable(getApiRoute() + COMMENTS_ACTION, - GHPullRequestReviewComment[].class, - item -> item.wrapUp(GHPullRequest.this)); + .withUrlPath(getApiRoute() + COMMENTS_ACTION) + .toIterable(GHPullRequestReviewComment[].class, item -> item.wrapUp(this)); } /** @@ -430,9 +429,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { */ public PagedIterable listCommits() { return root.createRequest() - .asPagedIterable(String.format("%s/commits", getApiRoute()), - GHPullRequestCommitDetail[].class, - item -> item.wrapUp(GHPullRequest.this)); + .withUrlPath(String.format("%s/commits", getApiRoute())) + .toIterable(GHPullRequestCommitDetail[].class, item -> item.wrapUp(this)); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java index d19d88e27..a010ee3a9 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java @@ -89,6 +89,7 @@ public class GHPullRequestQueryBuilder extends GHQueryBuilder { @Override public PagedIterable list() { return req.withPreview(SHADOW_CAT) - .asPagedIterable(repo.getApiTailUrl("pulls"), GHPullRequest[].class, item -> item.wrapUp(repo)); + .withUrlPath(repo.getApiTailUrl("pulls")) + .toIterable(GHPullRequest[].class, item -> item.wrapUp(repo)); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 0498ce183..03cb0130c 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -206,8 +206,7 @@ public class GHPullRequestReview extends GHObject { */ public PagedIterable listReviewComments() throws IOException { return owner.root.createRequest() - .asPagedIterable(getApiRoute() + "/comments", - GHPullRequestReviewComment[].class, - item -> item.wrapUp(owner)); + .withUrlPath(getApiRoute() + "/comments") + .toIterable(GHPullRequestReviewComment[].class, item -> item.wrapUp(owner)); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 4864b05b4..4eb89a663 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -213,6 +213,7 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable { public PagedIterable listReactions() { return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) - .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); + .withUrlPath(getApiRoute() + "/reactions") + .toIterable(GHReaction[].class, item -> item.wrap(owner.root)); } } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index f2937c350..cb5a2520d 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -139,9 +139,8 @@ public class GHRepository extends GHObject { .with("ref", ref) .with("task", task) .with("environment", environment) - .asPagedIterable(getApiTailUrl("deployments"), - GHDeployment[].class, - item -> item.wrap(GHRepository.this)); + .withUrlPath(getApiTailUrl("deployments")) + .toIterable(GHDeployment[].class, item -> item.wrap(this)); } /** @@ -391,7 +390,8 @@ public class GHRepository extends GHObject { public PagedIterable listIssues(final GHIssueState state) { return root.createRequest() .with("state", state) - .asPagedIterable(getApiTailUrl("issues"), GHIssue[].class, item -> item.wrap(GHRepository.this)); + .withUrlPath(getApiTailUrl("issues")) + .toIterable(GHIssue[].class, item -> item.wrap(this)); } /** @@ -500,7 +500,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listReleases() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("releases"), GHRelease[].class, item -> item.wrap(GHRepository.this)); + .withUrlPath(getApiTailUrl("releases")) + .toIterable(GHRelease[].class, item -> item.wrap(this)); } /** @@ -512,7 +513,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listTags() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("tags"), GHTag[].class, item -> item.wrap(GHRepository.this)); + .withUrlPath(getApiTailUrl("tags")) + .toIterable(GHTag[].class, item -> item.wrap(this)); } /** @@ -1114,7 +1116,8 @@ public class GHRepository extends GHObject { public PagedIterable listForks(final ForkSort sort) { return root.createRequest() .with("sort", sort) - .asPagedIterable(getApiTailUrl("forks"), GHRepository[].class, item -> item.wrap(root)); + .withUrlPath(getApiTailUrl("forks")) + .toIterable(GHRepository[].class, item -> item.wrap(root)); } /** @@ -1424,7 +1427,7 @@ public class GHRepository extends GHObject { */ public PagedIterable listRefs() throws IOException { final String url = String.format("/repos/%s/%s/git/refs", getOwnerName(), name); - return root.createRequest().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); + return root.createRequest().withUrlPath(url).toIterable(GHRef[].class, item -> item.wrap(root)); } /** @@ -1453,7 +1456,7 @@ public class GHRepository extends GHObject { */ public PagedIterable listRefs(String refType) throws IOException { final String url = String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType); - return root.createRequest().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); + return root.createRequest().withUrlPath(url).toIterable(GHRef[].class, item -> item.wrap(root)); } /** @@ -1612,9 +1615,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listCommits() { return root.createRequest() - .asPagedIterable(String.format("/repos/%s/%s/commits", getOwnerName(), name), - GHCommit[].class, - item -> item.wrapUp(GHRepository.this)); + .withUrlPath(String.format("/repos/%s/%s/commits", getOwnerName(), name)) + .toIterable(GHCommit[].class, item -> item.wrapUp(this)); } /** @@ -1633,9 +1635,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listCommitComments() { return root.createRequest() - .asPagedIterable(String.format("/repos/%s/%s/comments", getOwnerName(), name), - GHCommitComment[].class, - item -> item.wrap(GHRepository.this)); + .withUrlPath(String.format("/repos/%s/%s/comments", getOwnerName(), name)) + .toIterable(GHCommitComment[].class, item -> item.wrap(this)); } /** @@ -1685,9 +1686,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listCommitStatuses(final String sha1) throws IOException { return root.createRequest() - .asPagedIterable(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1), - GHCommitStatus[].class, - item -> item.wrapUp(root)); + .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1)) + .toIterable(GHCommitStatus[].class, item -> item.wrapUp(root)); } /** @@ -1768,9 +1768,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listEvents() throws IOException { return root.createRequest() - .asPagedIterable(String.format("/repos/%s/%s/events", getOwnerName(), name), - GHEventInfo[].class, - item -> item.wrapUp(root)); + .withUrlPath(String.format("/repos/%s/%s/events", getOwnerName(), name)) + .toIterable(GHEventInfo[].class, item -> item.wrapUp(root)); } /** @@ -1784,7 +1783,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listLabels() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("labels"), GHLabel[].class, item -> item.wrapUp(GHRepository.this)); + .withUrlPath(getApiTailUrl("labels")) + .toIterable(GHLabel[].class, item -> item.wrapUp(this)); } /** @@ -1846,9 +1846,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listInvitations() { return root.createRequest() - .asPagedIterable(String.format("/repos/%s/%s/invitations", getOwnerName(), name), - GHInvitation[].class, - item -> item.wrapUp(root)); + .withUrlPath(String.format("/repos/%s/%s/invitations", getOwnerName(), name)) + .toIterable(GHInvitation[].class, item -> item.wrapUp(root)); } /** @@ -1881,13 +1880,14 @@ public class GHRepository extends GHObject { public PagedIterable listStargazers2() { return root.createRequest() .withPreview("application/vnd.github.v3.star+json") - .asPagedIterable(getApiTailUrl("stargazers"), - GHStargazer[].class, - item -> item.wrapUp(GHRepository.this)); + .withUrlPath(getApiTailUrl("stargazers")) + .toIterable(GHStargazer[].class, item -> item.wrapUp(this)); } private PagedIterable listUsers(final String suffix) { - return root.createRequest().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest() + .withUrlPath(getApiTailUrl(suffix)) + .toIterable(GHUser[].class, item -> item.wrapUp(root)); } /** @@ -2081,9 +2081,8 @@ public class GHRepository extends GHObject { public PagedIterable listMilestones(final GHIssueState state) { return root.createRequest() .with("state", state) - .asPagedIterable(getApiTailUrl("milestones"), - GHMilestone[].class, - item -> item.wrap(GHRepository.this)); + .withUrlPath(getApiTailUrl("milestones")) + .toIterable(GHMilestone[].class, item -> item.wrap(this)); } /** @@ -2416,7 +2415,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listContributors() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("contributors"), Contributor[].class, item -> item.wrapUp(root)); + .withUrlPath(getApiTailUrl("contributors")) + .toIterable(Contributor[].class, item -> item.wrapUp(root)); } /** @@ -2493,7 +2493,8 @@ public class GHRepository extends GHObject { return root.createRequest() .withPreview(INERTIA) .with("state", status) - .asPagedIterable(getApiTailUrl("projects"), GHProject[].class, item -> item.wrap(GHRepository.this)); + .withUrlPath(getApiTailUrl("projects")) + .toIterable(GHProject[].class, item -> item.wrap(this)); } /** @@ -2596,7 +2597,8 @@ public class GHRepository extends GHObject { */ public PagedIterable listIssueEvents() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("issues/events"), GHIssueEvent[].class, item -> item.wrapUp(root)); + .withUrlPath(getApiTailUrl("issues/events")) + .toIterable(GHIssueEvent[].class, item -> item.wrapUp(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 49b30bae7..4d3f99c54 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -88,7 +88,8 @@ public class GHRepositoryStatistics { */ private PagedIterable getContributorStatsImpl() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("contributors"), ContributorStats[].class, item -> item.wrapUp(root)); + .withUrlPath(getApiTailUrl("contributors")) + .toIterable(ContributorStats[].class, item -> item.wrapUp(root)); } /** @@ -244,7 +245,8 @@ public class GHRepositoryStatistics { */ public PagedIterable getCommitActivity() throws IOException { return root.createRequest() - .asPagedIterable(getApiTailUrl("commit_activity"), CommitActivity[].class, item -> item.wrapUp(root)); + .withUrlPath(getApiTailUrl("commit_activity")) + .toIterable(CommitActivity[].class, item -> item.wrapUp(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index b0f6f3c86..c74f634ae 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -123,7 +123,7 @@ public class GHTeam implements Refreshable { * the io exception */ public PagedIterable listMembers() throws IOException { - return root.createRequest().asPagedIterable(api("/members"), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().withUrlPath(api("/members")).toIterable(GHUser[].class, item -> item.wrapUp(root)); } /** @@ -174,7 +174,9 @@ public class GHTeam implements Refreshable { * @return the paged iterable */ public PagedIterable listRepositories() { - return root.createRequest().asPagedIterable(api("/repos"), GHRepository[].class, item -> item.wrap(root)); + return root.createRequest() + .withUrlPath(api("/repos")) + .toIterable(GHRepository[].class, item -> item.wrap(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 462478802..42149c2ab 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -110,7 +110,9 @@ public class GHUser extends GHPerson { } private PagedIterable listUser(final String suffix) { - return root.createRequest().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest() + .withUrlPath(getApiTailUrl(suffix)) + .toIterable(GHUser[].class, item -> item.wrapUp(root)); } /** @@ -135,7 +137,8 @@ public class GHUser extends GHPerson { private PagedIterable listRepositories(final String suffix) { return root.createRequest() - .asPagedIterable(getApiTailUrl(suffix), GHRepository[].class, item -> item.wrap(root)); + .withUrlPath(getApiTailUrl(suffix)) + .toIterable(GHRepository[].class, item -> item.wrap(root)); } /** @@ -202,9 +205,8 @@ public class GHUser extends GHPerson { */ public PagedIterable listEvents() throws IOException { return root.createRequest() - .asPagedIterable(String.format("/users/%s/events", login), - GHEventInfo[].class, - item -> item.wrapUp(root)); + .withUrlPath(String.format("/users/%s/events", login)) + .toIterable(GHEventInfo[].class, item -> item.wrapUp(root)); } /** @@ -216,9 +218,8 @@ public class GHUser extends GHPerson { */ public PagedIterable listGists() throws IOException { return root.createRequest() - .asPagedIterable(String.format("/users/%s/gists", login), - GHGist[].class, - item -> item.wrapUp(GHUser.this)); + .withUrlPath(String.format("/users/%s/gists", login)) + .toIterable(GHGist[].class, item -> item.wrapUp(this)); } @Override diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index d4ccad1ae..4a68ced4b 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -633,7 +633,8 @@ public class GitHub { */ public PagedIterable listOrganizations(final String since) { return createRequest().with("since", since) - .asPagedIterable("/organizations", GHOrganization[].class, item -> item.wrapUp(GitHub.this)); + .withUrlPath("/organizations") + .toIterable(GHOrganization[].class, item -> item.wrapUp(this)); } /** @@ -675,7 +676,7 @@ public class GitHub { * @see GitHub API - Licenses */ public PagedIterable listLicenses() throws IOException { - return createRequest().asPagedIterable("/licenses", GHLicense[].class, item -> item.wrap(GitHub.this)); + return createRequest().withUrlPath("/licenses").toIterable(GHLicense[].class, item -> item.wrap(this)); } /** @@ -686,7 +687,7 @@ public class GitHub { * the io exception */ public PagedIterable listUsers() throws IOException { - return createRequest().asPagedIterable("/users", GHUser[].class, item -> item.wrapUp(GitHub.this)); + return createRequest().withUrlPath("/users").toIterable(GHUser[].class, item -> item.wrapUp(this)); } /** @@ -717,9 +718,8 @@ public class GitHub { * Plans */ public PagedIterable listMarketplacePlans() throws IOException { - return createRequest().asPagedIterable("/marketplace_listing/plans", - GHMarketplacePlan[].class, - item -> item.wrapUp(GitHub.this)); + return createRequest().withUrlPath("/marketplace_listing/plans") + .toIterable(GHMarketplacePlan[].class, item -> item.wrapUp(this)); } /** @@ -773,9 +773,8 @@ public class GitHub { * Marketplace purchases */ public PagedIterable getMyMarketplacePurchases() throws IOException { - return createRequest().asPagedIterable("/user/marketplace_purchases", - GHMarketplaceUserPurchase[].class, - item -> item.wrapUp(this)); + return createRequest().withUrlPath("/user/marketplace_purchases") + .toIterable(GHMarketplaceUserPurchase[].class, item -> item.wrapUp(this)); } /** @@ -1100,8 +1099,8 @@ public class GitHub { * authorizations */ public PagedIterable listMyAuthorizations() throws IOException { - return createRequest() - .asPagedIterable("/authorizations", GHAuthorization[].class, item -> item.wrap(GitHub.this)); + return createRequest().withUrlPath("/authorizations") + .toIterable(GHAuthorization[].class, item -> item.wrap(this)); } /** @@ -1371,7 +1370,8 @@ public class GitHub { */ public PagedIterable listAllPublicRepositories(final String since) { return createRequest().with("since", since) - .asPagedIterable("/repositories", GHRepository[].class, item -> item.wrap(GitHub.this)); + .withUrlPath("/repositories") + .toIterable(GHRepository[].class, item -> item.wrap(this)); } /** diff --git a/src/main/java/org/kohsuke/github/PagedIterable.java b/src/main/java/org/kohsuke/github/PagedIterable.java index 536922e03..698136cc0 100644 --- a/src/main/java/org/kohsuke/github/PagedIterable.java +++ b/src/main/java/org/kohsuke/github/PagedIterable.java @@ -5,6 +5,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nonnull; + /** * {@link Iterable} that returns {@link PagedIterator} * @@ -33,6 +35,12 @@ public abstract class PagedIterable implements Iterable { return this; } + /** + * Returns an iterator over elements of type {@code T}. + * + * @return an Iterator. + */ + @Nonnull public final PagedIterator iterator() { return _iterator(size); } @@ -44,6 +52,7 @@ public abstract class PagedIterable implements Iterable { * the page size * @return the paged iterator */ + @Nonnull public abstract PagedIterator _iterator(int pageSize); /** @@ -52,7 +61,7 @@ public abstract class PagedIterable implements Iterable { * @return the list */ public List asList() { - List r = new ArrayList(); + ArrayList r = new ArrayList<>(); for (PagedIterator i = iterator(); i.hasNext();) { r.addAll(i.nextPage()); } @@ -65,7 +74,7 @@ public abstract class PagedIterable implements Iterable { * @return the set */ public Set asSet() { - LinkedHashSet r = new LinkedHashSet(); + LinkedHashSet r = new LinkedHashSet<>(); for (PagedIterator i = iterator(); i.hasNext();) { r.addAll(i.nextPage()); } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 60ba91148..912c14fc5 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -627,11 +627,7 @@ class Requester { return forceBody || !METHODS_WITHOUT_BODY.contains(method); } - PagedIterable asPagedIterable(String tailApiUrl, Class type, Consumer consumer) { - return withUrlPath(tailApiUrl).asPagedIterable(type, consumer); - } - - PagedIterable asPagedIterable(Class type, Consumer consumer) { + PagedIterable toIterable(Class type, Consumer consumer) { return new PagedIterableWithConsumer<>(type, consumer); } @@ -664,14 +660,20 @@ class Requester { /** * Loads paginated resources. * - * Every iterator call reports a new batch. + * @param type + * type of each page (not the items in the page). + * @param pageSize + * the size of the + * @param + * type of each page (not the items in the page). + * @return */ Iterator asIterator(Class type, int pageSize) { - if (method != "GET") { + if (!"GET".equals(method)) { throw new IllegalStateException("Request method \"GET\" is required for iterator."); } - if (pageSize != 0) + if (pageSize > 0) args.add(new Entry("per_page", pageSize)); String tailApiUrl = buildTailApiUrl(urlPath); diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index ea6f9f1cf..ad15b6b32 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -343,6 +343,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { assertThat(postcommitHooks.size(), equalTo(0)); } + @Test public void getRefs() throws Exception { GHRepository repo = getTempRepository(); GHRef[] refs = repo.getRefs();