From 40f05e4dbb551e94c6879022e087c8be7dbc3ecf Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Mon, 16 Dec 2019 11:18:56 -0800 Subject: [PATCH] Clean up request method calls --- .../github/GHAppCreateTokenBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHAsset.java | 2 +- .../org/kohsuke/github/GHBlobBuilder.java | 2 +- .../kohsuke/github/GHBranchProtection.java | 4 +-- .../github/GHBranchProtectionBuilder.java | 2 +- .../org/kohsuke/github/GHCommitComment.java | 7 +---- .../github/GHCreateRepositoryBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHGist.java | 2 +- .../org/kohsuke/github/GHGistUpdater.java | 2 +- src/main/java/org/kohsuke/github/GHIssue.java | 11 +++----- .../org/kohsuke/github/GHIssueComment.java | 7 +---- .../java/org/kohsuke/github/GHMilestone.java | 2 +- .../kohsuke/github/GHNotificationStream.java | 5 ++-- .../org/kohsuke/github/GHOrganization.java | 4 +-- .../java/org/kohsuke/github/GHProject.java | 10 ++----- .../org/kohsuke/github/GHProjectCard.java | 10 ++----- .../org/kohsuke/github/GHProjectColumn.java | 10 ++----- .../org/kohsuke/github/GHPullRequest.java | 2 +- .../github/GHPullRequestReviewBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHRef.java | 3 +-- .../java/org/kohsuke/github/GHRelease.java | 4 +-- .../org/kohsuke/github/GHReleaseUpdater.java | 2 +- .../java/org/kohsuke/github/GHRepository.java | 27 ++++++++++--------- .../github/GHRepositoryStatistics.java | 4 +-- .../java/org/kohsuke/github/GHThread.java | 3 +-- .../org/kohsuke/github/GHTreeBuilder.java | 2 +- src/main/java/org/kohsuke/github/GitHub.java | 16 ++++------- .../java/org/kohsuke/github/Requester.java | 24 ++++++++--------- 28 files changed, 66 insertions(+), 107 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index f2b70088e..c504b2ee7 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 = root.retrieve().method("POST"); + this.builder = root.retrieve(); withPermissions(builder, permissions); } diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 121dde349..1bd739c78 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public class GHAsset extends GHObject { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index 5fb170866..c26ce8a82 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -13,7 +13,7 @@ public class GHBlobBuilder { GHBlobBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve().method("POST"); + req = repo.root.retrieve(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index c0c4676bf..5db307ca6 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -87,7 +87,7 @@ public class GHBranchProtection { @Preview @Deprecated public boolean getRequiredSignatures() throws IOException { - return requester().method("GET").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class).enabled; + return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class).enabled; } /** @@ -123,7 +123,7 @@ public class GHBranchProtection { } private Requester requester() { - return root.retrieve().method("POST").withPreview(ZZZAX); + return root.retrieve().withPreview(ZZZAX); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index 13d4fb1a2..ad57d372d 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -353,7 +353,7 @@ public class GHBranchProtectionBuilder { } private Requester requester() { - return branch.getRoot().retrieve().method("POST").withPreview(LUKE_CAGE); + return branch.getRoot().retrieve().withPreview(LUKE_CAGE); } private static class Restrictions { diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index c7c596327..e658cf5a0 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -113,12 +113,7 @@ public class GHCommitComment extends GHObject implements Reactable { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve() - .method("POST") - .with("body", body) - .method("PATCH") - .withUrlPath(getApiTail()) - .to(GHCommitComment.class); + owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiTail()).to(GHCommitComment.class); this.body = body; } diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 0c833d3a3..2f1854d0e 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 = root.retrieve().method("POST"); + this.builder = root.retrieve(); this.builder.with("name", name); } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index f0c59d3f5..df9de4603 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -203,7 +203,7 @@ public class GHGist extends GHObject { * the io exception */ public boolean isStarred() throws IOException { - return root.retrieve().asHttpStatusCode(getApiTailUrl("star")) / 100 == 2; + return root.retrieve().withUrlPath(getApiTailUrl("star")).asHttpStatusCode() / 100 == 2; } /** diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index 94064b6a0..fc8ef1150 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 = base.root.retrieve().method("POST"); + this.builder = base.root.retrieve(); files = new LinkedHashMap<>(); } diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 4700a6d53..22aeafb4d 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -239,11 +239,11 @@ public class GHIssue extends GHObject implements Reactable { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } private void editIssue(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).to(); } /** @@ -520,12 +520,7 @@ public class GHIssue extends GHObject implements Reactable { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - root.retrieve() - .method("POST") - .with(ASSIGNEES, getLogins(assignees)) - .method("PATCH") - .withUrlPath(getIssuesApiRoute()) - .to(); + root.retrieve().method("PATCH").with(ASSIGNEES, getLogins(assignees)).withUrlPath(getIssuesApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 2328897f2..68415b073 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -108,12 +108,7 @@ public class GHIssueComment extends GHObject implements Reactable { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve() - .method("POST") - .with("body", body) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(GHIssueComment.class); + owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiRoute()).to(GHIssueComment.class); this.body = body; } diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 222b73fe3..4b0ef4031 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -159,7 +159,7 @@ public class GHMilestone extends GHObject { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 9209cdc52..b29ed5566 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -102,7 +102,6 @@ public class GHNotificationStream implements Iterable { public Iterator iterator() { // capture the configuration setting here final Requester req = root.retrieve() - .method("GET") .with("all", all) .with("participating", participating) .with("since", since); @@ -233,10 +232,10 @@ public class GHNotificationStream implements Iterable { * the io exception */ public void markAsRead(long timestamp) throws IOException { - final Requester req = root.retrieve().method("PUT"); + final Requester req = root.retrieve(); if (timestamp >= 0) req.with("last_read_at", GitHub.printDate(new Date(timestamp))); - req.asHttpStatusCode(apiUrl); + req.withUrlPath(apiUrl).asHttpStatusCode(); } 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 867cb6e94..25eddfbb7 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -397,7 +397,7 @@ public class GHOrganization extends GHPerson { repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); } /** @@ -438,7 +438,7 @@ public class GHOrganization extends GHPerson { repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); } /** diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index f10102f59..c7afcb5db 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -176,13 +176,7 @@ public class GHProject extends GHObject { } private void edit(String key, Object value) throws IOException { - root.retrieve() - .method("POST") - .withPreview(INERTIA) - .with(key, value) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(); + root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); } /** @@ -276,7 +270,7 @@ public class GHProject extends GHObject { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index 80746c43c..7a9af18d9 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -198,13 +198,7 @@ public class GHProjectCard extends GHObject { } private void edit(String key, Object value) throws IOException { - root.retrieve() - .method("POST") - .withPreview(INERTIA) - .with(key, value) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(); + root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); } /** @@ -223,6 +217,6 @@ public class GHProjectCard extends GHObject { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index 660b13576..fcf43c813 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -106,13 +106,7 @@ public class GHProjectColumn extends GHObject { } private void edit(String key, Object value) throws IOException { - root.retrieve() - .method("POST") - .withPreview(INERTIA) - .with(key, value) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(); + root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); } /** @@ -131,7 +125,7 @@ public class GHProjectColumn extends GHObject { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 744a29921..af368ae25 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -615,7 +615,7 @@ public class GHPullRequest extends GHIssue implements Refreshable { private void fetchIssue() throws IOException { if (!fetchedIssueDetails) { - root.retrieve().method("GET").withUrlPath(getIssuesApiRoute()).to(this); + root.retrieve().withUrlPath(getIssuesApiRoute()).to(this); fetchedIssueDetails = true; } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index df08aed0f..27a555015 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 = pr.root.retrieve().method("POST"); + this.builder = pr.root.retrieve(); } // public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event, diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 1022d8671..c6370e1da 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -67,10 +67,9 @@ public class GHRef { */ public void updateTo(String sha, Boolean force) throws IOException { root.retrieve() - .method("POST") + .method("PATCH") .with("sha", sha) .with("force", force) - .method("PATCH") .withUrlPath(url) .to(GHRef.class) .wrap(root); diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index b742d6bf5..c3eff0594 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -256,9 +256,9 @@ public class GHRelease extends GHObject { * the io exception */ public List getAssets() throws IOException { - Requester builder = owner.root.retrieve().method("POST"); + Requester builder = owner.root.retrieve(); - GHAsset[] assets = builder.method("GET").withUrlPath(getApiTailUrl("assets")).toArray(GHAsset[].class); + GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).toArray(GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index e659b80a2..b9a3106ef 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 = base.root.retrieve().method("POST"); + this.builder = base.root.retrieve(); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index d50ce194e..02dcfda10 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -419,7 +419,6 @@ public class GHRepository extends GHObject { .method("POST") .with("ref", name) .with("sha", sha) - .method("POST") .withUrlPath(getApiTailUrl("git/refs")) .to(GHRef.class) .wrap(root); @@ -764,7 +763,7 @@ public class GHRepository extends GHObject { * the io exception */ public boolean hasAssignee(GHUser u) throws IOException { - return root.retrieve().asHttpStatusCode(getApiTailUrl("assignees/" + u.getLogin())) / 100 == 2; + return root.retrieve().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).asHttpStatusCode() / 100 == 2; } /** @@ -901,7 +900,7 @@ public class GHRepository extends GHObject { } private void edit(String key, String value) throws IOException { - Requester requester = root.retrieve().method("POST"); + Requester requester = root.retrieve(); 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").withUrlPath(getApiTailUrl("")).to(); @@ -1556,7 +1555,10 @@ public class GHRepository extends GHObject { */ 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.retrieve() + .withHeader("Accept", "application/vnd.github.VERSION.raw") + .withUrlPath(target) + .toStream(); } /** @@ -2280,7 +2282,6 @@ public class GHRepository extends GHObject { .method("POST") .with("title", title) .with("description", description) - .method("POST") .withUrlPath(getApiTailUrl("milestones")) .to(GHMilestone.class) .wrap(this); @@ -2302,7 +2303,6 @@ public class GHRepository extends GHObject { .method("POST") .with("title", title) .with("key", key) - .method("POST") .withUrlPath(getApiTailUrl("keys")) .to(GHDeployKey.class) .wrap(this); @@ -2372,10 +2372,9 @@ public class GHRepository extends GHObject { */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { return root.retrieve() - .method("POST") + .method("PUT") .with("subscribed", subscribed) .with("ignored", ignored) - .method("PUT") .withUrlPath(getApiTailUrl("subscription")) .to(GHSubscription.class) .wrapUp(this); @@ -2517,7 +2516,8 @@ public class GHRepository extends GHObject { .with("text", text) .with("mode", mode == null ? null : mode.toString()) .with("context", getFullName()) - .asStream("/markdown"), + .withUrlPath("/markdown") + .toStream(), "UTF-8"); } @@ -2628,8 +2628,11 @@ public class GHRepository extends GHObject { * the io exception */ public void setTopics(List topics) throws IOException { - Requester requester = root.retrieve().method("POST"); - requester.with("names", topics); - requester.method("PUT").withPreview(MERCY).withUrlPath(getApiTailUrl("topics")).to(); + root.retrieve() + .method("PUT") + .with("names", topics) + .withPreview(MERCY) + .withUrlPath(getApiTailUrl("topics")) + .to(); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 19b8bf812..9d6ea7065 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -318,7 +318,7 @@ public class GHRepositoryStatistics { // 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.retrieve().withUrlPath(getApiTailUrl("code_frequency")).toStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { @@ -460,7 +460,7 @@ public class GHRepositoryStatistics { 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.retrieve().withUrlPath(getApiTailUrl("punch_card")).toStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 40974660a..98ffb9058 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -177,10 +177,9 @@ public class GHThread extends GHObject { */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { return root.retrieve() - .method("POST") + .method("PUT") .with("subscribed", subscribed) .with("ignored", ignored) - .method("PUT") .withUrlPath(subscription_url) .to(GHSubscription.class) .wrapUp(root); diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index c712a2359..65b6369c1 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -33,7 +33,7 @@ public class GHTreeBuilder { GHTreeBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve().method("POST"); + req = repo.root.retrieve(); } /** diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 24c36be6d..60b2ae5d4 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -925,10 +925,7 @@ public class GitHub { * @see Documentation */ public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException { - Requester requester = retrieve().method("POST") - .with("scopes", scope) - .with("note", note) - .with("note_url", noteUrl); + Requester requester = retrieve().with("scopes", scope).with("note", note).with("note_url", noteUrl); return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); } @@ -961,10 +958,7 @@ public class GitHub { return createToken(scope, note, noteUrl); } catch (GHOTPRequiredException ex) { String OTPstring = OTP.get(); - Requester requester = retrieve().method("POST") - .with("scopes", scope) - .with("note", note) - .with("note_url", noteUrl); + Requester requester = retrieve().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").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); @@ -995,8 +989,7 @@ public class GitHub { List scopes, String note, String note_url) throws IOException { - Requester requester = retrieve().method("POST") - .with("client_secret", clientSecret) + Requester requester = retrieve().with("client_secret", clientSecret) .with("scopes", scopes) .with("note", note) .with("note_url", note_url); @@ -1356,7 +1349,8 @@ public class GitHub { retrieve().method("POST") .with(new ByteArrayInputStream(text.getBytes("UTF-8"))) .contentType("text/plain;charset=UTF-8") - .asStream("/markdown/raw"), + .withUrlPath("/markdown/raw") + .toStream(), "UTF-8"); } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 3a6581865..f3fdb04cc 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -500,26 +500,24 @@ class Requester { } /** - * 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 { + public int asHttpStatusCode() throws IOException { while (true) {// loop while API rate limit is hit - method("GET"); - setupConnection(root.getApiURL(tailApiUrl)); + setupConnection(root.getApiURL(urlPath)); try { return uc.getResponseCode(); } catch (IOException e) { handleApiError(e); } finally { - noteRateLimit(tailApiUrl); + noteRateLimit(urlPath); } } } @@ -527,22 +525,20 @@ class Requester { /** * 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 { + public InputStream toStream() throws IOException { while (true) {// loop while API rate limit is hit - setupConnection(root.getApiURL(tailApiUrl)); + setupConnection(root.getApiURL(urlPath)); try { return wrapStream(uc.getInputStream()); } catch (IOException e) { handleApiError(e); } finally { - noteRateLimit(tailApiUrl); + noteRateLimit(urlPath); } } } @@ -689,7 +685,9 @@ class Requester { * Every iterator call reports a new batch. */ Iterator asIterator(Class type, int pageSize) { - method("GET"); + if (method != "GET") { + throw new IllegalStateException("Request method \"GET\" is required for iterator."); + } if (pageSize != 0) args.add(new Entry("per_page", pageSize));