Skip to content

Commit f2991da

Browse files
committed
Refactor pagination
1 parent 362faaf commit f2991da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+869
-1126
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ public PagedSearchIterable<GHRepository> listRepositories() {
267267

268268
request = root().createRequest().withUrlPath("/installation/repositories").build();
269269

270-
return new PagedSearchIterable<>(root(), request, GHAppInstallationRepositoryResult.class);
270+
return new PagedSearchIterable<>(new GitHubEndpointIterable<>(root()
271+
.getClient(), request, GHAppInstallationRepositoryResult.class, GHRepository.class, null));
271272
}
272273
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111
public class GHAppInstallationRequest extends GHObject {
1212
private GHOrganization account;
13-
1413
private GHUser requester;
1514

1615
/**
Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.kohsuke.github;
22

3-
import java.util.Iterator;
4-
5-
import javax.annotation.Nonnull;
6-
73
// TODO: Auto-generated Javadoc
84
/**
95
* Iterable for GHAppInstallation listing.
@@ -12,8 +8,6 @@ class GHAppInstallationsIterable extends PagedIterable<GHAppInstallation> {
128

139
/** The Constant APP_INSTALLATIONS_URL. */
1410
public static final String APP_INSTALLATIONS_URL = "/user/installations";
15-
private GHAppInstallationsPage result;
16-
private final transient GitHub root;
1711

1812
/**
1913
* Instantiates a new GH app installations iterable.
@@ -22,45 +16,10 @@ class GHAppInstallationsIterable extends PagedIterable<GHAppInstallation> {
2216
* the root
2317
*/
2418
public GHAppInstallationsIterable(GitHub root) {
25-
this.root = root;
26-
}
27-
28-
/**
29-
* Iterator.
30-
*
31-
* @param pageSize
32-
* the page size
33-
* @return the paged iterator
34-
*/
35-
@Nonnull
36-
@Override
37-
public PagedIterator<GHAppInstallation> _iterator(int pageSize) {
38-
final GitHubRequest request = root.createRequest().withUrlPath(APP_INSTALLATIONS_URL).build();
39-
return new PagedIterator<>(
40-
adapt(GitHubPageIterator.create(root.getClient(), GHAppInstallationsPage.class, request, pageSize)),
41-
null);
42-
}
43-
44-
/**
45-
* Adapt.
46-
*
47-
* @param base
48-
* the base
49-
* @return the iterator
50-
*/
51-
protected Iterator<GHAppInstallation[]> adapt(final Iterator<GHAppInstallationsPage> base) {
52-
return new Iterator<GHAppInstallation[]>() {
53-
public boolean hasNext() {
54-
return base.hasNext();
55-
}
56-
57-
public GHAppInstallation[] next() {
58-
GHAppInstallationsPage v = base.next();
59-
if (result == null) {
60-
result = v;
61-
}
62-
return v.getInstallations();
63-
}
64-
};
19+
super(new GitHubEndpointIterable<>(root.getClient(),
20+
root.createRequest().withUrlPath(APP_INSTALLATIONS_URL).build(),
21+
GHAppInstallationsPage.class,
22+
GHAppInstallation.class,
23+
null));
6524
}
6625
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
/**
55
* Represents the one page of GHAppInstallations.
66
*/
7-
class GHAppInstallationsPage {
7+
class GHAppInstallationsPage implements GitHubPage<GHAppInstallation> {
88
private GHAppInstallation[] installations;
99
private int totalCount;
1010

11+
@Override
12+
public GHAppInstallation[] getItems() {
13+
return getInstallations();
14+
}
15+
1116
/**
1217
* Gets the total count.
1318
*
Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
package org.kohsuke.github;
22

3-
import java.util.Iterator;
4-
5-
import javax.annotation.Nonnull;
6-
73
// TODO: Auto-generated Javadoc
84
/**
95
* Iterable for artifacts listing.
106
*/
117
class GHArtifactsIterable extends PagedIterable<GHArtifact> {
12-
private final transient GHRepository owner;
13-
private final GitHubRequest request;
14-
15-
private GHArtifactsPage result;
168

179
/**
1810
* Instantiates a new GH artifacts iterable.
@@ -23,45 +15,10 @@ class GHArtifactsIterable extends PagedIterable<GHArtifact> {
2315
* the request builder
2416
*/
2517
public GHArtifactsIterable(GHRepository owner, GitHubRequest.Builder<?> requestBuilder) {
26-
this.owner = owner;
27-
this.request = requestBuilder.build();
28-
}
29-
30-
/**
31-
* Iterator.
32-
*
33-
* @param pageSize
34-
* the page size
35-
* @return the paged iterator
36-
*/
37-
@Nonnull
38-
@Override
39-
public PagedIterator<GHArtifact> _iterator(int pageSize) {
40-
return new PagedIterator<>(
41-
adapt(GitHubPageIterator.create(owner.root().getClient(), GHArtifactsPage.class, request, pageSize)),
42-
null);
43-
}
44-
45-
/**
46-
* Adapt.
47-
*
48-
* @param base
49-
* the base
50-
* @return the iterator
51-
*/
52-
protected Iterator<GHArtifact[]> adapt(final Iterator<GHArtifactsPage> base) {
53-
return new Iterator<GHArtifact[]>() {
54-
public boolean hasNext() {
55-
return base.hasNext();
56-
}
57-
58-
public GHArtifact[] next() {
59-
GHArtifactsPage v = base.next();
60-
if (result == null) {
61-
result = v;
62-
}
63-
return v.getArtifacts(owner);
64-
}
65-
};
18+
super(new GitHubEndpointIterable<>(owner.root().getClient(),
19+
requestBuilder.build(),
20+
GHArtifactsPage.class,
21+
GHArtifact.class,
22+
item -> item.wrapUp(owner)));
6623
}
6724
}

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
*/
99
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
1010
justification = "JSON API")
11-
class GHArtifactsPage {
11+
class GHArtifactsPage implements GitHubPage<GHArtifact> {
1212
private GHArtifact[] artifacts;
1313
private int totalCount;
1414

15+
@Override
16+
public GHArtifact[] getItems() {
17+
return artifacts;
18+
}
19+
1520
/**
1621
* Gets the total count.
1722
*
@@ -20,18 +25,4 @@ class GHArtifactsPage {
2025
public int getTotalCount() {
2126
return totalCount;
2227
}
23-
24-
/**
25-
* Gets the artifacts.
26-
*
27-
* @param owner
28-
* the owner
29-
* @return the artifacts
30-
*/
31-
GHArtifact[] getArtifacts(GHRepository owner) {
32-
for (GHArtifact artifact : artifacts) {
33-
artifact.wrapUp(owner);
34-
}
35-
return artifacts;
36-
}
3728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public PagedSearchIterable<GHRepository> listRepositories() {
3939

4040
request = root().createRequest().withUrlPath("/installation/repositories").build();
4141

42-
return new PagedSearchIterable<>(root(), request, GHAuthenticatedAppInstallationRepositoryResult.class);
42+
return new PagedSearchIterable<>(new GitHubEndpointIterable<>(root()
43+
.getClient(), request, GHAuthenticatedAppInstallationRepositoryResult.class, GHRepository.class, null));
4344
}
4445

4546
}
Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
package org.kohsuke.github;
22

3-
import java.util.Iterator;
4-
5-
import javax.annotation.Nonnull;
6-
73
// TODO: Auto-generated Javadoc
84
/**
95
* Iterable for check-runs listing.
106
*/
117
class GHCheckRunsIterable extends PagedIterable<GHCheckRun> {
12-
private final GHRepository owner;
13-
private final GitHubRequest request;
14-
15-
private GHCheckRunsPage result;
16-
178
/**
189
* Instantiates a new GH check runs iterable.
1910
*
@@ -23,45 +14,7 @@ class GHCheckRunsIterable extends PagedIterable<GHCheckRun> {
2314
* the request
2415
*/
2516
public GHCheckRunsIterable(GHRepository owner, GitHubRequest request) {
26-
this.owner = owner;
27-
this.request = request;
28-
}
29-
30-
/**
31-
* Iterator.
32-
*
33-
* @param pageSize
34-
* the page size
35-
* @return the paged iterator
36-
*/
37-
@Nonnull
38-
@Override
39-
public PagedIterator<GHCheckRun> _iterator(int pageSize) {
40-
return new PagedIterator<>(
41-
adapt(GitHubPageIterator.create(owner.root().getClient(), GHCheckRunsPage.class, request, pageSize)),
42-
null);
43-
}
44-
45-
/**
46-
* Adapt.
47-
*
48-
* @param base
49-
* the base
50-
* @return the iterator
51-
*/
52-
protected Iterator<GHCheckRun[]> adapt(final Iterator<GHCheckRunsPage> base) {
53-
return new Iterator<GHCheckRun[]>() {
54-
public boolean hasNext() {
55-
return base.hasNext();
56-
}
57-
58-
public GHCheckRun[] next() {
59-
GHCheckRunsPage v = base.next();
60-
if (result == null) {
61-
result = v;
62-
}
63-
return v.getCheckRuns(owner);
64-
}
65-
};
17+
super(new GitHubEndpointIterable<>(owner.root()
18+
.getClient(), request, GHCheckRunsPage.class, GHCheckRun.class, item -> item.wrap(owner)));
6619
}
6720
}

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
*/
99
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
1010
justification = "JSON API")
11-
class GHCheckRunsPage {
11+
class GHCheckRunsPage implements GitHubPage<GHCheckRun> {
1212
private GHCheckRun[] checkRuns;
1313
private int totalCount;
1414

15+
@Override
16+
public GHCheckRun[] getItems() {
17+
return checkRuns;
18+
}
19+
1520
/**
1621
* Gets the total count.
1722
*
@@ -20,18 +25,4 @@ class GHCheckRunsPage {
2025
public int getTotalCount() {
2126
return totalCount;
2227
}
23-
24-
/**
25-
* Gets the check runs.
26-
*
27-
* @param owner
28-
* the owner
29-
* @return the check runs
30-
*/
31-
GHCheckRun[] getCheckRuns(GHRepository owner) {
32-
for (GHCheckRun checkRun : checkRuns) {
33-
checkRun.wrap(owner);
34-
}
35-
return checkRuns;
36-
}
3728
}

0 commit comments

Comments
 (0)