Skip to content

Commit

Permalink
Clean up request method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Dec 16, 2019
1 parent 0f94828 commit 6ba9a3d
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GHAppCreateTokenBuilder {
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = root.retrieve().method("POST");
this.builder = root.retrieve();
withPermissions(builder, permissions);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHAsset.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() {
}

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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHBlobBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GHBlobBuilder {

GHBlobBuilder(GHRepository repo) {
this.repo = repo;
req = repo.root.retrieve().method("POST");
req = repo.root.retrieve();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHBranchProtection.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public RequiredReviews getRequiredReviews() {
@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;
}

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ GHBranchProtection wrap(GHBranch branch) {
}

private Requester requester() {
return root.retrieve().method("POST").withPreview(ZZZAX);
return root.retrieve().withPreview(ZZZAX);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ private StatusChecks getStatusChecks() {
}

private Requester requester() {
return branch.getRoot().retrieve().method("POST").withPreview(LUKE_CAGE);
return branch.getRoot().retrieve().withPreview(LUKE_CAGE);
}

private static class Restrictions {
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/kohsuke/github/GHCommitComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ public GHCommit getCommit() throws IOException {
* 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHGist.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.retrieve().withUrlPath(getApiTailUrl("star")).asHttpStatusCode() / 100 == 2;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHGistUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ public GHIssueComment comment(String message) throws IOException {
}

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();
}

/**
Expand Down Expand Up @@ -520,12 +520,7 @@ public void setAssignees(GHUser... assignees) throws IOException {
* the io exception
*/
public void setAssignees(Collection<GHUser> 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();
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/kohsuke/github/GHIssueComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ public GHCommentAuthorAssociation getAuthorAssociation() {
* 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHMilestone.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void delete() throws IOException {
}

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();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/kohsuke/github/GHNotificationStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public GHNotificationStream nonBlocking(boolean v) {
public Iterator<GHThread> iterator() {
// capture the configuration setting here
final Requester req = root.retrieve()
.method("GET")
.with("all", all)
.with("participating", participating)
.with("since", since);
Expand Down Expand Up @@ -236,7 +235,7 @@ public void markAsRead(long timestamp) throws IOException {
final Requester req = root.retrieve().method("PUT");
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];
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public GHTeam createTeam(String name, Permission p, Collection<GHRepository> rep
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);
}

/**
Expand Down Expand Up @@ -438,7 +438,7 @@ public GHTeam createTeam(String name, Collection<GHRepository> repositories) thr
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);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/kohsuke/github/GHProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ public GHProject wrap(GitHub root) {

private void edit(String key, Object value) throws IOException {
root.retrieve()
.method("POST")
.method("PATCH")
.withPreview(INERTIA)
.with(key, value)
.method("PATCH")
.withUrlPath(getApiRoute())
.to();
}
Expand Down Expand Up @@ -276,7 +275,7 @@ public void setPublic(boolean isPublic) throws IOException {
* 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();
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/kohsuke/github/GHProjectCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ public void setArchived(boolean archived) throws IOException {

private void edit(String key, Object value) throws IOException {
root.retrieve()
.method("POST")
.method("PATCH")
.withPreview(INERTIA)
.with(key, value)
.method("PATCH")
.withUrlPath(getApiRoute())
.to();
}
Expand All @@ -223,6 +222,6 @@ protected String getApiRoute() {
* 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();
}
}
10 changes: 2 additions & 8 deletions src/main/java/org/kohsuke/github/GHProjectColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ public void setName(String name) throws IOException {
}

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();
}

/**
Expand All @@ -131,7 +125,7 @@ protected String getApiRoute() {
* 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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public enum MergeMethod {

private void fetchIssue() throws IOException {
if (!fetchedIssueDetails) {
root.retrieve().method("GET").withUrlPath(getIssuesApiRoute()).to(this);
root.retrieve().withUrlPath(getIssuesApiRoute()).to(this);
fetchedIssueDetails = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/kohsuke/github/GHRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ public void updateTo(String sha) throws IOException {
*/
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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy
* the io exception
*/
public List<GHAsset> 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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHReleaseUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ public GHRef createRef(String name, String sha) throws IOException {
.method("POST")
.with("ref", name)
.with("sha", sha)
.method("POST")
.withUrlPath(getApiTailUrl("git/refs"))
.to(GHRef.class)
.wrap(root);
Expand Down Expand Up @@ -764,7 +763,7 @@ public PagedIterable<GHUser> 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.retrieve().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).asHttpStatusCode() / 100 == 2;
}

/**
Expand Down Expand Up @@ -901,7 +900,7 @@ public void setEmailServiceHook(String address) throws IOException {
}

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();
Expand Down Expand Up @@ -1556,7 +1555,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.retrieve()
.withHeader("Accept", "application/vnd.github.VERSION.raw")
.withUrlPath(target)
.toStream();
}

/**
Expand Down Expand Up @@ -2280,7 +2282,6 @@ public GHMilestone createMilestone(String title, String description) throws IOEx
.method("POST")
.with("title", title)
.with("description", description)
.method("POST")
.withUrlPath(getApiTailUrl("milestones"))
.to(GHMilestone.class)
.wrap(this);
Expand All @@ -2302,7 +2303,6 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException {
.method("POST")
.with("title", title)
.with("key", key)
.method("POST")
.withUrlPath(getApiTailUrl("keys"))
.to(GHDeployKey.class)
.wrap(this);
Expand Down Expand Up @@ -2372,10 +2372,9 @@ public GHRepository getParent() throws IOException {
*/
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);
Expand Down Expand Up @@ -2517,7 +2516,8 @@ public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException
.with("text", text)
.with("mode", mode == null ? null : mode.toString())
.with("context", getFullName())
.asStream("/markdown"),
.withUrlPath("/markdown")
.toStream(),
"UTF-8");
}

Expand Down Expand Up @@ -2628,8 +2628,11 @@ public List<String> listTopics() throws IOException {
* the io exception
*/
public void setTopics(List<String> 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();
}
}
Loading

0 comments on commit 6ba9a3d

Please sign in to comment.