Skip to content

Commit 4aef92e

Browse files
authored
Merge pull request hub4j#717 from bitwiseman/task/remove-fetch-array
Deprecate PagedIterable.asList() and PagedIterable.asSet()
2 parents b5c7f83 + 2ec5ca5 commit 4aef92e

29 files changed

Lines changed: 232 additions & 254 deletions

src/main/java/org/kohsuke/github/GHContent.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -387,22 +387,6 @@ GHContent wrap(GitHub root) {
387387
return this;
388388
}
389389

390-
/**
391-
* Wrap gh content [ ].
392-
*
393-
* @param contents
394-
* the contents
395-
* @param repository
396-
* the repository
397-
* @return the gh content [ ]
398-
*/
399-
public static GHContent[] wrap(GHContent[] contents, GHRepository repository) {
400-
for (GHContent unwrappedContent : contents) {
401-
unwrappedContent.wrap(repository);
402-
}
403-
return contents;
404-
}
405-
406390
/**
407391
* Fully populate the data by retrieving missing data.
408392
*

src/main/java/org/kohsuke/github/GHIssue.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ GHIssue wrap(GitHub root) {
100100
return this;
101101
}
102102

103-
static GHIssue[] wrap(GHIssue[] issues, GHRepository owner) {
104-
for (GHIssue i : issues)
105-
i.wrap(owner);
106-
return issues;
107-
}
108-
109103
/**
110104
* Repository to which the issue belongs.
111105
*
@@ -434,7 +428,7 @@ private void _removeLabels(Collection<String> names) throws IOException {
434428
* @see #listComments() #listComments()
435429
*/
436430
public List<GHIssueComment> getComments() throws IOException {
437-
return listComments().asList();
431+
return listComments().toList();
438432
}
439433

440434
/**

src/main/java/org/kohsuke/github/GHMembership.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ GHMembership wrap(GitHub root) {
8383
return this;
8484
}
8585

86-
static void wrap(GHMembership[] page, GitHub root) {
87-
for (GHMembership m : page)
88-
m.wrap(root);
89-
}
90-
9186
/**
9287
* Role of a user in an organization.
9388
*/

src/main/java/org/kohsuke/github/GHMyself.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.IOException;
44
import java.util.ArrayList;
5-
import java.util.Arrays;
65
import java.util.Collections;
76
import java.util.HashSet;
87
import java.util.List;
@@ -69,8 +68,7 @@ public List<String> getEmails() throws IOException {
6968
* the io exception
7069
*/
7170
public List<GHEmail> getEmails2() throws IOException {
72-
GHEmail[] addresses = root.createRequest().withUrlPath("/user/emails").fetchArray(GHEmail[].class);
73-
return Collections.unmodifiableList(Arrays.asList(addresses));
71+
return root.createRequest().withUrlPath("/user/emails").toIterable(GHEmail[].class, null).toList();
7472
}
7573

7674
/**
@@ -84,8 +82,7 @@ public List<GHEmail> getEmails2() throws IOException {
8482
* the io exception
8583
*/
8684
public List<GHKey> getPublicKeys() throws IOException {
87-
return Collections.unmodifiableList(
88-
Arrays.asList(root.createRequest().withUrlPath("/user/keys").fetchArray(GHKey[].class)));
85+
return root.createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toList();
8986
}
9087

9188
/**
@@ -99,8 +96,10 @@ public List<GHKey> getPublicKeys() throws IOException {
9996
* the io exception
10097
*/
10198
public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
102-
return Collections.unmodifiableList(Arrays.asList(
103-
root.createRequest().withUrlPath("/users/" + getLogin() + "/keys").fetchArray(GHVerifiedKey[].class)));
99+
return root.createRequest()
100+
.withUrlPath("/users/" + getLogin() + "/keys")
101+
.toIterable(GHVerifiedKey[].class, null)
102+
.toList();
104103
}
105104

106105
/**
@@ -113,7 +112,10 @@ public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
113112
public GHPersonSet<GHOrganization> getAllOrganizations() throws IOException {
114113
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
115114
Set<String> names = new HashSet<String>();
116-
for (GHOrganization o : root.createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class)) {
115+
for (GHOrganization o : root.createRequest()
116+
.withUrlPath("/user/orgs")
117+
.toIterable(GHOrganization[].class, null)
118+
.toArray()) {
117119
if (names.add(o.getLogin())) // in case of rumoured duplicates in the data
118120
orgs.add(root.getOrganization(o.getLogin()));
119121
}

src/main/java/org/kohsuke/github/GHNotificationStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ GHThread fetch() {
181181

182182
Requester requester = req.withUrlPath(apiUrl);
183183
GitHubResponse<GHThread[]> response = ((GitHubPageContentsIterable<GHThread>) requester
184-
.toIterable(requester.client, GHThread[].class, null)).toResponse();
184+
.toIterable(GHThread[].class, null)).toResponse();
185185
threads = response.body();
186186

187187
if (threads == null) {

src/main/java/org/kohsuke/github/GHOrganization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public void publicize(GHUser u) throws IOException {
253253
* @deprecated use {@link #listMembers()}
254254
*/
255255
public List<GHUser> getMembers() throws IOException {
256-
return listMembers().asList();
256+
return listMembers().toList();
257257
}
258258

259259
/**

src/main/java/org/kohsuke/github/GHPerson.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.FileNotFoundException;
44
import java.io.IOException;
5+
import java.net.MalformedURLException;
56
import java.net.URL;
67
import java.util.Arrays;
78
import java.util.Collections;
@@ -116,9 +117,15 @@ public PagedIterable<GHRepository> listRepositories(final int pageSize) {
116117
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
117118
return new Iterable<List<GHRepository>>() {
118119
public Iterator<List<GHRepository>> iterator() {
119-
final Iterator<GHRepository[]> pager = GitHubPageIterator.create(root.getClient(),
120-
GHRepository[].class,
121-
root.createRequest().withUrlPath("users", login, "repos").withPageSize(pageSize));
120+
final Iterator<GHRepository[]> pager;
121+
try {
122+
pager = GitHubPageIterator.create(root.getClient(),
123+
GHRepository[].class,
124+
root.createRequest().withUrlPath("users", login, "repos").build(),
125+
pageSize);
126+
} catch (MalformedURLException e) {
127+
throw new GHException("Unable to build GitHub API URL", e);
128+
}
122129

123130
return new Iterator<List<GHRepository>>() {
124131
public boolean hasNext() {

src/main/java/org/kohsuke/github/GHRef.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ GHRef wrap(GitHub root) {
8888
return this;
8989
}
9090

91-
static GHRef[] wrap(GHRef[] in, GitHub root) {
92-
for (GHRef r : in) {
93-
r.wrap(root);
94-
}
95-
return in;
96-
}
97-
9891
/**
9992
* The type GHObject.
10093
*/

src/main/java/org/kohsuke/github/GHRelease.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.io.InputStream;
77
import java.net.URL;
88
import java.net.URLEncoder;
9-
import java.util.Arrays;
109
import java.util.Date;
1110
import java.util.List;
1211

@@ -258,8 +257,9 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy
258257
public List<GHAsset> getAssets() throws IOException {
259258
Requester builder = owner.root.createRequest();
260259

261-
GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).fetchArray(GHAsset[].class);
262-
return Arrays.asList(GHAsset.wrap(assets, this));
260+
return builder.withUrlPath(getApiTailUrl("assets"))
261+
.toIterable(GHAsset[].class, item -> item.wrap(this))
262+
.toList();
263263
}
264264

265265
/**

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.net.URL;
4040
import java.util.AbstractSet;
4141
import java.util.ArrayList;
42-
import java.util.Arrays;
4342
import java.util.Collection;
4443
import java.util.Collections;
4544
import java.util.Date;
@@ -358,7 +357,7 @@ public GHIssueBuilder createIssue(String title) {
358357
* the io exception
359358
*/
360359
public List<GHIssue> getIssues(GHIssueState state) throws IOException {
361-
return listIssues(state).asList();
360+
return listIssues(state).toList();
362361
}
363362

364363
/**
@@ -376,8 +375,9 @@ public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws
376375
Requester requester = root.createRequest()
377376
.with("state", state)
378377
.with("milestone", milestone == null ? "none" : "" + milestone.getNumber());
379-
return Arrays
380-
.asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).fetchArray(GHIssue[].class), this));
378+
return requester.withUrlPath(getApiTailUrl("issues"))
379+
.toIterable(GHIssue[].class, item -> item.wrap(this))
380+
.toList();
381381
}
382382

383383
/**
@@ -436,7 +436,7 @@ public GHRef createRef(String name, String sha) throws IOException {
436436
* @deprecated use {@link #listReleases()}
437437
*/
438438
public List<GHRelease> getReleases() throws IOException {
439-
return listReleases().asList();
439+
return listReleases().toList();
440440
}
441441

442442
/**
@@ -734,7 +734,7 @@ public int getSize() {
734734
*/
735735
@WithBridgeMethods(Set.class)
736736
public GHPersonSet<GHUser> getCollaborators() throws IOException {
737-
return new GHPersonSet<GHUser>(listCollaborators().asList());
737+
return new GHPersonSet<GHUser>(listCollaborators().toList());
738738
}
739739

740740
/**
@@ -784,11 +784,14 @@ public boolean hasAssignee(GHUser u) throws IOException {
784784
* the io exception
785785
*/
786786
public Set<String> getCollaboratorNames() throws IOException {
787-
Set<String> r = new HashSet<String>();
788-
for (GHUser u : GHUser.wrap(
789-
root.createRequest().withUrlPath(getApiTailUrl("collaborators")).fetchArray(GHUser[].class),
790-
root))
787+
Set<String> r = new HashSet<>();
788+
// no initializer - we just want to the logins
789+
PagedIterable<GHUser> users = root.createRequest()
790+
.withUrlPath(getApiTailUrl("collaborators"))
791+
.toIterable(GHUser[].class, null);
792+
for (GHUser u : users.toArray()) {
791793
r.add(u.login);
794+
}
792795
return r;
793796
}
794797

@@ -830,9 +833,11 @@ public GHPermissionType getPermission(GHUser u) throws IOException {
830833
* the io exception
831834
*/
832835
public Set<GHTeam> getTeams() throws IOException {
833-
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(
834-
GHTeam.wrapUp(root.createRequest().withUrlPath(getApiTailUrl("teams")).fetchArray(GHTeam[].class),
835-
root.getOrganization(getOwnerName())))));
836+
GHOrganization org = root.getOrganization(getOwnerName());
837+
return root.createRequest()
838+
.withUrlPath(getApiTailUrl("teams"))
839+
.toIterable(GHTeam[].class, item -> item.wrapUp(org))
840+
.toSet();
836841
}
837842

838843
/**
@@ -1238,7 +1243,7 @@ public GHPullRequest getPullRequest(int i) throws IOException {
12381243
* @see #listPullRequests(GHIssueState) #listPullRequests(GHIssueState)
12391244
*/
12401245
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
1241-
return queryPullRequests().state(state).list().asList();
1246+
return queryPullRequests().state(state).list().toList();
12421247
}
12431248

12441249
/**
@@ -1449,9 +1454,7 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException {
14491454
* on failure communicating with GitHub
14501455
*/
14511456
public GHRef[] getRefs() throws IOException {
1452-
return GHRef.wrap(root.createRequest()
1453-
.withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name))
1454-
.fetchArray(GHRef[].class), root);
1457+
return listRefs().toArray();
14551458
}
14561459

14571460
/**
@@ -1476,9 +1479,7 @@ public PagedIterable<GHRef> listRefs() throws IOException {
14761479
* on failure communicating with GitHub, potentially due to an invalid ref type being requested
14771480
*/
14781481
public GHRef[] getRefs(String refType) throws IOException {
1479-
return GHRef.wrap(root.createRequest()
1480-
.withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType))
1481-
.fetchArray(GHRef[].class), root);
1482+
return listRefs(refType).toArray();
14821483
}
14831484

14841485
/**
@@ -1736,7 +1737,7 @@ public PagedIterable<GHCommitStatus> listCommitStatuses(final String sha1) throw
17361737
* the io exception
17371738
*/
17381739
public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
1739-
List<GHCommitStatus> v = listCommitStatuses(sha1).asList();
1740+
List<GHCommitStatus> v = listCommitStatuses(sha1).toList();
17401741
return v.isEmpty() ? null : v.get(0);
17411742
}
17421743

@@ -2071,8 +2072,10 @@ GHRepository wrap(GitHub root) {
20712072
*/
20722073
public Map<String, GHBranch> getBranches() throws IOException {
20732074
Map<String, GHBranch> r = new TreeMap<String, GHBranch>();
2074-
for (GHBranch p : root.createRequest().withUrlPath(getApiTailUrl("branches")).fetchArray(GHBranch[].class)) {
2075-
p.wrap(this);
2075+
for (GHBranch p : root.createRequest()
2076+
.withUrlPath(getApiTailUrl("branches"))
2077+
.toIterable(GHBranch[].class, item -> item.wrap(this))
2078+
.toArray()) {
20762079
r.put(p.getName(), p);
20772080
}
20782081
return r;
@@ -2203,11 +2206,10 @@ public List<GHContent> getDirectoryContent(String path, String ref) throws IOExc
22032206
}
22042207
String target = getApiTailUrl("contents/" + path);
22052208

2206-
GHContent[] files = requester.with("ref", ref).withUrlPath(target).fetchArray(GHContent[].class);
2207-
2208-
GHContent.wrap(files, this);
2209-
2210-
return Arrays.asList(files);
2209+
return requester.with("ref", ref)
2210+
.withUrlPath(target)
2211+
.toIterable(GHContent[].class, item -> item.wrap(this))
2212+
.toList();
22112213
}
22122214

22132215
/**
@@ -2361,11 +2363,10 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException {
23612363
* the io exception
23622364
*/
23632365
public List<GHDeployKey> getDeployKeys() throws IOException {
2364-
List<GHDeployKey> list = new ArrayList<GHDeployKey>(
2365-
Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHDeployKey[].class)));
2366-
for (GHDeployKey h : list)
2367-
h.wrap(this);
2368-
return list;
2366+
return root.createRequest()
2367+
.withUrlPath(getApiTailUrl("keys"))
2368+
.toIterable(GHDeployKey[].class, item -> item.wrap(this))
2369+
.toList();
23692370
}
23702371

23712372
/**

0 commit comments

Comments
 (0)