Skip to content

Commit 2b4b7a2

Browse files
committed
Clean up
1 parent d722709 commit 2b4b7a2

15 files changed

+65
-85
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,8 @@ public GHTargetType getTargetType() {
263263
*/
264264
@Deprecated
265265
public PagedSearchIterable<GHRepository> listRepositories() {
266-
GitHubRequest request;
267-
268-
request = root().createRequest().withUrlPath("/installation/repositories").build();
269-
270-
return new PagedSearchIterable<>(new PaginatedEndpoint<>(root()
271-
.getClient(), request, GHAppInstallationRepositoryResult.class, GHRepository.class, null));
266+
return new PagedSearchIterable<>(root().createRequest()
267+
.withUrlPath("/installation/repositories")
268+
.toPaginatedEndpoint(GHAppInstallationRepositoryResult.class, GHRepository.class, null));
272269
}
273270
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ protected GHAuthenticatedAppInstallation(@Nonnull GitHub root) {
3535
* @return the paged iterable
3636
*/
3737
public PagedSearchIterable<GHRepository> listRepositories() {
38-
GitHubRequest request;
39-
40-
request = root().createRequest().withUrlPath("/installation/repositories").build();
41-
42-
return new PagedSearchIterable<>(new PaginatedEndpoint<>(root()
43-
.getClient(), request, GHAuthenticatedAppInstallationRepositoryResult.class, GHRepository.class, null));
38+
return new PagedSearchIterable<>(root().createRequest()
39+
.withUrlPath("/installation/repositories")
40+
.toPaginatedEndpoint(GHAuthenticatedAppInstallationRepositoryResult.class, GHRepository.class, null));
4441
}
4542

4643
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ class GHCommitFileIterable extends PagedIterable<GHCommit.File> {
1717
*/
1818
private static final int GH_FILE_LIMIT_PER_COMMIT_PAGE = 300;
1919

20-
private static PaginatedEndpoint<GHCommitFilesPage, File> createEndpointIterable(GHRepository owner,
20+
private static PaginatedEndpoint<GHCommitFilesPage, File> createEndpoint(GHRepository owner,
2121
String sha,
2222
GHCommit.File[] files) {
2323
PaginatedEndpoint<GHCommitFilesPage, File> iterable;
2424
if (files != null && files.length < GH_FILE_LIMIT_PER_COMMIT_PAGE) {
2525
// create a page iterator that only provides one page
2626
iterable = PaginatedEndpoint.fromSinglePage(new GHCommitFilesPage(files), GHCommit.File.class);
2727
} else {
28-
GitHubRequest request = owner.root()
28+
iterable = owner.root()
2929
.createRequest()
3030
.withUrlPath(owner.getApiTailUrl("commits/" + sha))
31-
.build();
32-
iterable = new PaginatedEndpoint<>(owner.root()
33-
.getClient(), request, GHCommitFilesPage.class, GHCommit.File.class, null);
31+
.toPaginatedEndpoint(GHCommitFilesPage.class, GHCommit.File.class, null);
3432
}
3533
return iterable;
3634
}
@@ -45,8 +43,8 @@ private static PaginatedEndpoint<GHCommitFilesPage, File> createEndpointIterable
4543
* @param files
4644
* the list of files initially populated
4745
*/
48-
public GHCommitFileIterable(GHRepository owner, String sha, List<GHCommit.File> files) {
49-
super(createEndpointIterable(owner, sha, files != null ? files.toArray(new File[0]) : null));
46+
GHCommitFileIterable(GHRepository owner, String sha, List<GHCommit.File> files) {
47+
super(createEndpoint(owner, sha, files != null ? files.toArray(new File[0]) : null));
5048
}
5149

5250
@Override

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ public synchronized Map<String, GHRepository> getAllRepositories() {
113113
* app installations accessible to the user access token</a>
114114
*/
115115
public PagedIterable<GHAppInstallation> getAppInstallations() {
116-
return new PagedIterable<>(new PaginatedEndpoint<>(root().getClient(),
117-
root().createRequest().withUrlPath(APP_INSTALLATIONS_URL).build(),
118-
GHAppInstallationsPage.class,
119-
GHAppInstallation.class,
120-
null));
116+
return root().createRequest()
117+
.withUrlPath(APP_INSTALLATIONS_URL)
118+
.toIterable(GHAppInstallationsPage.class, GHAppInstallation.class, null);
121119
}
122120

123121
/**

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,11 +1189,7 @@ public Map<String, GHBranch> getBranches() throws IOException {
11891189
* for a specific ref</a>
11901190
*/
11911191
public PagedIterable<GHCheckRun> getCheckRuns(String ref) {
1192-
GitHubRequest request = root().createRequest()
1193-
.withUrlPath(String.format("/repos/%s/%s/commits/%s/check-runs", getOwnerName(), name, ref))
1194-
.build();
1195-
return new PagedIterable<>(new PaginatedEndpoint<>(root()
1196-
.getClient(), request, GHCheckRunsPage.class, GHCheckRun.class, item -> item.wrap(this)));
1192+
return getCheckRuns(ref, null);
11971193
}
11981194

11991195
/**
@@ -1208,12 +1204,10 @@ public PagedIterable<GHCheckRun> getCheckRuns(String ref) {
12081204
* for a specific ref</a>
12091205
*/
12101206
public PagedIterable<GHCheckRun> getCheckRuns(String ref, Map<String, Object> params) {
1211-
GitHubRequest request = root().createRequest()
1207+
Requester requester = root().createRequest()
12121208
.withUrlPath(String.format("/repos/%s/%s/commits/%s/check-runs", getOwnerName(), name, ref))
1213-
.with(params)
1214-
.build();
1215-
return new PagedIterable<>(new PaginatedEndpoint<>(root()
1216-
.getClient(), request, GHCheckRunsPage.class, GHCheckRun.class, item -> item.wrap(this)));
1209+
.with(params);
1210+
return requester.toIterable(GHCheckRunsPage.class, GHCheckRun.class, item -> item.wrap(this));
12171211
}
12181212

12191213
/**
@@ -2554,11 +2548,9 @@ public boolean isVulnerabilityAlertsEnabled() throws IOException {
25542548
* @return the paged iterable
25552549
*/
25562550
public PagedIterable<GHArtifact> listArtifacts() {
2557-
return new PagedIterable<>(new PaginatedEndpoint<>(this.root().getClient(),
2558-
root().createRequest().withUrlPath(getApiTailUrl("actions/artifacts")).build(),
2559-
GHArtifactsPage.class,
2560-
GHArtifact.class,
2561-
item -> item.wrapUp(this)));
2551+
return root().createRequest()
2552+
.withUrlPath(getApiTailUrl("actions/artifacts"))
2553+
.toIterable(GHArtifactsPage.class, GHArtifact.class, item -> item.wrapUp(this));
25622554
}
25632555

25642556
/**
@@ -2966,11 +2958,9 @@ public List<String> listTopics() throws IOException {
29662958
* @return the paged iterable
29672959
*/
29682960
public PagedIterable<GHWorkflow> listWorkflows() {
2969-
return new PagedIterable<>(new PaginatedEndpoint<>(root().getClient(),
2970-
root().createRequest().withUrlPath(getApiTailUrl("actions/workflows")).build(),
2971-
GHWorkflowsPage.class,
2972-
GHWorkflow.class,
2973-
item -> item.wrapUp(this)));
2961+
return root().createRequest()
2962+
.withUrlPath(getApiTailUrl("actions/workflows"))
2963+
.toIterable(GHWorkflowsPage.class, GHWorkflow.class, item -> item.wrapUp(this));
29742964
}
29752965

29762966
/**

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ public String getState() {
153153
* @return the paged iterable
154154
*/
155155
public PagedIterable<GHWorkflowRun> listRuns() {
156-
return new PagedIterable<>(new PaginatedEndpoint<>(owner.root().getClient(),
157-
root().createRequest().withUrlPath(getApiRoute(), "runs").build(),
158-
GHWorkflowRunsPage.class,
159-
GHWorkflowRun.class,
160-
item -> item.wrapUp(owner)));
156+
return root().createRequest()
157+
.withUrlPath(getApiRoute(), "runs")
158+
.toIterable(GHWorkflowRunsPage.class, GHWorkflowRun.class, item -> item.wrapUp(owner));
161159
}
162160

163161
private String getApiRoute() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public GHWorkflowJobQueryBuilder latest() {
4848
*/
4949
@Override
5050
public PagedIterable<GHWorkflowJob> list() {
51-
return new PagedIterable<>(new PaginatedEndpoint<>(repo.root()
52-
.getClient(), req.build(), GHWorkflowJobsPage.class, GHWorkflowJob.class, item -> item.wrapUp(repo)));
51+
return req.toIterable(GHWorkflowJobsPage.class, GHWorkflowJob.class, item -> item.wrapUp(repo));
5352
}
5453
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,9 @@ public PagedIterable<GHWorkflowJob> listAllJobs() {
579579
* @return the paged iterable
580580
*/
581581
public PagedIterable<GHArtifact> listArtifacts() {
582-
return new PagedIterable<>(new PaginatedEndpoint<>(owner.root().getClient(),
583-
root().createRequest().withUrlPath(getApiRoute(), "artifacts").build(),
584-
GHArtifactsPage.class,
585-
GHArtifact.class,
586-
item -> item.wrapUp(owner)));
582+
return root().createRequest()
583+
.withUrlPath(getApiRoute(), "artifacts")
584+
.toIterable(GHArtifactsPage.class, GHArtifact.class, item -> item.wrapUp(owner));
587585
}
588586

589587
/**

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,8 @@ public GHWorkflowRunQueryBuilder headSha(String headSha) {
133133
*/
134134
@Override
135135
public PagedIterable<GHWorkflowRun> list() {
136-
return new PagedIterable<>(new PaginatedEndpoint<>(repo.root().getClient(),
137-
req.withUrlPath(repo.getApiTailUrl("actions/runs")).build(),
138-
GHWorkflowRunsPage.class,
139-
GHWorkflowRun.class,
140-
item -> item.wrapUp(repo)));
136+
return req.withUrlPath(repo.getApiTailUrl("actions/runs"))
137+
.toIterable(GHWorkflowRunsPage.class, GHWorkflowRun.class, item -> item.wrapUp(repo));
141138
}
142139

143140
/**

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ public B with(@WillClose InputStream body) throws IOException {
323323
* @return the request builder
324324
*/
325325
public B with(Map<String, Object> map) {
326-
for (Map.Entry<String, Object> entry : map.entrySet()) {
327-
with(entry.getKey(), entry.getValue());
326+
if (map != null) {
327+
for (Map.Entry<String, Object> entry : map.entrySet()) {
328+
with(entry.getKey(), entry.getValue());
329+
}
328330
}
329-
330331
return (B) this;
331332
}
332333

0 commit comments

Comments
 (0)