diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index bebcdc7d8..5d559cbac 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -69,7 +69,10 @@ public class GHMyself extends GHUser { * the io exception */ public List getEmails2() throws IOException { - GHEmail[] addresses = root.createRequest().withUrlPath("/user/emails").fetchArray(GHEmail[].class); + GHEmail[] addresses = root.createRequest() + .withUrlPath("/user/emails") + .toIterable(GHEmail[].class, null) + .toArray(); return Collections.unmodifiableList(Arrays.asList(addresses)); } @@ -84,8 +87,8 @@ public class GHMyself extends GHUser { * the io exception */ public List getPublicKeys() throws IOException { - return Collections.unmodifiableList( - Arrays.asList(root.createRequest().withUrlPath("/user/keys").fetchArray(GHKey[].class))); + return Collections.unmodifiableList(Arrays + .asList(root.createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toArray())); } /** @@ -99,8 +102,10 @@ public class GHMyself extends GHUser { * the io exception */ public List getPublicVerifiedKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList( - root.createRequest().withUrlPath("/users/" + getLogin() + "/keys").fetchArray(GHVerifiedKey[].class))); + return Collections.unmodifiableList(Arrays.asList(root.createRequest() + .withUrlPath("/users/" + getLogin() + "/keys") + .toIterable(GHVerifiedKey[].class, null) + .toArray())); } /** @@ -113,7 +118,10 @@ public class GHMyself extends GHUser { public GHPersonSet getAllOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class)) { + for (GHOrganization o : root.createRequest() + .withUrlPath("/user/orgs") + .toIterable(GHOrganization[].class, null) + .toArray()) { if (names.add(o.getLogin())) // in case of rumoured duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 458c5a602..2ebde9d28 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -258,7 +258,7 @@ public class GHRelease extends GHObject { public List getAssets() throws IOException { Requester builder = owner.root.createRequest(); - GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).fetchArray(GHAsset[].class); + GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).toIterable(GHAsset[].class, null).toArray(); return Arrays.asList(GHAsset.wrap(assets, this)); } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index ff987ee0a..9ee25206a 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -376,8 +376,9 @@ public class GHRepository extends GHObject { Requester requester = root.createRequest() .with("state", state) .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()); - return Arrays - .asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).fetchArray(GHIssue[].class), this)); + return Arrays.asList( + GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).toIterable(GHIssue[].class, null).toArray(), + this)); } /** @@ -785,9 +786,10 @@ public class GHRepository extends GHObject { */ public Set getCollaboratorNames() throws IOException { Set r = new HashSet(); - for (GHUser u : GHUser.wrap( - root.createRequest().withUrlPath(getApiTailUrl("collaborators")).fetchArray(GHUser[].class), - root)) + for (GHUser u : GHUser.wrap(root.createRequest() + .withUrlPath(getApiTailUrl("collaborators")) + .toIterable(GHUser[].class, null) + .toArray(), root)) r.add(u.login); return r; } @@ -830,9 +832,9 @@ public class GHRepository extends GHObject { * the io exception */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(new HashSet(Arrays.asList( - GHTeam.wrapUp(root.createRequest().withUrlPath(getApiTailUrl("teams")).fetchArray(GHTeam[].class), - root.getOrganization(getOwnerName()))))); + return Collections.unmodifiableSet(new HashSet(Arrays.asList(GHTeam.wrapUp( + root.createRequest().withUrlPath(getApiTailUrl("teams")).toIterable(GHTeam[].class, null).toArray(), + root.getOrganization(getOwnerName()))))); } /** @@ -1451,7 +1453,8 @@ public class GHRepository extends GHObject { public GHRef[] getRefs() throws IOException { return GHRef.wrap(root.createRequest() .withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name)) - .fetchArray(GHRef[].class), root); + .toIterable(GHRef[].class, null) + .toArray(), root); } /** @@ -1478,7 +1481,8 @@ public class GHRepository extends GHObject { public GHRef[] getRefs(String refType) throws IOException { return GHRef.wrap(root.createRequest() .withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType)) - .fetchArray(GHRef[].class), root); + .toIterable(GHRef[].class, null) + .toArray(), root); } /** @@ -2071,7 +2075,10 @@ public class GHRepository extends GHObject { */ public Map getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.createRequest().withUrlPath(getApiTailUrl("branches")).fetchArray(GHBranch[].class)) { + for (GHBranch p : root.createRequest() + .withUrlPath(getApiTailUrl("branches")) + .toIterable(GHBranch[].class, null) + .toArray()) { p.wrap(this); r.put(p.getName(), p); } @@ -2203,7 +2210,10 @@ public class GHRepository extends GHObject { } String target = getApiTailUrl("contents/" + path); - GHContent[] files = requester.with("ref", ref).withUrlPath(target).fetchArray(GHContent[].class); + GHContent[] files = requester.with("ref", ref) + .withUrlPath(target) + .toIterable(GHContent[].class, null) + .toArray(); GHContent.wrap(files, this); @@ -2361,8 +2371,10 @@ public class GHRepository extends GHObject { * the io exception */ public List getDeployKeys() throws IOException { - List list = new ArrayList( - Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHDeployKey[].class))); + List list = new ArrayList(Arrays.asList(root.createRequest() + .withUrlPath(getApiTailUrl("keys")) + .toIterable(GHDeployKey[].class, null) + .toArray())); for (GHDeployKey h : list) h.wrap(this); return list; diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index ec1c18402..c5217ad77 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -41,8 +41,8 @@ public class GHUser extends GHPerson { * the io exception */ public List getKeys() throws IOException { - return Collections.unmodifiableList( - Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHKey[].class))); + return Collections.unmodifiableList(Arrays.asList( + root.createRequest().withUrlPath(getApiTailUrl("keys")).toIterable(GHKey[].class, null).toArray())); } /** @@ -191,7 +191,8 @@ public class GHUser extends GHPerson { Set names = new HashSet(); for (GHOrganization o : root.createRequest() .withUrlPath("/users/" + login + "/orgs") - .fetchArray(GHOrganization[].class)) { + .toIterable(GHOrganization[].class, null) + .toArray()) { if (names.add(o.getLogin())) // I've seen some duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index a20f09efe..2f1ce3d4c 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -600,7 +600,8 @@ public class GitHub { */ public List getMyInvitations() throws IOException { GHInvitation[] invitations = createRequest().withUrlPath("/user/repository_invitations") - .fetchArray(GHInvitation[].class); + .toIterable(GHInvitation[].class, null) + .toArray(); for (GHInvitation i : invitations) { i.wrapUp(this); } @@ -618,7 +619,9 @@ public class GitHub { * the io exception */ public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class); + GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs") + .toIterable(GHOrganization[].class, null) + .toArray(); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -672,7 +675,8 @@ public class GitHub { */ public Map getUserPublicOrganizations(String login) throws IOException { GHOrganization[] orgs = createRequest().withUrlPath("/users/" + login + "/orgs") - .fetchArray(GHOrganization[].class); + .toIterable(GHOrganization[].class, null) + .toArray(); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -693,7 +697,7 @@ public class GitHub { */ public Map> getMyTeams() throws IOException { Map> allMyTeams = new HashMap>(); - for (GHTeam team : createRequest().withUrlPath("/user/teams").fetchArray(GHTeam[].class)) { + for (GHTeam team : createRequest().withUrlPath("/user/teams").toIterable(GHTeam[].class, null).toArray()) { team.wrapUp(this); String orgLogin = team.getOrganization().getLogin(); Set teamsPerOrg = allMyTeams.get(orgLogin); @@ -727,7 +731,7 @@ public class GitHub { * the io exception */ public List getEvents() throws IOException { - GHEventInfo[] events = createRequest().withUrlPath("/events").fetchArray(GHEventInfo[].class); + GHEventInfo[] events = createRequest().withUrlPath("/events").toIterable(GHEventInfo[].class, null).toArray(); for (GHEventInfo e : events) e.wrapUp(this); return Arrays.asList(events); diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 56bb21f6c..0d7877b7f 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -68,21 +68,6 @@ class Requester extends GitHubRequest.Builder { return client.sendRequest(this, (responseInfo) -> GitHubResponse.parseBody(responseInfo, type)).body(); } - /** - * Sends a request and parses the response into an array of the given type via databinding. - * - * @param - * the type parameter - * @param type - * the type - * @return an array of {@link T} elements - * @throws IOException - * if the server returns 4xx/5xx responses. - */ - public T[] fetchArray(@Nonnull Class type) throws IOException { - return toIterable(client, type, null).toArray(); - } - /** * Like {@link #fetch(Class)} but updates an existing object instead of creating a new instance. *