diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index affdf9eca1..311dfccc1b 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -178,7 +178,7 @@ GHApp wrapUp(GitHub root) { @Preview @Deprecated public PagedIterable listInstallations() { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) .asPagedIterable("/app/installations", GHAppInstallation[].class, item -> item.wrapUp(root)); } @@ -198,9 +198,10 @@ public PagedIterable listInstallations() { @Preview @Deprecated public GHAppInstallation getInstallationById(long id) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) - .to(String.format("/app/installations/%d", id), GHAppInstallation.class) + .withUrlPath(String.format("/app/installations/%d", id)) + .fetch(GHAppInstallation.class) .wrapUp(root); } @@ -220,9 +221,10 @@ public GHAppInstallation getInstallationById(long id) throws IOException { @Preview @Deprecated public GHAppInstallation getInstallationByOrganization(String name) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) - .to(String.format("/orgs/%s/installation", name), GHAppInstallation.class) + .withUrlPath(String.format("/orgs/%s/installation", name)) + .fetch(GHAppInstallation.class) .wrapUp(root); } @@ -244,9 +246,10 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc @Preview @Deprecated public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) - .to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class) + .withUrlPath(String.format("/repos/%s/%s/installation", ownerName, repositoryName)) + .fetch(GHAppInstallation.class) .wrapUp(root); } @@ -265,9 +268,10 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re @Preview @Deprecated public GHAppInstallation getInstallationByUser(String name) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) - .to(String.format("/users/%s/installation", name), GHAppInstallation.class) + .withUrlPath(String.format("/users/%s/installation", name)) + .fetch(GHAppInstallation.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 29830425ba..7631204f45 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -23,7 +23,7 @@ public class GHAppCreateTokenBuilder { GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = new Requester(root); + this.builder = root.createRequest(); withPermissions(builder, permissions); } @@ -57,7 +57,8 @@ public GHAppCreateTokenBuilder repositoryIds(List repositoryIds) { public GHAppInstallationToken create() throws IOException { return builder.method("POST") .withPreview(MACHINE_MAN) - .to(apiUrlTail, GHAppInstallationToken.class) + .withUrlPath(apiUrlTail) + .fetch(GHAppInstallationToken.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index a9f2043c31..68ca25c90b 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -271,7 +271,11 @@ GHAppInstallation wrapUp(GitHub root) { @Preview @Deprecated public void deleteInstallation() throws IOException { - root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id)); + root.createRequest() + .method("DELETE") + .withPreview(GAMBIT) + .withUrlPath(String.format("/app/installations/%d", id)) + .send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 0003c9703d..694ff91b2d 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() { } private void edit(String key, Object value) throws IOException { - new Requester(root).with(key, value).method("PATCH").to(getApiRoute()); + root.createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } /** @@ -145,7 +145,7 @@ private void edit(String key, Object value) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(getApiRoute()); + root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } private String getApiRoute() { diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index d11ff943f5..d94abe7354 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -12,7 +12,7 @@ public class GHBlobBuilder { GHBlobBuilder(GHRepository repo) { this.repo = repo; - req = new Requester(repo.root); + req = repo.root.createRequest(); } /** @@ -54,6 +54,6 @@ private String getApiTail() { * if the blob cannot be created. */ public GHBlob create() throws IOException { - return req.method("POST").to(getApiTail(), GHBlob.class); + return req.method("POST").withUrlPath(getApiTail()).fetch(GHBlob.class); } } diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 7e1ff1a4f7..7b945107c0 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -9,8 +9,6 @@ import java.util.Collection; import java.util.Objects; -import static org.kohsuke.github.Previews.*; - /** * A branch in a repository. * @@ -103,7 +101,7 @@ public URL getProtectionUrl() { * the io exception */ public GHBranchProtection getProtection() throws IOException { - return root.retrieve().to(protection_url, GHBranchProtection.class).wrap(this); + return root.createRequest().withUrlPath(protection_url).fetch(GHBranchProtection.class).wrap(this); } /** @@ -122,7 +120,7 @@ public String getSHA1() { * if disabling protection fails */ public void disableProtection() throws IOException { - new Requester(root).method("DELETE").to(protection_url); + root.createRequest().method("DELETE").withUrlPath(protection_url).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 4c9246d9de..8782a74ec9 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -44,7 +44,7 @@ public class GHBranchProtection { @Preview @Deprecated public void enabledSignedCommits() throws IOException { - requester().method("POST").to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class); + requester().method("POST").withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class); } /** @@ -56,7 +56,7 @@ public void enabledSignedCommits() throws IOException { @Preview @Deprecated public void disableSignedCommits() throws IOException { - requester().method("DELETE").to(url + REQUIRE_SIGNATURES_URI); + requester().method("DELETE").withUrlPath(url + REQUIRE_SIGNATURES_URI).send(); } /** @@ -87,7 +87,7 @@ public RequiredReviews getRequiredReviews() { @Preview @Deprecated public boolean getRequiredSignatures() throws IOException { - return requester().method("GET").to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled; + return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class).enabled; } /** @@ -123,7 +123,7 @@ GHBranchProtection wrap(GHBranch branch) { } private Requester requester() { - return new Requester(root).withPreview(ZZZAX); + return root.createRequest().withPreview(ZZZAX); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index c94020b306..9f60aec13b 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -93,7 +93,8 @@ public GHBranchProtection enable() throws IOException { .withNullable("required_pull_request_reviews", prReviews) .withNullable("restrictions", restrictions) .withNullable("enforce_admins", enforceAdmins) - .to(branch.getProtectionUrl().toString(), GHBranchProtection.class) + .withUrlPath(branch.getProtectionUrl().toString()) + .fetch(GHBranchProtection.class) .wrap(branch); } @@ -352,7 +353,7 @@ private StatusChecks getStatusChecks() { } private Requester requester() { - return new Requester(branch.getRoot()).withPreview(LUKE_CAGE); + return branch.getRoot().createRequest().withPreview(LUKE_CAGE); } private static class Restrictions { diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index b1e7b7dc06..515410a37d 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -441,7 +441,7 @@ private GHUser resolveUser(User author) throws IOException { * @return {@link PagedIterable} with all the commit comments in this repository. */ public PagedIterable listComments() { - return owner.root.retrieve() + return owner.root.createRequest() .asPagedIterable( String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class, @@ -466,12 +466,15 @@ public PagedIterable listComments() { * if comment is not created */ public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException { - GHCommitComment r = new Requester(owner.root).with("body", body) + GHCommitComment r = owner.root.createRequest() + .method("POST") + .with("body", body) .with("path", path) .with("line", line) .with("position", position) - .to(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), - GHCommitComment.class); + .withUrlPath( + String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha)) + .fetch(GHCommitComment.class); return r.wrap(owner); } @@ -518,7 +521,7 @@ public GHCommitStatus getLastStatus() throws IOException { */ void populate() throws IOException { if (files == null && stats == null) - owner.root.retrieve().to(owner.getApiTailUrl("commits/" + sha), this); + owner.root.createRequest().withUrlPath(owner.getApiTailUrl("commits/" + sha)).fetchInto(this); } GHCommit wrapUp(GHRepository owner) { diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 71335ee02a..c7b459a22d 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -34,7 +34,7 @@ private UserInfo(String name, String email, Date date) { GHCommitBuilder(GHRepository repo) { this.repo = repo; - req = new Requester(repo.root); + req = repo.root.createRequest().method("POST"); } /** @@ -118,6 +118,6 @@ private String getApiTail() { */ public GHCommit create() throws IOException { req.with("parents", parents); - return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo); + return req.method("POST").withUrlPath(getApiTail()).fetch(GHCommit.class).wrapUp(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index e53e8607f0..b3da925c8f 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -113,23 +113,30 @@ public GHCommit getCommit() throws IOException { * the io exception */ public void update(String body) throws IOException { - new Requester(owner.root).with("body", body).method("PATCH").to(getApiTail(), GHCommitComment.class); + owner.root.createRequest() + .method("PATCH") + .with("body", body) + .withUrlPath(getApiTail()) + .fetch(GHCommitComment.class); this.body = body; } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.createRequest() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiTail() + "/reactions", GHReaction.class) + .withUrlPath(getApiTail() + "/reactions") + .fetch(GHReaction.class) .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiTail() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } @@ -141,7 +148,7 @@ public PagedIterable listReactions() { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiTail()); + owner.root.createRequest().method("DELETE").withUrlPath(getApiTail()).send(); } private String getApiTail() { diff --git a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java index dc544b390e..0350ec4a3b 100644 --- a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java @@ -24,7 +24,7 @@ public class GHCommitQueryBuilder { GHCommitQueryBuilder(GHRepository repo) { this.repo = repo; - this.req = repo.root.retrieve(); // requester to build up + this.req = repo.root.createRequest(); // requester to build up } /** diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 3ac5feba7e..e8db82305b 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -223,7 +223,7 @@ public boolean isDirectory() { * the io exception */ protected synchronized void populate() throws IOException { - root.retrieve().to(url, this); + root.createRequest().withUrlPath(url).fetchInto(this); } /** @@ -237,7 +237,9 @@ public PagedIterable listDirectoryContent() throws IOException { if (!isDirectory()) throw new IllegalStateException(path + " is not a directory"); - return root.retrieve().asPagedIterable(url, GHContent[].class, item -> item.wrap(repository)); + return root.createRequest() + .setRawUrlPath(url) + .asPagedIterable(GHContent[].class, item -> item.wrap(repository)); } /** @@ -306,7 +308,9 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa throws IOException { String encodedContent = Base64.getMimeEncoder().encodeToString(newContentBytes); - Requester requester = new Requester(root).with("path", path) + Requester requester = root.createRequest() + .method("POST") + .with("path", path) .with("message", commitMessage) .with("sha", sha) .with("content", encodedContent) @@ -316,7 +320,8 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa requester.with("branch", branch); } - GHContentUpdateResponse response = requester.to(getApiRoute(repository, path), GHContentUpdateResponse.class); + GHContentUpdateResponse response = requester.withUrlPath(getApiRoute(repository, path)) + .fetch(GHContentUpdateResponse.class); response.getContent().wrap(repository); response.getCommit().wrapUp(repository); @@ -350,7 +355,9 @@ public GHContentUpdateResponse delete(String message) throws IOException { * the io exception */ public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException { - Requester requester = new Requester(root).with("path", path) + Requester requester = root.createRequest() + .method("POST") + .with("path", path) .with("message", commitMessage) .with("sha", sha) .method("DELETE"); @@ -359,7 +366,8 @@ public GHContentUpdateResponse delete(String commitMessage, String branch) throw requester.with("branch", branch); } - GHContentUpdateResponse response = requester.to(getApiRoute(repository, path), GHContentUpdateResponse.class); + GHContentUpdateResponse response = requester.withUrlPath(getApiRoute(repository, path)) + .fetch(GHContentUpdateResponse.class); response.getCommit().wrapUp(repository); return response; @@ -405,6 +413,6 @@ public static GHContent[] wrap(GHContent[] contents, GHRepository repository) { */ @Override public synchronized void refresh() throws IOException { - root.retrieve().to(url, this); + root.createRequest().setRawUrlPath(url).fetchInto(this); } } diff --git a/src/main/java/org/kohsuke/github/GHContentBuilder.java b/src/main/java/org/kohsuke/github/GHContentBuilder.java index f89ed2582f..48b63769be 100644 --- a/src/main/java/org/kohsuke/github/GHContentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHContentBuilder.java @@ -20,7 +20,7 @@ public final class GHContentBuilder { GHContentBuilder(GHRepository repo) { this.repo = repo; - this.req = new Requester(repo.root).method("PUT"); + this.req = repo.root.createRequest().method("PUT"); } /** @@ -49,7 +49,7 @@ public GHContentBuilder branch(String branch) { } /** - * Used when updating (but not creating a new content) to specify Thetblob SHA of the file being replaced. + * Used when updating (but not creating a new content) to specify the blob SHA of the file being replaced. * * @param sha * the sha @@ -103,7 +103,8 @@ public GHContentBuilder message(String commitMessage) { * the io exception */ public GHContentUpdateResponse commit() throws IOException { - GHContentUpdateResponse response = req.to(GHContent.getApiRoute(repo, path), GHContentUpdateResponse.class); + GHContentUpdateResponse response = req.withUrlPath(GHContent.getApiRoute(repo, path)) + .fetch(GHContentUpdateResponse.class); response.getContent().wrap(repo); response.getCommit().wrapUp(repo); diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 268bfa8ef3..d25e3b4446 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -16,7 +16,7 @@ public class GHCreateRepositoryBuilder { GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = new Requester(root); + this.builder = root.createRequest(); this.builder.with("name", name); } @@ -196,7 +196,7 @@ public GHCreateRepositoryBuilder team(GHTeam team) { * if repsitory cannot be created */ public GHRepository create() throws IOException { - return builder.method("POST").to(apiUrlTail, GHRepository.class).wrap(root); + return builder.method("POST").withUrlPath(apiUrlTail).fetch(GHRepository.class).wrap(root); } } diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index f9bd1acd52..ddcbff0450 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -82,7 +82,9 @@ public String toString() { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE") - .to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)); + owner.root.createRequest() + .method("DELETE") + .withUrlPath(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)) + .send(); } } diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index 601bf258d6..01451cf9f5 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -131,7 +131,7 @@ public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) { * @return the paged iterable */ public PagedIterable listStatuses() { - return root.retrieve().asPagedIterable(statuses_url, GHDeploymentStatus[].class, item -> item.wrap(owner)); + return root.createRequest().asPagedIterable(statuses_url, GHDeploymentStatus[].class, item -> item.wrap(owner)); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java index c041538069..9677f55b6e 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java @@ -19,7 +19,7 @@ public class GHDeploymentBuilder { */ public GHDeploymentBuilder(GHRepository repo) { this.repo = repo; - this.builder = new Requester(repo.root); + this.builder = repo.root.createRequest().method("POST"); } /** @@ -127,6 +127,6 @@ public GHDeploymentBuilder description(String description) { * the io exception */ public GHDeployment create() throws IOException { - return builder.to(repo.getApiTailUrl("deployments"), GHDeployment.class).wrap(repo); + return builder.withUrlPath(repo.getApiTailUrl("deployments")).fetch(GHDeployment.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java index 31e54e64b1..34ff201a33 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java @@ -30,7 +30,7 @@ public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeployme GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) { this.repo = repo; this.deploymentId = deploymentId; - this.builder = new Requester(repo.root); + this.builder = repo.root.createRequest().method("POST"); this.builder.with("state", state); } @@ -66,7 +66,8 @@ public GHDeploymentStatusBuilder targetUrl(String targetUrl) { * the io exception */ public GHDeploymentStatus create() throws IOException { - return builder.to(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses"), GHDeploymentStatus.class) + return builder.withUrlPath(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses")) + .fetch(GHDeploymentStatus.class) .wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index d772d3dd77..86365b1c33 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -182,7 +182,7 @@ String getApiTailUrl(String tail) { * the io exception */ public void star() throws IOException { - new Requester(root).method("PUT").to(getApiTailUrl("star")); + root.createRequest().method("PUT").withUrlPath(getApiTailUrl("star")).send(); } /** @@ -192,7 +192,7 @@ public void star() throws IOException { * the io exception */ public void unstar() throws IOException { - new Requester(root).method("DELETE").to(getApiTailUrl("star")); + root.createRequest().method("DELETE").withUrlPath(getApiTailUrl("star")).send(); } /** @@ -203,7 +203,7 @@ public void unstar() throws IOException { * the io exception */ public boolean isStarred() throws IOException { - return root.retrieve().asHttpStatusCode(getApiTailUrl("star")) / 100 == 2; + return root.createRequest().withUrlPath(getApiTailUrl("star")).fetchHttpStatusCode() / 100 == 2; } /** @@ -214,7 +214,7 @@ public boolean isStarred() throws IOException { * the io exception */ public GHGist fork() throws IOException { - return new Requester(root).to(getApiTailUrl("forks"), GHGist.class).wrapUp(root); + return root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).fetch(GHGist.class).wrapUp(root); } /** @@ -223,7 +223,7 @@ public GHGist fork() throws IOException { * @return the paged iterable */ public PagedIterable listForks() { - return root.retrieve().asPagedIterable(getApiTailUrl("forks"), GHGist[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(getApiTailUrl("forks"), GHGist[].class, item -> item.wrapUp(root)); } /** @@ -233,7 +233,7 @@ public PagedIterable listForks() { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to("/gists/" + id); + root.createRequest().method("DELETE").withUrlPath("/gists/" + id).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index b0d572038e..1ea95b0b9c 100644 --- a/src/main/java/org/kohsuke/github/GHGistBuilder.java +++ b/src/main/java/org/kohsuke/github/GHGistBuilder.java @@ -23,7 +23,7 @@ public class GHGistBuilder { */ public GHGistBuilder(GitHub root) { this.root = root; - req = new Requester(root); + req = root.createRequest().method("POST"); } /** @@ -73,6 +73,6 @@ public GHGistBuilder file(String fileName, String content) { */ public GHGist create() throws IOException { req.with("files", files); - return req.to("/gists", GHGist.class).wrapUp(root); + return req.withUrlPath("/gists").fetch(GHGist.class).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index af5a4876a1..6a9726c7d3 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -16,7 +16,7 @@ public class GHGistUpdater { GHGistUpdater(GHGist base) { this.base = base; - this.builder = new Requester(base.root); + this.builder = base.root.createRequest(); files = new LinkedHashMap<>(); } @@ -96,6 +96,6 @@ public GHGistUpdater description(String desc) { */ public GHGist update() throws IOException { builder.with("files", files); - return builder.method("PATCH").to(base.getApiTailUrl(""), GHGist.class).wrap(base.owner); + return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).fetch(GHGist.class).wrap(base.owner); } } diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index a88c9a372c..35fa7bd1f9 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -74,7 +74,7 @@ public Map getConfig() { * @see Ping hook */ public void ping() throws IOException { - new Requester(getRoot()).method("POST").to(getApiRoute() + "/pings"); + getRoot().createRequest().method("POST").withUrlPath(getApiRoute() + "/pings").send(); } /** @@ -84,7 +84,7 @@ public void ping() throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(getRoot()).method("DELETE").to(getApiRoute()); + getRoot().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 7f99de7a77..05ad6fc3b8 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -28,8 +28,10 @@ private Context(GitHub root) { */ public List getHooks() throws IOException { - GHHook[] hookArray = root.retrieve().to(collection(), collectionClass()); // jdk/eclipse bug requires this - // to be on separate line + GHHook[] hookArray = root.createRequest().withUrlPath(collection()).fetch(collectionClass()); // jdk/eclipse + // bug + // requires this + // to be on separate line List list = new ArrayList(Arrays.asList(hookArray)); for (GHHook h : list) wrap(h); @@ -46,7 +48,7 @@ public List getHooks() throws IOException { * the io exception */ public GHHook getHook(int id) throws IOException { - GHHook hook = root.retrieve().to(collection() + "/" + id, clazz()); + GHHook hook = root.createRequest().withUrlPath(collection() + "/" + id).fetch(clazz()); return wrap(hook); } @@ -74,11 +76,14 @@ public GHHook createHook(String name, Map config, Collection getComments() throws IOException { * the io exception */ public PagedIterable listComments() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getIssuesApiRoute() + "/comments", GHIssueComment[].class, item -> item.wrapUp(GHIssue.this)); @@ -451,16 +454,19 @@ public PagedIterable listComments() throws IOException { @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.createRequest() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiRoute() + "/reactions", GHReaction.class) + .withUrlPath(getApiRoute() + "/reactions") + .fetch(GHReaction.class) .wrap(root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } @@ -486,10 +492,11 @@ public void addAssignees(GHUser... assignees) throws IOException { * the io exception */ public void addAssignees(Collection assignees) throws IOException { - root.retrieve() + root.createRequest() .method("POST") .with(ASSIGNEES, getLogins(assignees)) - .to(getIssuesApiRoute() + "/assignees", this); + .withUrlPath(getIssuesApiRoute() + "/assignees") + .fetchInto(this); } /** @@ -513,7 +520,11 @@ public void setAssignees(GHUser... assignees) throws IOException { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - new Requester(root).with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute()); + root.createRequest() + .method("PATCH") + .with(ASSIGNEES, getLogins(assignees)) + .withUrlPath(getIssuesApiRoute()) + .send(); } /** @@ -537,11 +548,12 @@ public void removeAssignees(GHUser... assignees) throws IOException { * the io exception */ public void removeAssignees(Collection assignees) throws IOException { - root.retrieve() + root.createRequest() .method("DELETE") .with(ASSIGNEES, getLogins(assignees)) .inBody() - .to(getIssuesApiRoute() + "/assignees", this); + .withUrlPath(getIssuesApiRoute() + "/assignees") + .fetchInto(this); } /** @@ -703,7 +715,7 @@ protected static List getLogins(Collection users) { * the io exception */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)), GHIssueEvent[].class, item -> item.wrapUp(GHIssue.this)); diff --git a/src/main/java/org/kohsuke/github/GHIssueBuilder.java b/src/main/java/org/kohsuke/github/GHIssueBuilder.java index 766449596e..2d21d3fd03 100644 --- a/src/main/java/org/kohsuke/github/GHIssueBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueBuilder.java @@ -17,7 +17,7 @@ public class GHIssueBuilder { GHIssueBuilder(GHRepository repo, String title) { this.repo = repo; - this.builder = new Requester(repo.root); + this.builder = repo.root.createRequest().method("POST"); builder.with("title", title); } @@ -95,7 +95,8 @@ public GHIssueBuilder label(String label) { public GHIssue create() throws IOException { return builder.with("labels", labels) .with("assignees", assignees) - .to(repo.getApiTailUrl("issues"), GHIssue.class) + .withUrlPath(repo.getApiTailUrl("issues")) + .fetch(GHIssue.class) .wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 9c2f1ae587..1a174f2c51 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -108,7 +108,11 @@ public GHCommentAuthorAssociation getAuthorAssociation() { * the io exception */ public void update(String body) throws IOException { - new Requester(owner.root).with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class); + owner.root.createRequest() + .method("PATCH") + .with("body", body) + .withUrlPath(getApiRoute()) + .fetch(GHIssueComment.class); this.body = body; } @@ -119,22 +123,25 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiRoute()); + owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.createRequest() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiRoute() + "/reactions", GHReaction.class) + .withUrlPath(getApiRoute() + "/reactions") + .fetch(GHReaction.class) .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 7c6bc38a81..b47e1f2d99 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -69,7 +69,7 @@ GHLabel wrapUp(GHRepository repo) { * the io exception */ public void delete() throws IOException { - repo.root.retrieve().method("DELETE").to(url); + repo.root.createRequest().method("DELETE").setRawUrlPath(url).send(); } /** @@ -81,13 +81,14 @@ public void delete() throws IOException { * the io exception */ public void setColor(String newColor) throws IOException { - repo.root.retrieve() + repo.root.createRequest() .method("PATCH") .withPreview(SYMMETRA) .with("name", name) .with("color", newColor) .with("description", description) - .to(url); + .setRawUrlPath(url) + .send(); } /** @@ -101,13 +102,14 @@ public void setColor(String newColor) throws IOException { @Preview @Deprecated public void setDescription(String newDescription) throws IOException { - repo.root.retrieve() + repo.root.createRequest() .method("PATCH") .withPreview(SYMMETRA) .with("name", name) .with("color", color) .with("description", newDescription) - .to(url); + .setRawUrlPath(url) + .send(); } static Collection toNames(Collection labels) { diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java index e7c4cff56d..0e7851e96a 100644 --- a/src/main/java/org/kohsuke/github/GHLicense.java +++ b/src/main/java/org/kohsuke/github/GHLicense.java @@ -199,7 +199,7 @@ protected synchronized void populate() throws IOException { if (description != null) return; // already populated - root.retrieve().to(url, this); + root.createRequest().withUrlPath(url).fetchInto(this); } @Override diff --git a/src/main/java/org/kohsuke/github/GHMembership.java b/src/main/java/org/kohsuke/github/GHMembership.java index 666e229fa3..b8099d5276 100644 --- a/src/main/java/org/kohsuke/github/GHMembership.java +++ b/src/main/java/org/kohsuke/github/GHMembership.java @@ -72,7 +72,7 @@ public GHOrganization getOrganization() { * @see GHMyself#getMembership(GHOrganization) GHMyself#getMembership(GHOrganization) */ public void activate() throws IOException { - root.retrieve().method("PATCH").with("state", State.ACTIVE).to(url, this); + root.createRequest().method("PATCH").with("state", State.ACTIVE).withUrlPath(url).fetchInto(this); } GHMembership wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 2126869cbb..bfe806f14c 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -155,11 +155,11 @@ public void reopen() throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(getApiRoute()); + root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } private void edit(String key, Object value) throws IOException { - new Requester(root).with(key, value).method("PATCH").to(getApiRoute()); + root.createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 0d16f77d4b..1a83ff0d2d 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -71,7 +71,7 @@ public List getEmails() throws IOException { * the io exception */ public List getEmails2() throws IOException { - GHEmail[] addresses = root.retrieve().to("/user/emails", GHEmail[].class); + GHEmail[] addresses = root.createRequest().withUrlPath("/user/emails").fetchArray(GHEmail[].class); return Collections.unmodifiableList(Arrays.asList(addresses)); } @@ -86,7 +86,8 @@ public List getEmails2() throws IOException { * the io exception */ public List getPublicKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class))); + return Collections.unmodifiableList( + Arrays.asList(root.createRequest().withUrlPath("/user/keys").fetchArray(GHKey[].class))); } /** @@ -100,8 +101,8 @@ public List getPublicKeys() throws IOException { * the io exception */ public List getPublicVerifiedKeys() throws IOException { - return Collections.unmodifiableList( - Arrays.asList(root.retrieve().to("/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); + return Collections.unmodifiableList(Arrays.asList( + root.createRequest().withUrlPath("/users/" + getLogin() + "/keys").fetchArray(GHVerifiedKey[].class))); } /** @@ -114,7 +115,7 @@ public List getPublicVerifiedKeys() throws IOException { public GHPersonSet getAllOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().to("/user/orgs", GHOrganization[].class)) { + for (GHOrganization o : root.createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class)) { if (names.add(o.getLogin())) // in case of rumoured duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } @@ -175,7 +176,7 @@ public PagedIterable listRepositories(final int pageSize) { * @return the paged iterable */ public PagedIterable listRepositories(final int pageSize, final RepositoryListFilter repoType) { - return root.retrieve() + return root.createRequest() .with("type", repoType) .asPagedIterable("/user/repos", GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); @@ -208,7 +209,7 @@ public PagedIterable listOrgMemberships() { * @return the paged iterable */ public PagedIterable listOrgMemberships(final GHMembership.State state) { - return root.retrieve() + return root.createRequest() .with("state", state) .asPagedIterable("/user/memberships/orgs", GHMembership[].class, item -> item.wrap(root)); } @@ -223,7 +224,10 @@ public PagedIterable listOrgMemberships(final GHMembership.State s * the io exception */ public GHMembership getMembership(GHOrganization o) throws IOException { - return root.retrieve().to("/user/memberships/orgs/" + o.getLogin(), GHMembership.class).wrap(root); + return root.createRequest() + .withUrlPath("/user/memberships/orgs/" + o.getLogin()) + .fetch(GHMembership.class) + .wrap(root); } // public void addEmails(Collection emails) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 9d62480651..65bd604d8b 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -101,7 +101,7 @@ public GHNotificationStream nonBlocking(boolean v) { */ public Iterator iterator() { // capture the configuration setting here - final Requester req = new Requester(root).method("GET") + final Requester req = root.createRequest() .with("all", all) .with("participating", participating) .with("since", since); @@ -180,7 +180,7 @@ GHThread fetch() { req.setHeader("If-Modified-Since", lastModified); - threads = req.to(apiUrl, GHThread[].class); + threads = req.withUrlPath(apiUrl).fetchArray(GHThread[].class); if (threads == null) { threads = EMPTY_ARRAY; // if unmodified, we get empty array } else { @@ -232,10 +232,10 @@ public void markAsRead() throws IOException { * the io exception */ public void markAsRead(long timestamp) throws IOException { - final Requester req = new Requester(root).method("PUT"); + final Requester req = root.createRequest(); if (timestamp >= 0) req.with("last_read_at", GitHub.printDate(new Date(timestamp))); - req.asHttpStatusCode(apiUrl); + req.withUrlPath(apiUrl).fetchHttpStatusCode(); } private static final GHThread[] EMPTY_ARRAY = new GHThread[0]; diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 62b38dbe35..dac65cb530 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -121,7 +121,7 @@ public Map getTeams() throws IOException { * the io exception */ public PagedIterable listTeams() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/orgs/%s/teams", login), GHTeam[].class, item -> item.wrapUp(GHOrganization.this)); @@ -183,10 +183,11 @@ public enum Role { * "https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership">documentation */ public void add(GHUser user, Role role) throws IOException { - root.retrieve() + root.createRequest() .method("PUT") .with("role", role.name().toLowerCase()) - .to("/orgs/" + login + "/memberships/" + user.getLogin()); + .withUrlPath("/orgs/" + login + "/memberships/" + user.getLogin()) + .send(); } /** @@ -198,7 +199,7 @@ public void add(GHUser user, Role role) throws IOException { */ public boolean hasMember(GHUser user) { try { - root.retrieve().to("/orgs/" + login + "/members/" + user.getLogin()); + root.createRequest().withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send(); return true; } catch (IOException ignore) { return false; @@ -215,7 +216,7 @@ public boolean hasMember(GHUser user) { * the io exception */ public void remove(GHUser user) throws IOException { - root.retrieve().method("DELETE").to("/orgs/" + login + "/members/" + user.getLogin()); + root.createRequest().method("DELETE").withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send(); } /** @@ -227,7 +228,7 @@ public void remove(GHUser user) throws IOException { */ public boolean hasPublicMember(GHUser user) { try { - root.retrieve().to("/orgs/" + login + "/public_members/" + user.getLogin()); + root.createRequest().withUrlPath("/orgs/" + login + "/public_members/" + user.getLogin()).send(); return true; } catch (IOException ignore) { return false; @@ -243,7 +244,7 @@ public boolean hasPublicMember(GHUser user) { * the io exception */ public void publicize(GHUser u) throws IOException { - root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null); + root.createRequest().method("PUT").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).send(); } /** @@ -299,7 +300,7 @@ public PagedIterable listMembersWithFilter(String filter) throws IOExcep private PagedIterable listMembers(final String suffix, final String filter) throws IOException { String filterParams = (filter == null) ? "" : ("?filter=" + filter); - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class, item -> item.wrapUp(root)); @@ -314,7 +315,7 @@ private PagedIterable listMembers(final String suffix, final String filt * the io exception */ public void conceal(GHUser u) throws IOException { - root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null); + root.createRequest().method("DELETE").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).send(); } /** @@ -327,7 +328,7 @@ public void conceal(GHUser u) throws IOException { * the io exception */ public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .with("state", status) .asPagedIterable(String.format("/orgs/%s/projects", login), GHProject[].class, item -> item.wrap(root)); @@ -356,12 +357,13 @@ public PagedIterable listProjects() throws IOException { * the io exception */ public GHProject createProject(String name, String body) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("name", name) .with("body", body) - .to(String.format("/orgs/%s/projects", login), GHProject.class) + .withUrlPath(String.format("/orgs/%s/projects", login)) + .fetch(GHProject.class) .wrap(root); } @@ -389,13 +391,13 @@ public enum Permission { */ @Deprecated public GHTeam createTeam(String name, Permission p, Collection repositories) throws IOException { - Requester post = new Requester(root).with("name", name).with("permission", p); + Requester post = root.createRequest().method("POST").with("name", name).with("permission", p); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").fetch(GHTeam.class).wrapUp(this); } /** @@ -430,13 +432,13 @@ public GHTeam createTeam(String name, Permission p, GHRepository... repositories * the io exception */ public GHTeam createTeam(String name, Collection repositories) throws IOException { - Requester post = new Requester(root).with("name", name); + Requester post = root.createRequest().method("POST").with("name", name); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").fetch(GHTeam.class).wrapUp(this); } /** @@ -495,7 +497,7 @@ public List getPullRequests() throws IOException { * Lists events performed by a user (this includes private events if the caller is authenticated. */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/orgs/%s/events", login), GHEventInfo[].class, item -> item.wrapUp(root)); @@ -511,7 +513,7 @@ public PagedIterable listEvents() throws IOException { */ @Override public PagedIterable listRepositories(final int pageSize) { - return root.retrieve() + return root.createRequest() .asPagedIterable("/orgs/" + login + "/repos", 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 286e97e6f3..2f47d3f9fd 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -47,7 +47,7 @@ protected synchronized void populate() throws IOException { if (root == null || root.isOffline()) { return; // cannot populate, will have to live with what we have } - root.retrieve().to(url, this); + root.createRequest().withUrlPath(url).fetchInto(this); } /** @@ -88,7 +88,7 @@ public PagedIterable listRepositories() { * @return the paged iterable */ public PagedIterable listRepositories(final int pageSize) { - return root.retrieve() + return root.createRequest() .asPagedIterable("/users/" + login + "/repos", GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); } @@ -112,8 +112,9 @@ public PagedIterable listRepositories(final int pageSize) { public synchronized Iterable> iterateRepositories(final int pageSize) { return new Iterable>() { public Iterator> iterator() { - final Iterator pager = root.retrieve() - .asIterator("/users/" + login + "/repos", GHRepository[].class, pageSize); + final Iterator pager = root.createRequest() + .withUrlPath("users", login, "repos") + .asIterator(GHRepository[].class, pageSize); return new Iterator>() { public boolean hasNext() { @@ -146,7 +147,10 @@ public void remove() { */ public GHRepository getRepository(String name) throws IOException { try { - return root.retrieve().to("/repos/" + login + '/' + name, GHRepository.class).wrap(root); + return root.createRequest() + .withUrlPath("/repos/" + login + '/' + name) + .fetch(GHRepository.class) + .wrap(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index 03807b795c..56714ffac5 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -74,11 +74,17 @@ public GHObject getOwner() throws IOException { if (owner == null) { try { if (owner_url.contains("/orgs/")) { - owner = root.retrieve().to(getOwnerUrl().getPath(), GHOrganization.class).wrapUp(root); + owner = root.createRequest() + .withUrlPath(getOwnerUrl().getPath()) + .fetch(GHOrganization.class) + .wrapUp(root); } else if (owner_url.contains("/users/")) { - owner = root.retrieve().to(getOwnerUrl().getPath(), GHUser.class).wrapUp(root); + owner = root.createRequest().withUrlPath(getOwnerUrl().getPath()).fetch(GHUser.class).wrapUp(root); } else if (owner_url.contains("/repos/")) { - owner = root.retrieve().to(getOwnerUrl().getPath(), GHRepository.class).wrap(root); + owner = root.createRequest() + .withUrlPath(getOwnerUrl().getPath()) + .fetch(GHRepository.class) + .wrap(root); } } catch (FileNotFoundException e) { return null; @@ -176,7 +182,7 @@ public GHProject wrap(GitHub root) { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send(); } /** @@ -270,7 +276,7 @@ public void setPublic(boolean isPublic) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -282,7 +288,7 @@ public void delete() throws IOException { */ public PagedIterable listColumns() throws IOException { final GHProject project = this; - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .asPagedIterable(String.format("/projects/%d/columns", id), GHProjectColumn[].class, @@ -299,11 +305,12 @@ public PagedIterable listColumns() throws IOException { * the io exception */ public GHProjectColumn createColumn(String name) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("name", name) - .to(String.format("/projects/%d/columns", id), GHProjectColumn.class) + .withUrlPath(String.format("/projects/%d/columns", id)) + .fetch(GHProjectColumn.class) .wrap(this); } } \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index 2ed518fcce..94b130c3aa 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -72,7 +72,7 @@ public GitHub getRoot() { public GHProject getProject() throws IOException { if (project == null) { try { - project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root); + project = root.createRequest().withUrlPath(getProjectUrl().getPath()).fetch(GHProject.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -90,7 +90,10 @@ public GHProject getProject() throws IOException { public GHProjectColumn getColumn() throws IOException { if (column == null) { try { - column = root.retrieve().to(getColumnUrl().getPath(), GHProjectColumn.class).wrap(root); + column = root.createRequest() + .withUrlPath(getColumnUrl().getPath()) + .fetch(GHProjectColumn.class) + .wrap(root); } catch (FileNotFoundException e) { return null; } @@ -110,9 +113,12 @@ public GHIssue getContent() throws IOException { return null; try { if (content_url.contains("/pulls")) { - return root.retrieve().to(getContentUrl().getPath(), GHPullRequest.class).wrap(root); + return root.createRequest() + .withUrlPath(getContentUrl().getPath()) + .fetch(GHPullRequest.class) + .wrap(root); } else { - return root.retrieve().to(getContentUrl().getPath(), GHIssue.class).wrap(root); + return root.createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class).wrap(root); } } catch (FileNotFoundException e) { return null; @@ -198,7 +204,7 @@ public void setArchived(boolean archived) throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send(); } /** @@ -217,6 +223,6 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send(); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index b93f709c36..b561f6f905 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -67,7 +67,7 @@ public GitHub getRoot() { public GHProject getProject() throws IOException { if (project == null) { try { - project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root); + project = root.createRequest().withUrlPath(getProjectUrl().getPath()).fetch(GHProject.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -106,7 +106,7 @@ public void setName(String name) throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send(); } /** @@ -125,7 +125,7 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -137,7 +137,7 @@ public void delete() throws IOException { */ public PagedIterable listCards() throws IOException { final GHProjectColumn column = this; - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .asPagedIterable(String.format("/projects/columns/%d/cards", id), GHProjectCard[].class, @@ -154,11 +154,12 @@ public PagedIterable listCards() throws IOException { * the io exception */ public GHProjectCard createCard(String note) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("note", note) - .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class) + .withUrlPath(String.format("/projects/columns/%d/cards", id)) + .fetch(GHProjectCard.class) .wrap(this); } @@ -172,12 +173,13 @@ public GHProjectCard createCard(String note) throws IOException { * the io exception */ public GHProjectCard createCard(GHIssue issue) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("content_type", issue instanceof GHPullRequest ? "PullRequest" : "Issue") .with("content_id", issue.getId()) - .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class) + .withUrlPath(String.format("/projects/columns/%d/cards", id)) + .fetch(GHProjectCard.class) .wrap(this); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index f8a9bb4bc7..fb891f7139 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -384,7 +384,7 @@ public void refresh() throws IOException { if (root.isOffline()) { return; // cannot populate, will have to live with what we have } - root.retrieve().withPreview(SHADOW_CAT).to(url, this).wrapUp(owner); + root.createRequest().withPreview(SHADOW_CAT).withUrlPath(url).fetchInto(this).wrapUp(owner); } /** @@ -393,7 +393,7 @@ public void refresh() throws IOException { * @return the paged iterable */ public PagedIterable listFiles() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("%s/files", getApiRoute()), GHPullRequestFileDetail[].class, null); } @@ -403,7 +403,7 @@ public PagedIterable listFiles() { * @return the paged iterable */ public PagedIterable listReviews() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("%s/reviews", getApiRoute()), GHPullRequestReview[].class, item -> item.wrapUp(GHPullRequest.this)); @@ -417,7 +417,7 @@ public PagedIterable listReviews() { * the io exception */ public PagedIterable listReviewComments() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment[].class, item -> item.wrapUp(GHPullRequest.this)); @@ -429,7 +429,7 @@ public PagedIterable listReviewComments() throws IOE * @return the paged iterable */ public PagedIterable listCommits() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("%s/commits", getApiRoute()), GHPullRequestCommitDetail[].class, item -> item.wrapUp(GHPullRequest.this)); @@ -505,12 +505,14 @@ public GHPullRequestReviewBuilder createReview() { */ public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException { - return new Requester(root).method("POST") + return root.createRequest() + .method("POST") .with("body", body) .with("commit_id", sha) .with("path", path) .with("position", position) - .to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class) + .withUrlPath(getApiRoute() + COMMENTS_ACTION) + .fetch(GHPullRequestReviewComment.class) .wrapUp(this); } @@ -523,9 +525,11 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S * the io exception */ public void requestReviewers(List reviewers) throws IOException { - new Requester(root).method("POST") + root.createRequest() + .method("POST") .with("reviewers", getLogins(reviewers)) - .to(getApiRoute() + REQUEST_REVIEWERS); + .withUrlPath(getApiRoute() + REQUEST_REVIEWERS) + .send(); } /** @@ -541,7 +545,11 @@ public void requestTeamReviewers(List teams) throws IOException { for (GHTeam team : teams) { teamReviewers.add(team.getSlug()); } - new Requester(root).method("POST").with("team_reviewers", teamReviewers).to(getApiRoute() + REQUEST_REVIEWERS); + root.createRequest() + .method("POST") + .with("team_reviewers", teamReviewers) + .withUrlPath(getApiRoute() + REQUEST_REVIEWERS) + .send(); } /** @@ -589,11 +597,13 @@ public void merge(String msg, String sha) throws IOException { * the io exception */ public void merge(String msg, String sha, MergeMethod method) throws IOException { - new Requester(root).method("PUT") + root.createRequest() + .method("PUT") .with("commit_message", msg) .with("sha", sha) .with("merge_method", method) - .to(getApiRoute() + "/merge"); + .withUrlPath(getApiRoute() + "/merge") + .send(); } /** @@ -605,7 +615,7 @@ public enum MergeMethod { private void fetchIssue() throws IOException { if (!fetchedIssueDetails) { - new Requester(root).method("GET").to(getIssuesApiRoute(), this); + root.createRequest().withUrlPath(getIssuesApiRoute()).fetchInto(this); fetchedIssueDetails = true; } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 65a29d33a7..0498ce183f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -160,10 +160,12 @@ public void submit(String body, GHPullRequestReviewState state) throws IOExcepti * the io exception */ public void submit(String body, GHPullRequestReviewEvent event) throws IOException { - new Requester(owner.root).method("POST") + owner.root.createRequest() + .method("POST") .with("body", body) .with("event", event.action()) - .to(getApiRoute() + "/events", this); + .withUrlPath(getApiRoute() + "/events") + .fetchInto(this); this.body = body; this.state = event.toState(); } @@ -175,7 +177,7 @@ public void submit(String body, GHPullRequestReviewEvent event) throws IOExcepti * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiRoute()); + owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -187,7 +189,11 @@ public void delete() throws IOException { * the io exception */ public void dismiss(String message) throws IOException { - new Requester(owner.root).method("PUT").with("message", message).to(getApiRoute() + "/dismissals"); + owner.root.createRequest() + .method("PUT") + .with("message", message) + .withUrlPath(getApiRoute() + "/dismissals") + .send(); state = GHPullRequestReviewState.DISMISSED; } @@ -199,7 +205,7 @@ public void dismiss(String message) throws IOException { * the io exception */ public PagedIterable listReviewComments() throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .asPagedIterable(getApiRoute() + "/comments", GHPullRequestReviewComment[].class, item -> item.wrapUp(owner)); diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index cf0bf2171d..3a93777fd5 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -17,7 +17,7 @@ public class GHPullRequestReviewBuilder { GHPullRequestReviewBuilder(GHPullRequest pr) { this.pr = pr; - this.builder = new Requester(pr.root); + this.builder = pr.root.createRequest(); } // public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event, @@ -91,7 +91,8 @@ public GHPullRequestReviewBuilder comment(String body, String path, int position public GHPullRequestReview create() throws IOException { return builder.method("POST") .with("comments", comments) - .to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class) + .withUrlPath(pr.getApiRoute() + "/reviews") + .fetch(GHPullRequestReview.class) .wrapUp(pr); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 74f9dd8d02..4864b05b45 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -163,7 +163,7 @@ protected String getApiRoute() { * the io exception */ public void update(String body) throws IOException { - new Requester(owner.root).method("PATCH").with("body", body).to(getApiRoute(), this); + owner.root.createRequest().method("PATCH").with("body", body).withUrlPath(getApiRoute()).fetchInto(this); this.body = body; } @@ -174,7 +174,7 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiRoute()); + owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -187,26 +187,31 @@ public void delete() throws IOException { * the io exception */ public GHPullRequestReviewComment reply(String body) throws IOException { - return new Requester(owner.root).method("POST") + return owner.root.createRequest() + .method("POST") .with("body", body) .with("in_reply_to", getId()) - .to(getApiRoute() + "/comments", GHPullRequestReviewComment.class) + .withUrlPath(getApiRoute() + "/comments") + .fetch(GHPullRequestReviewComment.class) .wrapUp(owner); } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.createRequest() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiRoute() + "/reactions", GHReaction.class) + .withUrlPath(getApiRoute() + "/reactions") + .fetch(GHReaction.class) .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } diff --git a/src/main/java/org/kohsuke/github/GHQueryBuilder.java b/src/main/java/org/kohsuke/github/GHQueryBuilder.java index be63c7b324..b9ee5e061d 100644 --- a/src/main/java/org/kohsuke/github/GHQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHQueryBuilder.java @@ -13,7 +13,7 @@ public abstract class GHQueryBuilder { GHQueryBuilder(GitHub root) { this.root = root; - this.req = root.retrieve(); + this.req = root.createRequest(); } /** diff --git a/src/main/java/org/kohsuke/github/GHReaction.java b/src/main/java/org/kohsuke/github/GHReaction.java index ced6792b41..2b0b80c391 100644 --- a/src/main/java/org/kohsuke/github/GHReaction.java +++ b/src/main/java/org/kohsuke/github/GHReaction.java @@ -58,6 +58,6 @@ public URL getHtmlUrl() { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/" + id); + root.createRequest().method("DELETE").withPreview(SQUIRREL_GIRL).withUrlPath("/reactions/" + id).send(); } } diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index c450aae080..75194a5357 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -66,7 +66,13 @@ public void updateTo(String sha) throws IOException { * the io exception */ public void updateTo(String sha, Boolean force) throws IOException { - new Requester(root).with("sha", sha).with("force", force).method("PATCH").to(url, GHRef.class).wrap(root); + root.createRequest() + .method("PATCH") + .with("sha", sha) + .with("force", force) + .withUrlPath(url) + .fetch(GHRef.class) + .wrap(root); } /** @@ -76,7 +82,7 @@ public void updateTo(String sha, Boolean force) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(url); + root.createRequest().method("DELETE").withUrlPath(url).send(); } GHRef wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 3955693071..23e90916b3 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -240,12 +240,12 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { * the io exception */ public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { - Requester builder = new Requester(owner.root); + Requester builder = owner.root.createRequest().method("POST"); String url = getUploadUrl(); // strip the helpful garbage from the url url = url.substring(0, url.indexOf('{')); url += "?name=" + URLEncoder.encode(filename, "UTF-8"); - return builder.contentType(contentType).with(stream).to(url, GHAsset.class).wrap(this); + return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this); } /** @@ -256,9 +256,9 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy * the io exception */ public List getAssets() throws IOException { - Requester builder = new Requester(owner.root); + Requester builder = owner.root.createRequest(); - GHAsset[] assets = builder.method("GET").to(getApiTailUrl("assets"), GHAsset[].class); + GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).fetchArray(GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); } @@ -269,7 +269,7 @@ public List getAssets() throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(owner.getApiTailUrl("releases/" + id)); + root.createRequest().method("DELETE").withUrlPath(owner.getApiTailUrl("releases/" + id)).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java index 19dbafd6bf..6c0914def1 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java +++ b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java @@ -21,7 +21,7 @@ public class GHReleaseBuilder { */ public GHReleaseBuilder(GHRepository ghRepository, String tag) { this.repo = ghRepository; - this.builder = new Requester(repo.root); + this.builder = repo.root.createRequest().method("POST"); builder.with("tag_name", tag); } @@ -95,6 +95,6 @@ public GHReleaseBuilder prerelease(boolean prerelease) { * the io exception */ public GHRelease create() throws IOException { - return builder.to(repo.getApiTailUrl("releases"), GHRelease.class).wrap(repo); + return builder.withUrlPath(repo.getApiTailUrl("releases")).fetch(GHRelease.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index 3c52eb0864..4d1b69b89e 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -14,7 +14,7 @@ public class GHReleaseUpdater { GHReleaseUpdater(GHRelease base) { this.base = base; - this.builder = new Requester(base.root); + this.builder = base.root.createRequest(); } /** @@ -100,7 +100,8 @@ public GHReleaseUpdater prerelease(boolean prerelease) { */ public GHRelease update() throws IOException { return builder.method("PATCH") - .to(base.owner.getApiTailUrl("releases/" + base.id), GHRelease.class) + .withUrlPath(base.owner.getApiTailUrl("releases/" + base.id)) + .fetch(GHRelease.class) .wrap(base.owner); } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 932e769ad6..a76dd5b1e7 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -134,13 +134,14 @@ public PagedIterable getDeploymentStatuses(final int id) thr * @return the paged iterable */ public PagedIterable listDeployments(String sha, String ref, String task, String environment) { - List params = Arrays.asList(getParam("sha", sha), - getParam("ref", ref), - getParam("task", task), - getParam("environment", environment)); - final String deploymentsUrl = getApiTailUrl("deployments") + "?" + join(params, "&"); - return root.retrieve() - .asPagedIterable(deploymentsUrl, GHDeployment[].class, item -> item.wrap(GHRepository.this)); + return root.createRequest() + .with("sha", sha) + .with("ref", ref) + .with("task", task) + .with("environment", environment) + .asPagedIterable(getApiTailUrl("deployments"), + GHDeployment[].class, + item -> item.wrap(GHRepository.this)); } /** @@ -153,21 +154,10 @@ public PagedIterable listDeployments(String sha, String ref, Strin * the io exception */ public GHDeployment getDeployment(long id) throws IOException { - return root.retrieve().to(getApiTailUrl("deployments/" + id), GHDeployment.class).wrap(this); - } - - private String join(List params, String joinStr) { - StringBuilder output = new StringBuilder(); - for (String param : params) { - if (param != null) { - output.append(param + joinStr); - } - } - return output.toString(); - } - - private String getParam(String name, String value) { - return StringUtils.trimToNull(value) == null ? null : name + "=" + value; + return root.createRequest() + .withUrlPath(getApiTailUrl("deployments/" + id)) + .fetch(GHDeployment.class) + .wrap(this); } /** @@ -345,7 +335,7 @@ public GHUser getOwner() throws IOException { * the io exception */ public GHIssue getIssue(int id) throws IOException { - return root.retrieve().to(getApiTailUrl("issues/" + id), GHIssue.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("issues/" + id)).fetch(GHIssue.class).wrap(this); } /** @@ -384,10 +374,11 @@ public List getIssues(GHIssueState state) throws IOException { * the io exception */ public List getIssues(GHIssueState state, GHMilestone milestone) throws IOException { - return Arrays.asList(GHIssue.wrap(root.retrieve() + Requester requester = root.createRequest() .with("state", state) - .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()) - .to(getApiTailUrl("issues"), GHIssue[].class), this)); + .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()); + return Arrays + .asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).fetchArray(GHIssue[].class), this)); } /** @@ -398,7 +389,7 @@ public List getIssues(GHIssueState state, GHMilestone milestone) throws * @return the paged iterable */ public PagedIterable listIssues(final GHIssueState state) { - return root.retrieve() + return root.createRequest() .with("state", state) .asPagedIterable(getApiTailUrl("issues"), GHIssue[].class, item -> item.wrap(GHRepository.this)); } @@ -427,10 +418,12 @@ public GHReleaseBuilder createRelease(String tag) { * the io exception */ public GHRef createRef(String name, String sha) throws IOException { - return new Requester(root).with("ref", name) - .with("sha", sha) + return root.createRequest() .method("POST") - .to(getApiTailUrl("git/refs"), GHRef.class) + .with("ref", name) + .with("sha", sha) + .withUrlPath(getApiTailUrl("git/refs")) + .fetch(GHRef.class) .wrap(root); } @@ -457,7 +450,7 @@ public List getReleases() throws IOException { */ public GHRelease getRelease(long id) throws IOException { try { - return root.retrieve().to(getApiTailUrl("releases/" + id), GHRelease.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("releases/" + id)).fetch(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no release for this id } @@ -474,7 +467,10 @@ public GHRelease getRelease(long id) throws IOException { */ public GHRelease getReleaseByTagName(String tag) throws IOException { try { - return root.retrieve().to(getApiTailUrl("releases/tags/" + tag), GHRelease.class).wrap(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("releases/tags/" + tag)) + .fetch(GHRelease.class) + .wrap(this); } catch (FileNotFoundException e) { return null; // no release for this tag } @@ -489,7 +485,7 @@ public GHRelease getReleaseByTagName(String tag) throws IOException { */ public GHRelease getLatestRelease() throws IOException { try { - return root.retrieve().to(getApiTailUrl("releases/latest"), GHRelease.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("releases/latest")).fetch(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no latest release } @@ -503,7 +499,7 @@ public GHRelease getLatestRelease() throws IOException { * the io exception */ public PagedIterable listReleases() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("releases"), GHRelease[].class, item -> item.wrap(GHRepository.this)); } @@ -515,7 +511,7 @@ public PagedIterable listReleases() throws IOException { * the io exception */ public PagedIterable listTags() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("tags"), GHTag[].class, item -> item.wrap(GHRepository.this)); } @@ -528,7 +524,7 @@ public PagedIterable listTags() throws IOException { * the io exception */ public Map listLanguages() throws IOException { - return root.retrieve().to(getApiTailUrl("languages"), HashMap.class); + return root.createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class); } /** @@ -773,7 +769,8 @@ public PagedIterable listAssignees() throws IOException { * the io exception */ public boolean hasAssignee(GHUser u) throws IOException { - return root.retrieve().asHttpStatusCode(getApiTailUrl("assignees/" + u.getLogin())) / 100 == 2; + return root.createRequest().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).fetchHttpStatusCode() + / 100 == 2; } /** @@ -786,7 +783,9 @@ public boolean hasAssignee(GHUser u) throws IOException { */ public Set getCollaboratorNames() throws IOException { Set r = new HashSet(); - for (GHUser u : GHUser.wrap(root.retrieve().to(getApiTailUrl("collaborators"), GHUser[].class), root)) + for (GHUser u : GHUser.wrap( + root.createRequest().withUrlPath(getApiTailUrl("collaborators")).fetchArray(GHUser[].class), + root)) r.add(u.login); return r; } @@ -801,8 +800,9 @@ public Set getCollaboratorNames() throws IOException { * the io exception */ public GHPermissionType getPermission(String user) throws IOException { - GHPermission perm = root.retrieve() - .to(getApiTailUrl("collaborators/" + user + "/permission"), GHPermission.class); + GHPermission perm = root.createRequest() + .withUrlPath(getApiTailUrl("collaborators/" + user + "/permission")) + .fetch(GHPermission.class); perm.wrapUp(root); return perm.getPermissionType(); } @@ -828,8 +828,8 @@ public GHPermissionType getPermission(GHUser u) throws IOException { * the io exception */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(new HashSet( - Arrays.asList(GHTeam.wrapUp(root.retrieve().to(getApiTailUrl("teams"), GHTeam[].class), + return Collections.unmodifiableSet(new HashSet(Arrays.asList( + GHTeam.wrapUp(root.createRequest().withUrlPath(getApiTailUrl("teams")).fetchArray(GHTeam[].class), root.getOrganization(getOwnerName()))))); } @@ -883,7 +883,7 @@ public void removeCollaborators(Collection users) throws IOException { private void modifyCollaborators(Collection users, String method) throws IOException { for (GHUser user : users) { - new Requester(root).method(method).to(getApiTailUrl("collaborators/" + user.getLogin())); + root.createRequest().method(method).withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send(); } } @@ -898,18 +898,20 @@ private void modifyCollaborators(Collection users, String method) throws public void setEmailServiceHook(String address) throws IOException { Map config = new HashMap(); config.put("address", address); - new Requester(root).method("POST") + root.createRequest() + .method("POST") .with("name", "email") .with("config", config) .with("active", true) - .to(getApiTailUrl("hooks")); + .withUrlPath(getApiTailUrl("hooks")) + .send(); } private void edit(String key, String value) throws IOException { - Requester requester = new Requester(root); + Requester requester = root.createRequest(); if (!key.equals("name")) requester.with("name", name); // even when we don't change the name, we need to send it in - requester.with(key, value).method("PATCH").to(getApiTailUrl("")); + requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).send(); } /** @@ -1052,7 +1054,7 @@ public void allowRebaseMerge(boolean value) throws IOException { */ public void delete() throws IOException { try { - new Requester(root).method("DELETE").to(getApiTailUrl("")); + root.createRequest().method("DELETE").withUrlPath(getApiTailUrl("")).send(); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916") @@ -1110,7 +1112,7 @@ public PagedIterable listForks() { * @return the paged iterable */ public PagedIterable listForks(final ForkSort sort) { - return root.retrieve() + return root.createRequest() .with("sort", sort) .asPagedIterable(getApiTailUrl("forks"), GHRepository[].class, item -> item.wrap(root)); } @@ -1123,7 +1125,7 @@ public PagedIterable listForks(final ForkSort sort) { * the io exception */ public GHRepository fork() throws IOException { - new Requester(root).method("POST").to(getApiTailUrl("forks"), null); + root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).send(); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1149,7 +1151,11 @@ public GHRepository fork() throws IOException { * the io exception */ public GHRepository forkTo(GHOrganization org) throws IOException { - new Requester(root).to(getApiTailUrl("forks?org=" + org.getLogin())); + root.createRequest() + .method("POST") + .with("organization", org.getLogin()) + .withUrlPath(getApiTailUrl("forks")) + .send(); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1175,9 +1181,10 @@ public GHRepository forkTo(GHOrganization org) throws IOException { * the io exception */ public GHPullRequest getPullRequest(int i) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(SHADOW_CAT) - .to(getApiTailUrl("pulls/" + i), GHPullRequest.class) + .withUrlPath(getApiTailUrl("pulls/" + i)) + .fetch(GHPullRequest.class) .wrapUp(this); } @@ -1291,14 +1298,17 @@ public GHPullRequest createPullRequest(String title, String body, boolean maintainerCanModify, boolean draft) throws IOException { - return new Requester(root).withPreview(SHADOW_CAT) + return root.createRequest() + .method("POST") + .withPreview(SHADOW_CAT) .with("title", title) .with("head", head) .with("base", base) .with("body", body) .with("maintainer_can_modify", maintainerCanModify) .with("draft", draft) - .to(getApiTailUrl("pulls"), GHPullRequest.class) + .withUrlPath(getApiTailUrl("pulls")) + .fetch(GHPullRequest.class) .wrapUp(this); } @@ -1340,8 +1350,9 @@ public GHHook getHook(int id) throws IOException { * on failure communicating with GitHub */ public GHCompare getCompare(String id1, String id2) throws IOException { - GHCompare compare = root.retrieve() - .to(getApiTailUrl(String.format("compare/%s...%s", id1, id2)), GHCompare.class); + GHCompare compare = root.createRequest() + .withUrlPath(getApiTailUrl(String.format("compare/%s...%s", id1, id2))) + .fetch(GHCompare.class); return compare.wrap(this); } @@ -1399,9 +1410,9 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { * on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { - return GHRef.wrap( - root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), - root); + return GHRef.wrap(root.createRequest() + .withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name)) + .fetchArray(GHRef[].class), root); } /** @@ -1413,7 +1424,7 @@ public GHRef[] getRefs() throws IOException { */ public PagedIterable listRefs() throws IOException { final String url = String.format("/repos/%s/%s/git/refs", getOwnerName(), name); - return root.retrieve().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); + return root.createRequest().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); } /** @@ -1426,10 +1437,9 @@ public PagedIterable listRefs() throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef[] getRefs(String refType) throws IOException { - return GHRef.wrap( - root.retrieve() - .to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class), - root); + return GHRef.wrap(root.createRequest() + .withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType)) + .fetchArray(GHRef[].class), root); } /** @@ -1443,7 +1453,7 @@ public GHRef[] getRefs(String refType) throws IOException { */ public PagedIterable listRefs(String refType) throws IOException { final String url = String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType); - return root.retrieve().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); + return root.createRequest().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); } /** @@ -1456,7 +1466,10 @@ public PagedIterable listRefs(String refType) throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef getRef(String refName) throws IOException { - return root.retrieve().to(getApiTailUrl(String.format("git/refs/%s", refName)), GHRef.class).wrap(root); + return root.createRequest() + .withUrlPath(getApiTailUrl(String.format("git/refs/%s", refName))) + .fetch(GHRef.class) + .wrap(root); } /** @@ -1470,7 +1483,7 @@ public GHRef getRef(String refName) throws IOException { * the io exception */ public GHTagObject getTagObject(String sha) throws IOException { - return root.retrieve().to(getApiTailUrl("git/tags/" + sha), GHTagObject.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("git/tags/" + sha)).fetch(GHTagObject.class).wrap(this); } /** @@ -1484,7 +1497,7 @@ public GHTagObject getTagObject(String sha) throws IOException { */ public GHTree getTree(String sha) throws IOException { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); - return root.retrieve().to(url, GHTree.class).wrap(this); + return root.createRequest().withUrlPath(url).fetch(GHTree.class).wrap(this); } /** @@ -1509,8 +1522,8 @@ public GHTreeBuilder createTree() { * on failure communicating with GitHub, potentially due to an invalid tree type being requested */ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { - String url = String.format("/repos/%s/%s/git/trees/%s?recursive=%d", getOwnerName(), name, sha, recursive); - return root.retrieve().to(url, GHTree.class).wrap(this); + String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); + return root.createRequest().with("recursive", recursive).withUrlPath(url).fetch(GHTree.class).wrap(this); } /** @@ -1529,7 +1542,7 @@ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { */ public GHBlob getBlob(String blobSha) throws IOException { String target = getApiTailUrl("git/blobs/" + blobSha); - return root.retrieve().to(target, GHBlob.class); + return root.createRequest().withUrlPath(target).fetch(GHBlob.class); } /** @@ -1554,7 +1567,10 @@ public GHBlobBuilder createBlob() { */ public InputStream readBlob(String blobSha) throws IOException { String target = getApiTailUrl("git/blobs/" + blobSha); - return root.retrieve().withHeader("Accept", "application/vnd.github.VERSION.raw").asStream(target); + return root.createRequest() + .withHeader("Accept", "application/vnd.github.VERSION.raw") + .withUrlPath(target) + .fetchStream(); } /** @@ -1569,8 +1585,9 @@ public InputStream readBlob(String blobSha) throws IOException { public GHCommit getCommit(String sha1) throws IOException { GHCommit c = commits.get(sha1); if (c == null) { - c = root.retrieve() - .to(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1), GHCommit.class) + c = root.createRequest() + .withUrlPath(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1)) + .fetch(GHCommit.class) .wrapUp(this); commits.put(sha1, c); } @@ -1592,7 +1609,7 @@ public GHCommitBuilder createCommit() { * @return the paged iterable */ public PagedIterable listCommits() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/commits", getOwnerName(), name), GHCommit[].class, item -> item.wrapUp(GHRepository.this)); @@ -1613,7 +1630,7 @@ public GHCommitQueryBuilder queryCommits() { * @return the paged iterable */ public PagedIterable listCommitComments() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/comments", getOwnerName(), name), GHCommitComment[].class, item -> item.wrap(GHRepository.this)); @@ -1646,7 +1663,10 @@ public GHContent getLicenseContent() throws IOException { private GHContentWithLicense getLicenseContent_() throws IOException { try { - return root.retrieve().to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("license")) + .fetch(GHContentWithLicense.class) + .wrap(this); } catch (FileNotFoundException e) { return null; } @@ -1662,7 +1682,7 @@ private GHContentWithLicense getLicenseContent_() throws IOException { * the io exception */ public PagedIterable listCommitStatuses(final String sha1) throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1), GHCommitStatus[].class, item -> item.wrapUp(root)); @@ -1704,11 +1724,14 @@ public GHCommitStatus createCommitStatus(String sha1, String targetUrl, String description, String context) throws IOException { - return new Requester(root).with("state", state) + return root.createRequest() + .method("POST") + .with("state", state) .with("target_url", targetUrl) .with("description", description) .with("context", context) - .to(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1), GHCommitStatus.class) + .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1)) + .fetch(GHCommitStatus.class) .wrapUp(root); } @@ -1742,7 +1765,7 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin * the io exception */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/events", getOwnerName(), name), GHEventInfo[].class, item -> item.wrapUp(root)); @@ -1758,7 +1781,7 @@ public PagedIterable listEvents() throws IOException { * the io exception */ public PagedIterable listLabels() throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(SYMMETRA) .asPagedIterable(getApiTailUrl("labels"), GHLabel[].class, item -> item.wrapUp(GHRepository.this)); } @@ -1773,7 +1796,11 @@ public PagedIterable listLabels() throws IOException { * the io exception */ public GHLabel getLabel(String name) throws IOException { - return root.retrieve().withPreview(SYMMETRA).to(getApiTailUrl("labels/" + name), GHLabel.class).wrapUp(this); + return root.createRequest() + .withPreview(SYMMETRA) + .withUrlPath(getApiTailUrl("labels/" + name)) + .fetch(GHLabel.class) + .wrapUp(this); } /** @@ -1807,13 +1834,14 @@ public GHLabel createLabel(String name, String color) throws IOException { @Preview @Deprecated public GHLabel createLabel(String name, String color, String description) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(SYMMETRA) .with("name", name) .with("color", color) .with("description", description) - .to(getApiTailUrl("labels"), GHLabel.class) + .withUrlPath(getApiTailUrl("labels")) + .fetch(GHLabel.class) .wrapUp(this); } @@ -1823,7 +1851,7 @@ public GHLabel createLabel(String name, String color, String description) throws * @return the paged iterable */ public PagedIterable listInvitations() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/invitations", getOwnerName(), name), GHInvitation[].class, item -> item.wrapUp(root)); @@ -1857,7 +1885,7 @@ public PagedIterable listStargazers() { * @return the paged iterable */ public PagedIterable listStargazers2() { - return root.retrieve() + return root.createRequest() .withPreview("application/vnd.github.v3.star+json") .asPagedIterable(getApiTailUrl("stargazers"), GHStargazer[].class, @@ -1865,7 +1893,7 @@ public PagedIterable listStargazers2() { } private PagedIterable listUsers(final String suffix) { - return root.retrieve().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); } /** @@ -2013,7 +2041,7 @@ GHRepository wrap(GitHub root) { */ public Map getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) { + for (GHBranch p : root.createRequest().withUrlPath(getApiTailUrl("branches")).fetchArray(GHBranch[].class)) { p.wrap(this); r.put(p.getName(), p); } @@ -2030,7 +2058,7 @@ public Map getBranches() throws IOException { * the io exception */ public GHBranch getBranch(String name) throws IOException { - return root.retrieve().to(getApiTailUrl("branches/" + name), GHBranch.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("branches/" + name)).fetch(GHBranch.class).wrap(this); } /** @@ -2057,7 +2085,7 @@ public Map getMilestones() throws IOException { * @return the paged iterable */ public PagedIterable listMilestones(final GHIssueState state) { - return root.retrieve() + return root.createRequest() .with("state", state) .asPagedIterable(getApiTailUrl("milestones"), GHMilestone[].class, @@ -2076,7 +2104,7 @@ public PagedIterable listMilestones(final GHIssueState state) { public GHMilestone getMilestone(int number) throws IOException { GHMilestone m = milestones.get(number); if (m == null) { - m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class); + m = root.createRequest().withUrlPath(getApiTailUrl("milestones/" + number)).fetch(GHMilestone.class); m.owner = this; m.root = root; milestones.put(m.getNumber(), m); @@ -2109,10 +2137,10 @@ public GHContent getFileContent(String path) throws IOException { * the io exception */ public GHContent getFileContent(String path, String ref) throws IOException { - Requester requester = root.retrieve(); + Requester requester = root.createRequest(); String target = getApiTailUrl("contents/" + path); - return requester.with("ref", ref).to(target, GHContent.class).wrap(this); + return requester.with("ref", ref).withUrlPath(target).fetch(GHContent.class).wrap(this); } /** @@ -2140,13 +2168,13 @@ public List getDirectoryContent(String path) throws IOException { * the io exception */ public List getDirectoryContent(String path, String ref) throws IOException { - Requester requester = root.retrieve(); + Requester requester = root.createRequest(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } String target = getApiTailUrl("contents/" + path); - GHContent[] files = requester.with("ref", ref).to(target, GHContent[].class); + GHContent[] files = requester.with("ref", ref).withUrlPath(target).fetchArray(GHContent[].class); GHContent.wrap(files, this); @@ -2161,8 +2189,8 @@ public List getDirectoryContent(String path, String ref) throws IOExc * the io exception */ public GHContent getReadme() throws IOException { - Requester requester = root.retrieve(); - return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this); + Requester requester = root.createRequest(); + return requester.withUrlPath(getApiTailUrl("readme")).fetch(GHContent.class).wrap(this); } /** @@ -2265,10 +2293,12 @@ public GHContentUpdateResponse createContent(byte[] contentBytes, String commitM * the io exception */ public GHMilestone createMilestone(String title, String description) throws IOException { - return new Requester(root).with("title", title) - .with("description", description) + return root.createRequest() .method("POST") - .to(getApiTailUrl("milestones"), GHMilestone.class) + .with("title", title) + .with("description", description) + .withUrlPath(getApiTailUrl("milestones")) + .fetch(GHMilestone.class) .wrap(this); } @@ -2284,10 +2314,12 @@ public GHMilestone createMilestone(String title, String description) throws IOEx * the io exception */ public GHDeployKey addDeployKey(String title, String key) throws IOException { - return new Requester(root).with("title", title) - .with("key", key) + return root.createRequest() .method("POST") - .to(getApiTailUrl("keys"), GHDeployKey.class) + .with("title", title) + .with("key", key) + .withUrlPath(getApiTailUrl("keys")) + .fetch(GHDeployKey.class) .wrap(this); } @@ -2301,7 +2333,7 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { */ public List getDeployKeys() throws IOException { List list = new ArrayList( - Arrays.asList(root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class))); + Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHDeployKey[].class))); for (GHDeployKey h : list) h.wrap(this); return list; @@ -2354,10 +2386,12 @@ public GHRepository getParent() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return new Requester(root).with("subscribed", subscribed) - .with("ignored", ignored) + return root.createRequest() .method("PUT") - .to(getApiTailUrl("subscription"), GHSubscription.class) + .with("subscribed", subscribed) + .with("ignored", ignored) + .withUrlPath(getApiTailUrl("subscription")) + .fetch(GHSubscription.class) .wrapUp(this); } @@ -2370,7 +2404,10 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return root.retrieve().to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("subscription")) + .fetch(GHSubscription.class) + .wrapUp(this); } catch (FileNotFoundException e) { return null; } @@ -2384,7 +2421,7 @@ public GHSubscription getSubscription() throws IOException { * the io exception */ public PagedIterable listContributors() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("contributors"), Contributor[].class, item -> item.wrapUp(root)); } @@ -2439,12 +2476,13 @@ public GHRepositoryStatistics getStatistics() { * the io exception */ public GHProject createProject(String name, String body) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("name", name) .with("body", body) - .to(getApiTailUrl("projects"), GHProject.class) + .withUrlPath(getApiTailUrl("projects")) + .fetch(GHProject.class) .wrap(this); } @@ -2458,7 +2496,7 @@ public GHProject createProject(String name, String body) throws IOException { * the io exception */ public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .with("state", status) .asPagedIterable(getApiTailUrl("projects"), GHProject[].class, item -> item.wrap(GHRepository.this)); @@ -2490,10 +2528,15 @@ public PagedIterable listProjects() throws IOException { * @see GitHub#renderMarkdown(String) GitHub#renderMarkdown(String) */ public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException { - return new InputStreamReader(new Requester(root).with("text", text) - .with("mode", mode == null ? null : mode.toString()) - .with("context", getFullName()) - .asStream("/markdown"), "UTF-8"); + return new InputStreamReader( + root.createRequest() + .method("POST") + .with("text", text) + .with("mode", mode == null ? null : mode.toString()) + .with("context", getFullName()) + .withUrlPath("/markdown") + .fetchStream(), + "UTF-8"); } /** @@ -2514,7 +2557,7 @@ public GHNotificationStream listNotifications() { * the io exception */ public GHRepositoryViewTraffic getViewTraffic() throws IOException { - return root.retrieve().to(getApiTailUrl("/traffic/views"), GHRepositoryViewTraffic.class); + return root.createRequest().withUrlPath(getApiTailUrl("/traffic/views")).fetch(GHRepositoryViewTraffic.class); } /** @@ -2526,7 +2569,7 @@ public GHRepositoryViewTraffic getViewTraffic() throws IOException { * the io exception */ public GHRepositoryCloneTraffic getCloneTraffic() throws IOException { - return root.retrieve().to(getApiTailUrl("/traffic/clones"), GHRepositoryCloneTraffic.class); + return root.createRequest().withUrlPath(getApiTailUrl("/traffic/clones")).fetch(GHRepositoryCloneTraffic.class); } @Override @@ -2546,7 +2589,7 @@ public boolean equals(Object obj) { String getApiTailUrl(String tail) { if (tail.length() > 0 && !tail.startsWith("/")) tail = '/' + tail; - return Requester.urlPathEncode("/repos/" + getOwnerName() + "/" + name + tail); + return "/repos/" + getOwnerName() + "/" + name + tail; } /** @@ -2558,7 +2601,7 @@ String getApiTailUrl(String tail) { * the io exception */ public PagedIterable listIssueEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("issues/events"), GHIssueEvent[].class, item -> item.wrapUp(root)); } @@ -2572,7 +2615,10 @@ public PagedIterable listIssueEvents() throws IOException { * the io exception */ public GHIssueEvent getIssueEvent(long id) throws IOException { - return root.retrieve().to(getApiTailUrl("issues/events/" + id), GHIssueEvent.class).wrapUp(root); + return root.createRequest() + .withUrlPath(getApiTailUrl("issues/events/" + id)) + .fetch(GHIssueEvent.class) + .wrapUp(root); } // Only used within listTopics(). @@ -2589,7 +2635,10 @@ private static class Topics { * the io exception */ public List listTopics() throws IOException { - Topics topics = root.retrieve().withPreview(MERCY).to(getApiTailUrl("topics"), Topics.class); + Topics topics = root.createRequest() + .withPreview(MERCY) + .withUrlPath(getApiTailUrl("topics")) + .fetch(Topics.class); return topics.names; } @@ -2603,8 +2652,11 @@ public List listTopics() throws IOException { * the io exception */ public void setTopics(List topics) throws IOException { - Requester requester = new Requester(root); - requester.with("names", topics); - requester.method("PUT").withPreview(MERCY).to(getApiTailUrl("topics")); + root.createRequest() + .method("PUT") + .with("names", topics) + .withPreview(MERCY) + .withUrlPath(getApiTailUrl("topics")) + .send(); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 043a585f15..49b30bae70 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -87,7 +87,7 @@ public PagedIterable getContributorStats(boolean waitTillReady * This gets the actual statistics from the server. Returns null if they are still being cached. */ private PagedIterable getContributorStatsImpl() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("contributors"), ContributorStats[].class, item -> item.wrapUp(root)); } @@ -243,7 +243,7 @@ ContributorStats wrapUp(GitHub root) { * the io exception */ public PagedIterable getCommitActivity() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("commit_activity"), CommitActivity[].class, item -> item.wrapUp(root)); } @@ -318,7 +318,7 @@ public List getCodeFrequency() throws IOException { // Map to ArrayLists first, since there are no field names in the // returned JSON. try { - InputStream stream = root.retrieve().asStream(getApiTailUrl("code_frequency")); + InputStream stream = root.createRequest().withUrlPath(getApiTailUrl("code_frequency")).fetchStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { @@ -400,7 +400,7 @@ public String toString() { * the io exception */ public Participation getParticipation() throws IOException { - return root.retrieve().to(getApiTailUrl("participation"), Participation.class); + return root.createRequest().withUrlPath(getApiTailUrl("participation")).fetch(Participation.class); } /** @@ -460,7 +460,7 @@ Participation wrapUp(GitHub root) { public List getPunchCard() throws IOException { // Map to ArrayLists first, since there are no field names in the // returned JSON. - InputStream stream = root.retrieve().asStream(getApiTailUrl("punch_card")); + InputStream stream = root.createRequest().withUrlPath(getApiTailUrl("punch_card")).fetchStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { diff --git a/src/main/java/org/kohsuke/github/GHSearchBuilder.java b/src/main/java/org/kohsuke/github/GHSearchBuilder.java index a1c9e7c89d..d17f41cb98 100644 --- a/src/main/java/org/kohsuke/github/GHSearchBuilder.java +++ b/src/main/java/org/kohsuke/github/GHSearchBuilder.java @@ -45,7 +45,7 @@ public PagedSearchIterable list() { return new PagedSearchIterable(root) { public PagedIterator _iterator(int pageSize) { req.set("q", StringUtils.join(terms, " ")); - return new PagedIterator(adapt(req.asIterator(getApiUrl(), receiverType, pageSize))) { + return new PagedIterator(adapt(req.withUrlPath(getApiUrl()).asIterator(receiverType, pageSize))) { protected void wrapUp(T[] page) { // SearchResult.getItems() should do it } diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index a8ddc81dd9..b3e7da4fa8 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -87,7 +87,7 @@ public GHRepository getRepository() { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(repo.getApiTailUrl("subscription")); + root.createRequest().method("DELETE").withUrlPath(repo.getApiTailUrl("subscription")).send(); } GHSubscription wrapUp(GHRepository repo) { diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 9254817b91..b0f6f3c862 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -103,7 +103,7 @@ public String getDescription() { * the io exception */ public void setDescription(String description) throws IOException { - root.retrieve().method("PATCH").with("description", description).to(api("")); + root.createRequest().method("PATCH").with("description", description).withUrlPath(api("")).send(); } /** @@ -123,7 +123,7 @@ public int getId() { * the io exception */ public PagedIterable listMembers() throws IOException { - return root.retrieve().asPagedIterable(api("/members"), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(api("/members"), GHUser[].class, item -> item.wrapUp(root)); } /** @@ -146,7 +146,7 @@ public Set getMembers() throws IOException { */ public boolean hasMember(GHUser user) { try { - root.retrieve().to("/teams/" + id + "/members/" + user.getLogin()); + root.createRequest().withUrlPath("/teams/" + id + "/members/" + user.getLogin()).send(); return true; } catch (IOException ignore) { return false; @@ -174,7 +174,7 @@ public Map getRepositories() throws IOException { * @return the paged iterable */ public PagedIterable listRepositories() { - return root.retrieve().asPagedIterable(api("/repos"), GHRepository[].class, item -> item.wrap(root)); + return root.createRequest().asPagedIterable(api("/repos"), GHRepository[].class, item -> item.wrap(root)); } /** @@ -189,7 +189,7 @@ public PagedIterable listRepositories() { * @since 1.59 */ public void add(GHUser u) throws IOException { - root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null); + root.createRequest().method("PUT").withUrlPath(api("/memberships/" + u.getLogin())).send(); } /** @@ -205,7 +205,11 @@ public void add(GHUser u) throws IOException { * the io exception */ public void add(GHUser user, Role role) throws IOException { - root.retrieve().method("PUT").with("role", role).to(api("/memberships/" + user.getLogin()), null); + root.createRequest() + .method("PUT") + .with("role", role) + .withUrlPath(api("/memberships/" + user.getLogin())) + .send(); } /** @@ -217,7 +221,7 @@ public void add(GHUser user, Role role) throws IOException { * the io exception */ public void remove(GHUser u) throws IOException { - root.retrieve().method("DELETE").to(api("/members/" + u.getLogin()), null); + root.createRequest().method("DELETE").withUrlPath(api("/members/" + u.getLogin())).send(); } /** @@ -243,10 +247,11 @@ public void add(GHRepository r) throws IOException { * the io exception */ public void add(GHRepository r, GHOrganization.Permission permission) throws IOException { - root.retrieve() + root.createRequest() .method("PUT") .with("permission", permission) - .to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null); + .withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())) + .send(); } /** @@ -258,7 +263,7 @@ public void add(GHRepository r, GHOrganization.Permission permission) throws IOE * the io exception */ public void remove(GHRepository r) throws IOException { - root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null); + root.createRequest().method("DELETE").withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())).send(); } /** @@ -268,7 +273,7 @@ public void remove(GHRepository r) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(api("")); + root.createRequest().method("DELETE").withUrlPath(api("")).send(); } private String api(String tail) { @@ -289,6 +294,6 @@ public GHOrganization getOrganization() throws IOException { @Override public void refresh() throws IOException { - root.retrieve().to(api(""), this).wrapUp(root); + root.createRequest().withUrlPath(api("")).fetchInto(this).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 52b942512b..cfd492d500 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -161,7 +161,7 @@ GHThread wrap(GitHub root) { * the io exception */ public void markAsRead() throws IOException { - new Requester(root).method("PATCH").to(url); + root.createRequest().method("PATCH").withUrlPath(url).send(); } /** @@ -176,10 +176,12 @@ public void markAsRead() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return new Requester(root).with("subscribed", subscribed) - .with("ignored", ignored) + return root.createRequest() .method("PUT") - .to(subscription_url, GHSubscription.class) + .with("subscribed", subscribed) + .with("ignored", ignored) + .withUrlPath(subscription_url) + .fetch(GHSubscription.class) .wrapUp(root); } @@ -192,7 +194,11 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return new Requester(root).to(subscription_url, GHSubscription.class).wrapUp(root); + return root.createRequest() + .method("POST") + .withUrlPath(subscription_url) + .fetch(GHSubscription.class) + .wrapUp(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index ed27854b13..0439c808c3 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -33,7 +33,7 @@ private TreeEntry(String path, String mode, String type) { GHTreeBuilder(GHRepository repo) { this.repo = repo; - req = new Requester(repo.root); + req = repo.root.createRequest(); } /** @@ -163,6 +163,6 @@ private String getApiTail() { */ public GHTree create() throws IOException { req.with("tree", treeEntries); - return req.method("POST").to(getApiTail(), GHTree.class).wrap(repo); + return req.method("POST").withUrlPath(getApiTail()).fetch(GHTree.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 73cdfea9bd..4624788023 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -43,7 +43,8 @@ public class GHUser extends GHPerson { * the io exception */ public List getKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.retrieve().to(getApiTailUrl("keys"), GHKey[].class))); + return Collections.unmodifiableList( + Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHKey[].class))); } /** @@ -53,7 +54,7 @@ public List getKeys() throws IOException { * the io exception */ public void follow() throws IOException { - new Requester(root).method("PUT").to("/user/following/" + login); + root.createRequest().method("PUT").withUrlPath("/user/following/" + login).send(); } /** @@ -63,7 +64,7 @@ public void follow() throws IOException { * the io exception */ public void unfollow() throws IOException { - new Requester(root).method("DELETE").to("/user/following/" + login); + root.createRequest().method("DELETE").withUrlPath("/user/following/" + login).send(); } /** @@ -109,7 +110,7 @@ public PagedIterable listFollowers() { } private PagedIterable listUser(final String suffix) { - return root.retrieve().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); } /** @@ -133,7 +134,8 @@ public PagedIterable listStarredRepositories() { } private PagedIterable listRepositories(final String suffix) { - return root.retrieve().asPagedIterable(getApiTailUrl(suffix), GHRepository[].class, item -> item.wrap(root)); + return root.createRequest() + .asPagedIterable(getApiTailUrl(suffix), GHRepository[].class, item -> item.wrap(root)); } /** @@ -186,7 +188,9 @@ static GHUser[] wrap(GHUser[] users, GitHub root) { public GHPersonSet getOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().to("/users/" + login + "/orgs", GHOrganization[].class)) { + for (GHOrganization o : root.createRequest() + .withUrlPath("/users/" + login + "/orgs") + .fetchArray(GHOrganization[].class)) { if (names.add(o.getLogin())) // I've seen some duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } @@ -197,7 +201,7 @@ public GHPersonSet getOrganizations() throws IOException { * Lists events performed by a user (this includes private events if the caller is authenticated. */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/users/%s/events", login), GHEventInfo[].class, item -> item.wrapUp(root)); @@ -211,7 +215,7 @@ public PagedIterable listEvents() throws IOException { * the io exception */ public PagedIterable listGists() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/users/%s/gists", login), GHGist[].class, item -> item.wrapUp(GHUser.this)); diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index f8312d5bcc..a14614a03a 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -424,8 +424,8 @@ URL getApiURL(String tailApiUrl) throws IOException { } } - Requester retrieve() { - return new Requester(this).method("GET"); + Requester createRequest() { + return new Requester(this); } /** @@ -438,7 +438,7 @@ Requester retrieve() { public GHRateLimit getRateLimit() throws IOException { GHRateLimit rateLimit; try { - rateLimit = retrieve().to("/rate_limit", JsonRateLimit.class).resources; + rateLimit = createRequest().withUrlPath("/rate_limit").fetch(JsonRateLimit.class).resources; } catch (FileNotFoundException e) { // GitHub Enterprise doesn't have the rate limit // return a default rate limit that @@ -544,7 +544,7 @@ public GHMyself getMyself() throws IOException { if (this.myself != null) return myself; - GHMyself u = retrieve().to("/user", GHMyself.class); + GHMyself u = createRequest().withUrlPath("/user").fetch(GHMyself.class); u.root = this; this.myself = u; @@ -564,7 +564,7 @@ public GHMyself getMyself() throws IOException { public GHUser getUser(String login) throws IOException { GHUser u = users.get(login); if (u == null) { - u = retrieve().to("/users/" + login, GHUser.class); + u = createRequest().withUrlPath("/users/" + login).fetch(GHUser.class); u.root = this; users.put(u.getLogin(), u); } @@ -608,7 +608,7 @@ protected GHUser getUser(GHUser orig) { public GHOrganization getOrganization(String name) throws IOException { GHOrganization o = orgs.get(name); if (o == null) { - o = retrieve().to("/orgs/" + name, GHOrganization.class).wrapUp(this); + o = createRequest().withUrlPath("/orgs/" + name).fetch(GHOrganization.class).wrapUp(this); orgs.put(name, o); } return o; @@ -632,7 +632,7 @@ public PagedIterable listOrganizations() { * @see List All Orgs - Parameters */ public PagedIterable listOrganizations(final String since) { - return retrieve().with("since", since) + return createRequest().with("since", since) .asPagedIterable("/organizations", GHOrganization[].class, item -> item.wrapUp(GitHub.this)); } @@ -648,7 +648,9 @@ public PagedIterable listOrganizations(final String since) { */ public GHRepository getRepository(String name) throws IOException { String[] tokens = name.split("/"); - return retrieve().to("/repos/" + tokens[0] + '/' + tokens[1], GHRepository.class).wrap(this); + return createRequest().withUrlPath("/repos/" + tokens[0] + '/' + tokens[1]) + .fetch(GHRepository.class) + .wrap(this); } /** @@ -661,7 +663,7 @@ public GHRepository getRepository(String name) throws IOException { * the io exception */ public GHRepository getRepositoryById(String id) throws IOException { - return retrieve().to("/repositories/" + id, GHRepository.class).wrap(this); + return createRequest().withUrlPath("/repositories/" + id).fetch(GHRepository.class).wrap(this); } /** @@ -673,7 +675,7 @@ public GHRepository getRepositoryById(String id) throws IOException { * @see GitHub API - Licenses */ public PagedIterable listLicenses() throws IOException { - return retrieve().asPagedIterable("/licenses", GHLicense[].class, item -> item.wrap(GitHub.this)); + return createRequest().asPagedIterable("/licenses", GHLicense[].class, item -> item.wrap(GitHub.this)); } /** @@ -684,7 +686,7 @@ public PagedIterable listLicenses() throws IOException { * the io exception */ public PagedIterable listUsers() throws IOException { - return retrieve().asPagedIterable("/users", GHUser[].class, item -> item.wrapUp(GitHub.this)); + return createRequest().asPagedIterable("/users", GHUser[].class, item -> item.wrapUp(GitHub.this)); } /** @@ -698,7 +700,7 @@ public PagedIterable listUsers() throws IOException { * @see GHLicense#getKey() GHLicense#getKey() */ public GHLicense getLicense(String key) throws IOException { - return retrieve().to("/licenses/" + key, GHLicense.class); + return createRequest().withUrlPath("/licenses/" + key).fetch(GHLicense.class); } /** @@ -709,7 +711,8 @@ public GHLicense getLicense(String key) throws IOException { * the io exception */ public List getMyInvitations() throws IOException { - GHInvitation[] invitations = retrieve().to("/user/repository_invitations", GHInvitation[].class); + GHInvitation[] invitations = createRequest().withUrlPath("/user/repository_invitations") + .fetchArray(GHInvitation[].class); for (GHInvitation i : invitations) { i.wrapUp(this); } @@ -727,7 +730,7 @@ public List getMyInvitations() throws IOException { * the io exception */ public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class); + GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -761,7 +764,8 @@ public Map getUserPublicOrganizations(GHUser user) throw * the io exception */ public Map getUserPublicOrganizations(String login) throws IOException { - GHOrganization[] orgs = retrieve().to("/users/" + login + "/orgs", GHOrganization[].class); + GHOrganization[] orgs = createRequest().withUrlPath("/users/" + login + "/orgs") + .fetchArray(GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -782,7 +786,7 @@ public Map getUserPublicOrganizations(String login) thro */ public Map> getMyTeams() throws IOException { Map> allMyTeams = new HashMap>(); - for (GHTeam team : retrieve().to("/user/teams", GHTeam[].class)) { + for (GHTeam team : createRequest().withUrlPath("/user/teams").fetchArray(GHTeam[].class)) { team.wrapUp(this); String orgLogin = team.getOrganization().getLogin(); Set teamsPerOrg = allMyTeams.get(orgLogin); @@ -805,7 +809,7 @@ public Map> getMyTeams() throws IOException { * the io exception */ public GHTeam getTeam(int id) throws IOException { - return retrieve().to("/teams/" + id, GHTeam.class).wrapUp(this); + return createRequest().withUrlPath("/teams/" + id).fetch(GHTeam.class).wrapUp(this); } /** @@ -816,7 +820,7 @@ public GHTeam getTeam(int id) throws IOException { * the io exception */ public List getEvents() throws IOException { - GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class); + GHEventInfo[] events = createRequest().withUrlPath("/events").fetchArray(GHEventInfo[].class); for (GHEventInfo e : events) e.wrapUp(this); return Arrays.asList(events); @@ -832,7 +836,7 @@ public List getEvents() throws IOException { * the io exception */ public GHGist getGist(String id) throws IOException { - return retrieve().to("/gists/" + id, GHGist.class).wrapUp(this); + return createRequest().withUrlPath("/gists/" + id).fetch(GHGist.class).wrapUp(this); } /** @@ -924,9 +928,9 @@ public GHCreateRepositoryBuilder createRepository(String name) { * @see Documentation */ public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException { - Requester requester = new Requester(this).with("scopes", scope).with("note", note).with("note_url", noteUrl); + Requester requester = createRequest().with("scopes", scope).with("note", note).with("note_url", noteUrl); - return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); + return requester.method("POST").withUrlPath("/authorizations").fetch(GHAuthorization.class).wrap(this); } /** @@ -957,12 +961,10 @@ public GHAuthorization createToken(Collection scope, String note, String return createToken(scope, note, noteUrl); } catch (GHOTPRequiredException ex) { String OTPstring = OTP.get(); - Requester requester = new Requester(this).with("scopes", scope) - .with("note", note) - .with("note_url", noteUrl); + Requester requester = createRequest().with("scopes", scope).with("note", note).with("note_url", noteUrl); // Add the OTP from the user requester.setHeader("x-github-otp", OTPstring); - return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); + return requester.method("POST").withUrlPath("/authorizations").fetch(GHAuthorization.class).wrap(this); } } @@ -990,12 +992,12 @@ public GHAuthorization createOrGetAuth(String clientId, List scopes, String note, String note_url) throws IOException { - Requester requester = new Requester(this).with("client_secret", clientSecret) + Requester requester = createRequest().with("client_secret", clientSecret) .with("scopes", scopes) .with("note", note) .with("note_url", note_url); - return requester.method("PUT").to("/authorizations/clients/" + clientId, GHAuthorization.class); + return requester.method("PUT").withUrlPath("/authorizations/clients/" + clientId).fetch(GHAuthorization.class); } /** @@ -1009,7 +1011,7 @@ public GHAuthorization createOrGetAuth(String clientId, * authorization */ public void deleteAuth(long id) throws IOException { - retrieve().method("DELETE").to("/authorizations/" + id); + createRequest().method("DELETE").withUrlPath("/authorizations/" + id).send(); } /** @@ -1026,7 +1028,8 @@ public void deleteAuth(long id) throws IOException { * authorization */ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { - return retrieve().to("/applications/" + clientId + "/tokens/" + accessToken, GHAuthorization.class); + return createRequest().withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) + .fetch(GHAuthorization.class); } /** @@ -1043,8 +1046,9 @@ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String acces * authorization */ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { - return retrieve().method("POST") - .to("/applications/" + clientId + "/tokens/" + accessToken, GHAuthorization.class); + return createRequest().method("POST") + .withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) + .fetch(GHAuthorization.class); } /** @@ -1057,7 +1061,8 @@ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String acces * authorizations */ public PagedIterable listMyAuthorizations() throws IOException { - return retrieve().asPagedIterable("/authorizations", GHAuthorization[].class, item -> item.wrap(GitHub.this)); + return createRequest() + .asPagedIterable("/authorizations", GHAuthorization[].class, item -> item.wrap(GitHub.this)); } /** @@ -1074,7 +1079,7 @@ public PagedIterable listMyAuthorizations() throws IOException @Preview @Deprecated public GHApp getApp() throws IOException { - return retrieve().withPreview(MACHINE_MAN).to("/app", GHApp.class).wrapUp(this); + return createRequest().withPreview(MACHINE_MAN).withUrlPath("/app").fetch(GHApp.class).wrapUp(this); } /** @@ -1084,7 +1089,7 @@ public GHApp getApp() throws IOException { */ public boolean isCredentialValid() { try { - retrieve().to("/user", GHUser.class); + createRequest().withUrlPath("/user").fetch(GHUser.class); return true; } catch (IOException e) { if (LOGGER.isLoggable(FINE)) @@ -1105,7 +1110,7 @@ public boolean isCredentialValid() { * @see Get Meta */ public GHMeta getMeta() throws IOException { - return retrieve().to("/meta", GHMeta.class); + return createRequest().withUrlPath("/meta").fetch(GHMeta.class); } GHUser intern(GHUser user) throws IOException { @@ -1132,7 +1137,7 @@ GHUser intern(GHUser user) throws IOException { * the io exception */ public GHProject getProject(long id) throws IOException { - return retrieve().withPreview(INERTIA).to("/projects/" + id, GHProject.class).wrap(this); + return createRequest().withPreview(INERTIA).withUrlPath("/projects/" + id).fetch(GHProject.class).wrap(this); } /** @@ -1145,7 +1150,10 @@ public GHProject getProject(long id) throws IOException { * the io exception */ public GHProjectColumn getProjectColumn(long id) throws IOException { - return retrieve().withPreview(INERTIA).to("/projects/columns/" + id, GHProjectColumn.class).wrap(this); + return createRequest().withPreview(INERTIA) + .withUrlPath("/projects/columns/" + id) + .fetch(GHProjectColumn.class) + .wrap(this); } /** @@ -1158,7 +1166,10 @@ public GHProjectColumn getProjectColumn(long id) throws IOException { * the io exception */ public GHProjectCard getProjectCard(long id) throws IOException { - return retrieve().withPreview(INERTIA).to("/projects/columns/cards/" + id, GHProjectCard.class).wrap(this); + return createRequest().withPreview(INERTIA) + .withUrlPath("/projects/columns/cards/" + id) + .fetch(GHProjectCard.class) + .wrap(this); } private static class GHApiInfo { @@ -1188,7 +1199,7 @@ void check(String apiUrl) throws IOException { */ public void checkApiUrlValidity() throws IOException { try { - retrieve().to("/", GHApiInfo.class).check(apiUrl); + createRequest().withUrlPath("/").fetch(GHApiInfo.class).check(apiUrl); } catch (IOException e) { if (isPrivateModeEnabled()) { throw (IOException) new IOException( @@ -1320,7 +1331,7 @@ public PagedIterable listAllPublicRepositories() { * @see documentation */ public PagedIterable listAllPublicRepositories(final String since) { - return retrieve().with("since", since) + return createRequest().with("since", since) .asPagedIterable("/repositories", GHRepository[].class, item -> item.wrap(GitHub.this)); } @@ -1339,9 +1350,13 @@ public PagedIterable listAllPublicRepositories(final String since) * @see GHRepository#renderMarkdown(String, MarkdownMode) GHRepository#renderMarkdown(String, MarkdownMode) */ public Reader renderMarkdown(String text) throws IOException { - return new InputStreamReader(new Requester(this).with(new ByteArrayInputStream(text.getBytes("UTF-8"))) - .contentType("text/plain;charset=UTF-8") - .asStream("/markdown/raw"), "UTF-8"); + return new InputStreamReader( + createRequest().method("POST") + .with(new ByteArrayInputStream(text.getBytes("UTF-8"))) + .contentType("text/plain;charset=UTF-8") + .withUrlPath("/markdown/raw") + .fetchStream(), + "UTF-8"); } static URL parseURL(String s) { diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 1fe3bab8bb..60ba91148c 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -24,7 +24,6 @@ package org.kohsuke.github; import com.fasterxml.jackson.databind.JsonMappingException; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -44,6 +43,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -53,13 +53,13 @@ import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.function.Consumer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import javax.annotation.WillClose; import static java.util.Arrays.asList; @@ -77,10 +77,13 @@ class Requester { private final List args = new ArrayList(); private final Map headers = new LinkedHashMap(); + @Nonnull + private String urlPath = "/"; + /** * Request method. */ - private String method = "POST"; + private String method = "GET"; private String contentType = null; private InputStream body; @@ -91,8 +94,8 @@ class Requester { private boolean forceBody; private static class Entry { - String key; - Object value; + final String key; + final Object value; private Entry(String key, Object value) { this.key = key; @@ -281,9 +284,9 @@ public Requester with(String key, Object value) { * @return the requester */ public Requester set(String key, Object value) { - for (Entry e : args) { - if (e.key.equals(key)) { - e.value = value; + for (int index = 0; index < args.size(); index++) { + if (args.get(index).key.equals(key)) { + args.set(index, new Entry(key, value)); return this; } } @@ -314,6 +317,56 @@ public Requester contentType(String contentType) { return this; } + /** + * NOT FOR PUBLIC USE. Do not make this method public. + *

+ * Sets the path component of api URL without URI encoding. + *

+ * Should only be used when passing a literal URL field from a GHObject, such as {@link GHContent#refresh()} or when + * needing to set query parameters on requests methods that don't usually have them, such as + * {@link GHRelease#uploadAsset(String, InputStream, String)}. + * + * @param urlOrPath + * the content type + * @return the requester + */ + Requester setRawUrlPath(String urlOrPath) { + Objects.requireNonNull(urlOrPath); + this.urlPath = urlOrPath; + return this; + } + + /** + * Path component of api URL. Appended to api url. + *

+ * If urlPath starts with a slash, it will be URI encoded as a path. If it starts with anything else, it will be + * used as is. + * + * @param urlPathItems + * the content type + * @return the requester + */ + public Requester withUrlPath(String... urlPathItems) { + if (!this.urlPath.startsWith("/")) { + throw new GHException("Cannot append to url path after setting a raw path"); + } + + if (urlPathItems.length == 1 && !urlPathItems[0].startsWith("/")) { + return setRawUrlPath(urlPathItems[0]); + } + + String tailUrlPath = String.join("/", urlPathItems); + + if (this.urlPath.endsWith("/")) { + tailUrlPath = StringUtils.stripStart(tailUrlPath, "/"); + } else { + tailUrlPath = StringUtils.prependIfMissing(tailUrlPath, "/"); + } + + this.urlPath += urlPathEncode(tailUrlPath); + return this; + } + /** * Small number of GitHub APIs use HTTP methods somewhat inconsistently, and use a body where it's not expected. * Normally whether parameters go as query parameters or a body depends on the HTTP verb in use, but this method @@ -325,143 +378,108 @@ public Requester inBody() { } /** - * To. + * Sends a request to the specified URL and checks that it is sucessful. * - * @param tailApiUrl - * the tail api url * @throws IOException * the io exception */ - public void to(String tailApiUrl) throws IOException { - _to(tailApiUrl, null, null); + public void send() throws IOException { + _fetch(() -> parse(null, null)); } /** - * Sends a request to the specified URL, and parses the response into the given type via databinding. + * Sends a request and parses the response into the given type via databinding. * * @param * the type parameter - * @param tailApiUrl - * the tail api url * @param type * the type * @return {@link Reader} that reads the response. * @throws IOException * if the server returns 4xx/5xx responses. */ - public T to(String tailApiUrl, Class type) throws IOException { - return _to(tailApiUrl, type, null); + public T fetch(@Nonnull Class type) throws IOException { + return _fetch(() -> parse(type, null)); } /** - * Like {@link #to(String, Class)} but updates an existing object instead of creating a new instance. + * 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 {@link Reader} that reads the response. + * @throws IOException + * if the server returns 4xx/5xx responses. + */ + public T[] fetchArray(@Nonnull Class type) throws IOException { + T[] result; + + // for arrays we might have to loop for pagination + // use the iterator to handle it + List pages = new ArrayList<>(); + int totalSize = 0; + for (Iterator iterator = asIterator(type, 0); iterator.hasNext();) { + T[] nextResult = iterator.next(); + totalSize += Array.getLength(nextResult); + pages.add(nextResult); + } + + result = concatenatePages(type, pages, totalSize); + return result; + } + + /** + * Like {@link #fetch(Class)} but updates an existing object instead of creating a new instance. * * @param * the type parameter - * @param tailApiUrl - * the tail api url * @param existingInstance * the existing instance * @return the t * @throws IOException * the io exception */ - public T to(String tailApiUrl, T existingInstance) throws IOException { - return _to(tailApiUrl, null, existingInstance); - } - - @SuppressFBWarnings("SBSC_USE_STRINGBUFFER_CONCATENATION") - private T _to(String tailApiUrl, Class type, T instance) throws IOException { - if (!isMethodWithBody() && !args.isEmpty()) { - boolean questionMarkFound = tailApiUrl.indexOf('?') != -1; - tailApiUrl += questionMarkFound ? '&' : '?'; - for (Iterator it = args.listIterator(); it.hasNext();) { - Entry arg = it.next(); - tailApiUrl += arg.key + '=' + URLEncoder.encode(arg.value.toString(), "UTF-8"); - if (it.hasNext()) { - tailApiUrl += '&'; - } - } - } - - while (true) {// loop while API rate limit is hit - setupConnection(root.getApiURL(tailApiUrl)); - - buildRequest(); - - try { - T result = parse(type, instance); - if (type != null && type.isArray()) { // we might have to loop for pagination - done through recursion - final String links = uc.getHeaderField("link"); - if (links != null && links.contains("rel=\"next\"")) { - Pattern nextLinkPattern = Pattern.compile(".*<(.*)>; rel=\"next\""); - Matcher nextLinkMatcher = nextLinkPattern.matcher(links); - if (nextLinkMatcher.find()) { - final String link = nextLinkMatcher.group(1); - T nextResult = _to(link, type, instance); - setResponseHeaders(nextResult); - final int resultLength = Array.getLength(result); - final int nextResultLength = Array.getLength(nextResult); - T concatResult = (T) Array.newInstance(type.getComponentType(), - resultLength + nextResultLength); - System.arraycopy(result, 0, concatResult, 0, resultLength); - System.arraycopy(nextResult, 0, concatResult, resultLength, nextResultLength); - result = concatResult; - } - } - } - return setResponseHeaders(result); - } catch (IOException e) { - handleApiError(e); - } finally { - noteRateLimit(tailApiUrl); - } - } + public T fetchInto(@Nonnull T existingInstance) throws IOException { + return _fetch(() -> parse(null, existingInstance)); } /** - * Makes a request and just obtains the HTTP status code. + * Makes a request and just obtains the HTTP status code. Method does not throw exceptions for many status codes + * that would otherwise throw. * - * @param tailApiUrl - * the tail api url * @return the int * @throws IOException * the io exception */ - public int asHttpStatusCode(String tailApiUrl) throws IOException { - while (true) {// loop while API rate limit is hit - method("GET"); - setupConnection(root.getApiURL(tailApiUrl)); - - buildRequest(); - - try { - return uc.getResponseCode(); - } catch (IOException e) { - handleApiError(e); - } finally { - noteRateLimit(tailApiUrl); - } - } + public int fetchHttpStatusCode() throws IOException { + return _fetch(() -> uc.getResponseCode()); } /** * As stream input stream. * - * @param tailApiUrl - * the tail api url * @return the input stream * @throws IOException * the io exception */ - public InputStream asStream(String tailApiUrl) throws IOException { - while (true) {// loop while API rate limit is hit - setupConnection(root.getApiURL(tailApiUrl)); + public InputStream fetchStream() throws IOException { + return _fetch(() -> parse(InputStream.class, null)); + } + + private T _fetch(SupplierThrows supplier) throws IOException { + String tailApiUrl = buildTailApiUrl(urlPath); + URL url = root.getApiURL(tailApiUrl); + return _fetch(tailApiUrl, url, supplier); + } - buildRequest(); + private T _fetch(String tailApiUrl, URL url, SupplierThrows supplier) throws IOException { + while (true) {// loop while API rate limit is hit + setupConnection(url); try { - return wrapStream(uc.getInputStream()); + return supplier.get(); } catch (IOException e) { handleApiError(e); } finally { @@ -470,11 +488,52 @@ public InputStream asStream(String tailApiUrl) throws IOException { } } + private T[] concatenatePages(Class type, List pages, int totalLength) { + + T[] result = type.cast(Array.newInstance(type.getComponentType(), totalLength)); + + int position = 0; + for (T[] page : pages) { + final int pageLength = Array.getLength(page); + System.arraycopy(page, 0, result, position, pageLength); + position += pageLength; + } + return result; + } + + private String buildTailApiUrl(String tailApiUrl) { + if (!isMethodWithBody() && !args.isEmpty()) { + try { + boolean questionMarkFound = tailApiUrl.indexOf('?') != -1; + StringBuilder argString = new StringBuilder(); + argString.append(questionMarkFound ? '&' : '?'); + + for (Iterator it = args.listIterator(); it.hasNext();) { + Entry arg = it.next(); + argString.append(URLEncoder.encode(arg.key, StandardCharsets.UTF_8.name())); + argString.append('='); + argString.append(URLEncoder.encode(arg.value.toString(), StandardCharsets.UTF_8.name())); + if (it.hasNext()) { + argString.append('&'); + } + } + tailApiUrl += argString; + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); // UTF-8 is mandatory + } + } + return tailApiUrl; + } + private void noteRateLimit(String tailApiUrl) { + if (uc == null) { + return; + } if (tailApiUrl.startsWith("/search")) { // the search API uses a different rate limit return; } + String limitString = uc.getHeaderField("X-RateLimit-Limit"); if (StringUtils.isBlank(limitString)) { // if we are missing a header, return fast @@ -569,31 +628,31 @@ private boolean isMethodWithBody() { } PagedIterable asPagedIterable(String tailApiUrl, Class type, Consumer consumer) { - return new PagedIterableWithConsumer<>(type, this, tailApiUrl, consumer); + return withUrlPath(tailApiUrl).asPagedIterable(type, consumer); } - static class PagedIterableWithConsumer extends PagedIterable { + PagedIterable asPagedIterable(Class type, Consumer consumer) { + return new PagedIterableWithConsumer<>(type, consumer); + } - private final Class clazz; - private final Requester requester; - private final String tailApiUrl; - private final Consumer consumer; + class PagedIterableWithConsumer extends PagedIterable { - PagedIterableWithConsumer(Class clazz, Requester requester, String tailApiUrl, Consumer consumer) { + private final Class clazz; + private final Consumer consumer; + + PagedIterableWithConsumer(Class clazz, Consumer consumer) { this.clazz = clazz; - this.tailApiUrl = tailApiUrl; - this.requester = requester; this.consumer = consumer; } @Override - public PagedIterator _iterator(int pageSize) { - final Iterator iterator = requester.asIterator(tailApiUrl, clazz, pageSize); - return new PagedIterator(iterator) { + public PagedIterator _iterator(int pageSize) { + final Iterator iterator = asIterator(clazz, pageSize); + return new PagedIterator(iterator) { @Override - protected void wrapUp(S[] page) { + protected void wrapUp(T[] page) { if (consumer != null) { - for (S item : page) { + for (T item : page) { consumer.accept(item); } } @@ -607,35 +666,32 @@ protected void wrapUp(S[] page) { * * Every iterator call reports a new batch. */ - Iterator asIterator(String tailApiUrl, Class type, int pageSize) { - method("GET"); + Iterator asIterator(Class type, int pageSize) { + if (method != "GET") { + throw new IllegalStateException("Request method \"GET\" is required for iterator."); + } if (pageSize != 0) args.add(new Entry("per_page", pageSize)); - StringBuilder s = new StringBuilder(tailApiUrl); - if (!args.isEmpty()) { - boolean first = true; - try { - for (Entry a : args) { - s.append(first ? '?' : '&'); - first = false; - s.append(URLEncoder.encode(a.key, "UTF-8")); - s.append('='); - s.append(URLEncoder.encode(a.value.toString(), "UTF-8")); - } - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); // UTF-8 is mandatory - } - } + String tailApiUrl = buildTailApiUrl(urlPath); try { - return new PagingIterator(type, tailApiUrl, root.getApiURL(s.toString())); + return new PagingIterator<>(type, tailApiUrl, root.getApiURL(tailApiUrl)); } catch (IOException e) { throw new GHException("Unable to build github Api URL", e); } } + /** + * May be used for any item that has pagination information. + * + * Works for array responses, also works for search results which are single instances with an array of items + * inside. + * + * @param + * type of each page (not the items in the page). + */ class PagingIterator implements Iterator { private final Class type; @@ -682,19 +738,9 @@ private void fetch() { return; // no more data to fetch try { - while (true) {// loop while API rate limit is hit - setupConnection(url); - try { - next = parse(type, null); - assert next != null; - findNextURL(); - return; - } catch (IOException e) { - handleApiError(e); - } finally { - noteRateLimit(tailApiUrl); - } - } + next = _fetch(tailApiUrl, url, () -> parse(type, null)); + assert next != null; + findNextURL(); } catch (IOException e) { throw new GHException("Failed to retrieve " + url, e); } @@ -744,6 +790,7 @@ private void setupConnection(URL url) throws IOException { setRequestMethod(uc); uc.setRequestProperty("Accept-Encoding", "gzip"); + buildRequest(); } private void setRequestMethod(HttpURLConnection uc) throws IOException { @@ -815,7 +862,11 @@ private T parse(Class type, T instance, int timeouts) throws IOException return null; } - r = new InputStreamReader(wrapStream(uc.getInputStream()), "UTF-8"); + if (type != null && type.equals(InputStream.class)) { + return type.cast(wrapStream(uc.getInputStream())); + } + + r = new InputStreamReader(wrapStream(uc.getInputStream()), StandardCharsets.UTF_8); String data = IOUtils.toString(r); if (type != null) try { @@ -894,7 +945,7 @@ void handleApiError(IOException e) throws IOException { InputStream es = wrapStream(uc.getErrorStream()); if (es != null) { try { - String error = IOUtils.toString(es, "UTF-8"); + String error = IOUtils.toString(es, StandardCharsets.UTF_8); if (e instanceof FileNotFoundException) { // pass through 404 Not Found to allow the caller to handle it intelligently e = (IOException) new GHFileNotFoundException(error).withResponseHeaderFields(uc).initCause(e); @@ -961,4 +1012,27 @@ public static String urlPathEncode(String value) { private static final List METHODS_WITHOUT_BODY = asList("GET", "DELETE"); private static final Logger LOGGER = Logger.getLogger(Requester.class.getName()); + + /** + * Represents a supplier of results that can throw. + * + *

+ * This is a functional interface whose functional method is {@link #get()}. + * + * @param + * the type of results supplied by this supplier + * @param + * the type of throwable that could be thrown + */ + @FunctionalInterface + interface SupplierThrows { + + /** + * Gets a result. + * + * @return a result + * @throws E + */ + T get() throws E; + } } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 02727cde25..810b8b3528 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -313,11 +313,9 @@ public void testPublicKeys() throws Exception { assertFalse(keys.isEmpty()); } - @Ignore("Needs mocking check") @Test public void testOrgFork() throws Exception { - kohsuke(); - + cleanupRepository(GITHUB_API_TEST_ORG + "/rubywm"); gitHub.getRepository("kohsuke/rubywm").forkTo(gitHub.getOrganization(GITHUB_API_TEST_ORG)); } diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 6b4d3b7a02..95f1a1e3eb 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -96,8 +96,9 @@ public void getMeta() throws IOException { ReadOnlyObjects.GHMetaGettersFinalCreator.class, }; for (Class metaClass : examples) { - ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve() - .to("/meta", (Class) metaClass); + ReadOnlyObjects.GHMetaExample metaExample = gitHub.createRequest() + .withUrlPath("/meta") + .fetch((Class) metaClass); assertTrue(metaExample.isVerifiablePasswordAuthentication()); assertEquals(19, metaExample.getApi().size()); assertEquals(19, metaExample.getGit().size()); diff --git a/src/test/java/org/kohsuke/github/RepositoryMockTest.java b/src/test/java/org/kohsuke/github/RepositoryMockTest.java index 6e8969adae..66ad11c025 100644 --- a/src/test/java/org/kohsuke/github/RepositoryMockTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryMockTest.java @@ -42,9 +42,11 @@ public void listCollaborators() throws Exception { when(iterator.next()).thenReturn(new GHUser[]{ user1 }, new GHUser[]{ user2 }); Requester requester = Mockito.mock(Requester.class); - when(mockGitHub.retrieve()).thenReturn(requester); + when(mockGitHub.createRequest()).thenReturn(requester); - when(requester.asIterator("/repos/*/*/collaborators", GHUser[].class, 0)).thenReturn(iterator, iterator); + when(requester.withUrlPath("/repos/*/*/collaborators")).thenReturn(requester); + + when(requester.asIterator(GHUser[].class, 0)).thenReturn(iterator, iterator); PagedIterable pagedIterable = Mockito.mock(PagedIterable.class); when(mockRepository.listCollaborators()).thenReturn(pagedIterable); diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json index ea6a5672a7..75b848873c 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json @@ -2,7 +2,7 @@ "id": "a979348d-c6be-4cb7-8877-7c42a6f013ae", "name": "notifications", "request": { - "url": "/notifications?all=true&page=9&all=true", + "url": "/notifications?all=true&page=9", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json index 340b8a92eb..82ef74131a 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json @@ -2,7 +2,7 @@ "id": "89714ed3-235b-4914-86a8-44ad66d59f30", "name": "notifications", "request": { - "url": "/notifications?all=true&page=10&all=true", + "url": "/notifications?all=true&page=10", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json index 6e0cdb447b..21ea9c9f9b 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json @@ -2,7 +2,7 @@ "id": "2b718339-36d3-4c6b-9484-79cdd79a79e4", "name": "notifications", "request": { - "url": "/notifications?all=true&page=11&all=true", + "url": "/notifications?all=true&page=11", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json index 334b2d2725..d9630607d7 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json @@ -2,7 +2,7 @@ "id": "989db4b3-8dde-4065-b4ef-6a2d90a2753a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=12&all=true", + "url": "/notifications?all=true&page=12", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json index 59c90bd0b6..5d3c4281a4 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json @@ -2,7 +2,7 @@ "id": "50b907ef-a983-4cc9-bfd2-e2ba76eae729", "name": "notifications", "request": { - "url": "/notifications?all=true&page=13&all=true", + "url": "/notifications?all=true&page=13", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json index 6b25c7de98..66534ef7cd 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json @@ -2,7 +2,7 @@ "id": "f2648b73-4af1-4be3-a2a4-9edc712c5d59", "name": "notifications", "request": { - "url": "/notifications?all=true&page=14&all=true", + "url": "/notifications?all=true&page=14", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json index 9da8b89150..063c092f13 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json @@ -2,7 +2,7 @@ "id": "ee5a6c9f-da3a-47e7-a393-b403e82ae5d9", "name": "notifications", "request": { - "url": "/notifications?all=true&page=15&all=true", + "url": "/notifications?all=true&page=15", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json index 3f36730721..6b8abb3763 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json @@ -2,7 +2,7 @@ "id": "a41aeecf-7097-4ac6-b857-ab14797afe0a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=16&all=true", + "url": "/notifications?all=true&page=16", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json index bc4bbe5240..0a94a0c84f 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json @@ -2,7 +2,7 @@ "id": "e1d519f7-9bd2-4fcd-a288-2391944ec7ca", "name": "notifications", "request": { - "url": "/notifications?all=true&page=17&all=true", + "url": "/notifications?all=true&page=17", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json index 667c9f768a..33fbc0cbdc 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json @@ -2,7 +2,7 @@ "id": "1b694852-8043-418c-a76e-39370f22db96", "name": "notifications", "request": { - "url": "/notifications?all=true&page=18&all=true", + "url": "/notifications?all=true&page=18", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json index 46c3189aa4..55ed37649c 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json @@ -2,7 +2,7 @@ "id": "48908278-ce2f-4cec-8662-6f4ca3d81226", "name": "notifications", "request": { - "url": "/notifications?all=true&page=19&all=true", + "url": "/notifications?all=true&page=19", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json index 8238b8ca6a..d1d6ce1e5d 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json @@ -2,7 +2,7 @@ "id": "42be6527-0570-4353-b42f-d0cae80258e3", "name": "notifications", "request": { - "url": "/notifications?all=true&page=20&all=true", + "url": "/notifications?all=true&page=20", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json index 2a3aafe0f7..e57e5703da 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json @@ -2,7 +2,7 @@ "id": "5720c49c-c69b-495b-b7e6-b885d88c10b1", "name": "notifications", "request": { - "url": "/notifications?all=true&page=21&all=true", + "url": "/notifications?all=true&page=21", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json index 7c46c5d61e..e8dda461b9 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json @@ -2,7 +2,7 @@ "id": "045c369a-0818-455a-afe1-3ae9ec919af2", "name": "notifications", "request": { - "url": "/notifications?all=true&page=22&all=true", + "url": "/notifications?all=true&page=22", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json index 71a870674e..d128ed1bf1 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json @@ -2,7 +2,7 @@ "id": "bfc7733f-6dff-4675-81e9-926103c40b83", "name": "notifications", "request": { - "url": "/notifications?all=true&page=23&all=true", + "url": "/notifications?all=true&page=23", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json index e90a40a00c..8a177e2a2a 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json @@ -2,7 +2,7 @@ "id": "d9617266-1ca6-44b2-b495-52c1f3be4b91", "name": "notifications", "request": { - "url": "/notifications?all=true&page=2&all=true", + "url": "/notifications?all=true&page=2", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json index 2c5994ca0a..0e65dfad11 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json @@ -2,7 +2,7 @@ "id": "6dea5253-3aa2-4484-b97a-effcad5c6ebd", "name": "notifications", "request": { - "url": "/notifications?all=true&page=3&all=true", + "url": "/notifications?all=true&page=3", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json index 8763e59513..1a893896d2 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json @@ -2,7 +2,7 @@ "id": "a8e9449d-b78c-4e46-801e-59fc459920d3", "name": "notifications", "request": { - "url": "/notifications?all=true&page=4&all=true", + "url": "/notifications?all=true&page=4", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json index 7fe53ad5fc..8602bc43d0 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json @@ -2,7 +2,7 @@ "id": "2658e99a-6619-4b0b-b70f-814a0841839e", "name": "notifications", "request": { - "url": "/notifications?all=true&page=5&all=true", + "url": "/notifications?all=true&page=5", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json index e40f801aa1..330b27af4f 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json @@ -2,7 +2,7 @@ "id": "f2524684-5156-4db6-97fa-10dedac5f779", "name": "notifications", "request": { - "url": "/notifications?all=true&page=6&all=true", + "url": "/notifications?all=true&page=6", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json index 479c340c72..8dd6188c30 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json @@ -2,7 +2,7 @@ "id": "9437189d-2f1b-47de-898d-66fde88ef05b", "name": "notifications", "request": { - "url": "/notifications?all=true&page=7&all=true", + "url": "/notifications?all=true&page=7", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json index 079f9a0fa7..a783d53d33 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json @@ -2,7 +2,7 @@ "id": "1de52522-e900-4b19-90cd-758573c2349a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=8&all=true", + "url": "/notifications?all=true&page=8", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json index b5fe8f595e..0cd1ce7827 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json @@ -2,7 +2,7 @@ "id": "b4bcdadb-a708-4509-9382-479f300eb172", "name": "repos_github-api-test-org_github-api-test_deployments", "request": { - "url": "/repos/github-api-test-org/github-api-test/deployments?ref=master&environment=unittest&", + "url": "/repos/github-api-test-org/github-api-test/deployments?ref=master&environment=unittest", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json new file mode 100644 index 0000000000..8a639e51da --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json @@ -0,0 +1,41 @@ +{ + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/github-api-test-org", + "repos_url": "https://api.github.com/orgs/github-api-test-org/repos", + "events_url": "https://api.github.com/orgs/github-api-test-org/events", + "hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks", + "issues_url": "https://api.github.com/orgs/github-api-test-org/issues", + "members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 9, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/github-api-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 132, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 10, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json new file mode 100644 index 0000000000..81e8e7d2d0 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json @@ -0,0 +1,312 @@ +{ + "id": 224294379, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjQyOTQzNzk=", + "name": "rubywm", + "full_name": "github-api-test-org/rubywm", + "private": false, + "owner": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/github-api-test-org/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": true, + "url": "https://api.github.com/repos/github-api-test-org/rubywm", + "forks_url": "https://api.github.com/repos/github-api-test-org/rubywm/forks", + "keys_url": "https://api.github.com/repos/github-api-test-org/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/github-api-test-org/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/github-api-test-org/rubywm/teams", + "hooks_url": "https://api.github.com/repos/github-api-test-org/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/github-api-test-org/rubywm/events", + "assignees_url": "https://api.github.com/repos/github-api-test-org/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/github-api-test-org/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/tags", + "blobs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/github-api-test-org/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/github-api-test-org/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/github-api-test-org/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/github-api-test-org/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscription", + "commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/github-api-test-org/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/github-api-test-org/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/github-api-test-org/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/github-api-test-org/rubywm/merges", + "archive_url": "https://api.github.com/repos/github-api-test-org/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/github-api-test-org/rubywm/downloads", + "issues_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/github-api-test-org/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/github-api-test-org/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/github-api-test-org/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/github-api-test-org/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/github-api-test-org/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/github-api-test-org/rubywm/deployments", + "created_at": "2019-11-26T22:05:41Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/github-api-test-org/rubywm.git", + "ssh_url": "git@github.com:github-api-test-org/rubywm.git", + "clone_url": "https://github.com/github-api-test-org/rubywm.git", + "svn_url": "https://github.com/github-api-test-org/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": false, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "organization": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "parent": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "source": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "network_count": 6, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json new file mode 100644 index 0000000000..48ea41c76d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json @@ -0,0 +1,101 @@ +{ + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 5, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 5, + "open_issues": 0, + "watchers": 7, + "default_branch": "master", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "network_count": 5, + "subscribers_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json new file mode 100644 index 0000000000..f734edeabe --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json @@ -0,0 +1,309 @@ +{ + "id": 224294379, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjQyOTQzNzk=", + "name": "rubywm", + "full_name": "github-api-test-org/rubywm", + "private": false, + "owner": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/github-api-test-org/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": true, + "url": "https://api.github.com/repos/github-api-test-org/rubywm", + "forks_url": "https://api.github.com/repos/github-api-test-org/rubywm/forks", + "keys_url": "https://api.github.com/repos/github-api-test-org/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/github-api-test-org/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/github-api-test-org/rubywm/teams", + "hooks_url": "https://api.github.com/repos/github-api-test-org/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/github-api-test-org/rubywm/events", + "assignees_url": "https://api.github.com/repos/github-api-test-org/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/github-api-test-org/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/tags", + "blobs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/github-api-test-org/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/github-api-test-org/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/github-api-test-org/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/github-api-test-org/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscription", + "commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/github-api-test-org/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/github-api-test-org/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/github-api-test-org/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/github-api-test-org/rubywm/merges", + "archive_url": "https://api.github.com/repos/github-api-test-org/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/github-api-test-org/rubywm/downloads", + "issues_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/github-api-test-org/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/github-api-test-org/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/github-api-test-org/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/github-api-test-org/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/github-api-test-org/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/github-api-test-org/rubywm/deployments", + "created_at": "2019-11-26T22:05:41Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/github-api-test-org/rubywm.git", + "ssh_url": "git@github.com:github-api-test-org/rubywm.git", + "clone_url": "https://github.com/github-api-test-org/rubywm.git", + "svn_url": "https://github.com/github-api-test-org/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": false, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "organization": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "parent": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "source": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "network_count": 6, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json new file mode 100644 index 0000000000..a45e820c9e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json @@ -0,0 +1,45 @@ +{ + "login": "bitwiseman", + "id": 1958953, + "node_id": "MDQ6VXNlcjE5NTg5NTM=", + "avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bitwiseman", + "html_url": "https://github.com/bitwiseman", + "followers_url": "https://api.github.com/users/bitwiseman/followers", + "following_url": "https://api.github.com/users/bitwiseman/following{/other_user}", + "gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions", + "organizations_url": "https://api.github.com/users/bitwiseman/orgs", + "repos_url": "https://api.github.com/users/bitwiseman/repos", + "events_url": "https://api.github.com/users/bitwiseman/events{/privacy}", + "received_events_url": "https://api.github.com/users/bitwiseman/received_events", + "type": "User", + "site_admin": false, + "name": "Liam Newman", + "company": "Cloudbees, Inc.", + "blog": "", + "location": "Seattle, WA, USA", + "email": "bitwiseman@gmail.com", + "hireable": null, + "bio": "https://twitter.com/bitwiseman", + "public_repos": 176, + "public_gists": 7, + "followers": 141, + "following": 9, + "created_at": "2012-07-11T20:38:33Z", + "updated_at": "2019-11-26T22:02:50Z", + "private_gists": 7, + "total_private_repos": 10, + "owned_private_repos": 0, + "disk_usage": 33697, + "collaborators": 0, + "two_factor_authentication": true, + "plan": { + "name": "free", + "space": 976562499, + "collaborators": 0, + "private_repos": 10000 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json new file mode 100644 index 0000000000..43e0fedadb --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json @@ -0,0 +1,43 @@ +{ + "id": "1839874d-c184-4f20-942f-cc6d36806868", + "name": "orgs_github-api-test-org", + "request": { + "url": "/orgs/github-api-test-org", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:41 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4913", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"21e3e165e412ba27b4bd9260ce4bcf70\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D58F8:93D8C8:5DDDA1B4" + } + }, + "uuid": "1839874d-c184-4f20-942f-cc6d36806868", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json new file mode 100644 index 0000000000..a975a853d0 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json @@ -0,0 +1,43 @@ +{ + "id": "5b2f012d-aa23-4e59-849c-22b53a469c95", + "name": "repos_github-api-test-org_rubywm", + "request": { + "url": "/repos/github-api-test-org/rubywm", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:42 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4911", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"4b00cafaee1fc02361314a36cba325da\"", + "Last-Modified": "Tue, 13 Aug 2019 14:29:25 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D598F:93D986:5DDDA1B6" + } + }, + "uuid": "5b2f012d-aa23-4e59-849c-22b53a469c95", + "persistent": true, + "insertionIndex": 5 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json new file mode 100644 index 0000000000..7cfe8f5677 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json @@ -0,0 +1,43 @@ +{ + "id": "7f6b9ed5-222f-4c89-95a7-e45ef24d78a7", + "name": "repos_kohsuke_rubywm", + "request": { + "url": "/repos/kohsuke/rubywm", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:40 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4914", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"956ce297c162ac69efaf4ba1328b1cdb\"", + "Last-Modified": "Tue, 13 Aug 2019 14:29:25 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D58DD:93D7F2:5DDDA1B3" + } + }, + "uuid": "7f6b9ed5-222f-4c89-95a7-e45ef24d78a7", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json new file mode 100644 index 0000000000..242c23878c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json @@ -0,0 +1,43 @@ +{ + "id": "044af303-143e-4469-be96-0a6e72032e5c", + "name": "repos_kohsuke_rubywm_forks", + "request": { + "url": "/repos/kohsuke/rubywm/forks", + "method": "POST", + "bodyPatterns": [ + { + "equalToJson": "{\"organization\":\"github-api-test-org\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ] + }, + "response": { + "status": 202, + "bodyFileName": "repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:42 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "202 Accepted", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4912", + "X-RateLimit-Reset": "1574809159", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D5915:93D8F7:5DDDA1B5" + } + }, + "uuid": "044af303-143e-4469-be96-0a6e72032e5c", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json new file mode 100644 index 0000000000..fd2c70467d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json @@ -0,0 +1,43 @@ +{ + "id": "07a0042d-8162-4e85-9ed4-0ed31ebc9d63", + "name": "user", + "request": { + "url": "/user", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:39 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4917", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"072b29f799172fd1523e04ec9f30fc24\"", + "Last-Modified": "Tue, 26 Nov 2019 22:02:50 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D5829:93D7D9:5DDDA1B3" + } + }, + "uuid": "07a0042d-8162-4e85-9ed4-0ed31ebc9d63", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file