Skip to content

Commit

Permalink
Merge pull request #614 from bitwiseman/task/requester-cleanup
Browse files Browse the repository at this point in the history
Clean up Requester interface a bit
  • Loading branch information
bitwiseman authored Nov 15, 2019
2 parents d3564a9 + 37d7cfa commit c174be3
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 131 deletions.
11 changes: 10 additions & 1 deletion src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -23,7 +24,7 @@ public class GHAppCreateTokenBuilder {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = new Requester(root);
this.builder.withPermissions("permissions", permissions);
withPermissions(builder, permissions);
}

/**
Expand Down Expand Up @@ -58,4 +59,12 @@ public GHAppInstallationToken create() throws IOException {
.wrapUp(root);
}

private static Requester withPermissions(Requester builder, Map<String, GHPermissionType> value) {
Map<String, String> retMap = new HashMap<String, String>();
for (Map.Entry<String, GHPermissionType> entry : value.entrySet()) {
retMap.put(entry.getKey(), Requester.transformEnum(entry.getValue()));
}
return builder.with("permissions", retMap);
}

}
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 {
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
new Requester(root).with(key, value).method("PATCH").to(getApiRoute());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHCommitBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public GHCommitBuilder parent(String parent) {
* @return the gh commit builder
*/
public GHCommitBuilder author(String name, String email, Date date) {
req._with("author", new UserInfo(name, email, date));
req.with("author", new UserInfo(name, email, date));
return this;
}

Expand All @@ -101,7 +101,7 @@ public GHCommitBuilder author(String name, String email, Date date) {
* @return the gh commit builder
*/
public GHCommitBuilder committer(String name, String email, Date date) {
req._with("committer", new UserInfo(name, email, date));
req.with("committer", new UserInfo(name, email, date));
return this;
}

Expand All @@ -117,7 +117,7 @@ private String getApiTail() {
* the io exception
*/
public GHCommit create() throws IOException {
req._with("parents", parents);
req.with("parents", parents);
return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHGistBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public GHGistBuilder file(String fileName, String content) {
* if Gist cannot be created.
*/
public GHGist create() throws IOException {
req._with("files", files);
req.with("files", files);
return req.to("/gists", GHGist.class).wrapUp(root);
}
}
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 @@ -95,7 +95,7 @@ public GHGistUpdater description(String desc) {
* the io exception
*/
public GHGist update() throws IOException {
builder._with("files", files);
builder.with("files", files);
return builder.method("PATCH").to(base.getApiTailUrl(""), GHGist.class).wrap(base.owner);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public GHHook createHook(String name, Map<String, String> config, Collection<GHE
ea.add(e.symbol());
}

GHHook hook = new Requester(root).with("name", name).with("active", active)._with("config", config)
._with("events", ea).to(collection(), clazz());
GHHook hook = new Requester(root).with("name", name).with("active", active).with("config", config)
.with("events", ea).to(collection(), clazz());

return wrap(hook);
}
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ public GHIssueComment comment(String message) throws IOException {
}

private void edit(String key, Object value) throws IOException {
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
new Requester(root).with(key, value).method("PATCH").to(getApiRoute());
}

private void editIssue(String key, Object value) throws IOException {
new Requester(root)._with(key, value).method("PATCH").to(getIssuesApiRoute());
new Requester(root).with(key, value).method("PATCH").to(getIssuesApiRoute());
}

/**
Expand Down Expand Up @@ -482,7 +482,8 @@ public void addAssignees(GHUser... assignees) throws IOException {
* the io exception
*/
public void addAssignees(Collection<GHUser> assignees) throws IOException {
root.retrieve().method("POST").withLogins(ASSIGNEES, assignees).to(getIssuesApiRoute() + "/assignees", this);
root.retrieve().method("POST").with(ASSIGNEES, getLogins(assignees)).to(getIssuesApiRoute() + "/assignees",
this);
}

/**
Expand All @@ -506,7 +507,7 @@ public void setAssignees(GHUser... assignees) throws IOException {
* the io exception
*/
public void setAssignees(Collection<GHUser> assignees) throws IOException {
new Requester(root).withLogins(ASSIGNEES, assignees).method("PATCH").to(getIssuesApiRoute());
new Requester(root).with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute());
}

/**
Expand All @@ -530,7 +531,7 @@ public void removeAssignees(GHUser... assignees) throws IOException {
* the io exception
*/
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
root.retrieve().method("DELETE").withLogins(ASSIGNEES, assignees).inBody()
root.retrieve().method("DELETE").with(ASSIGNEES, getLogins(assignees)).inBody()
.to(getIssuesApiRoute() + "/assignees", this);
}

Expand Down Expand Up @@ -677,6 +678,14 @@ public URL getUrl() {
}
}

protected static List<String> getLogins(Collection<GHUser> users) {
List<String> names = new ArrayList<String>(users.size());
for (GHUser a : users) {
names.add(a.getLogin());
}
return names;
}

/**
* Lists events for this issue. See https://developer.github.com/v3/issues/events/
*
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 {
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
new Requester(root).with(key, value).method("PATCH").to(getApiRoute());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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());
new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHProjectCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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());
new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHProjectColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S
* the io exception
*/
public void requestReviewers(List<GHUser> reviewers) throws IOException {
new Requester(root).method("POST").withLogins("reviewers", reviewers).to(getApiRoute() + REQUEST_REVIEWERS);
new Requester(root).method("POST").with("reviewers", getLogins(reviewers))
.to(getApiRoute() + REQUEST_REVIEWERS);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public GHPullRequestReviewBuilder comment(String body, String path, int position
* the io exception
*/
public GHPullRequestReview create() throws IOException {
return builder.method("POST")._with("comments", comments)
return builder.method("POST").with("comments", comments)
.to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class).wrapUp(pr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private String getApiTail() {
* the io exception
*/
public GHTree create() throws IOException {
req._with("tree", treeEntries);
req.with("tree", treeEntries);
return req.method("POST").to(getApiTail(), GHTree.class).wrap(repo);
}
}
Loading

0 comments on commit c174be3

Please sign in to comment.