Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d5809e3

Browse filesBrowse files
committed
Simplification via enum handling in 'req.with'
1 parent 2440a67 commit d5809e3
Copy full SHA for d5809e3
Expand file treeCollapse file tree

9 files changed

+18
-24
lines changed

‎src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeployme
1212
this.repo = repo;
1313
this.deploymentId = deploymentId;
1414
this.builder = new Requester(repo.root);
15-
this.builder.with("state",state.toString().toLowerCase(Locale.ENGLISH));
15+
this.builder.with("state",state);
1616
}
1717

1818
public GHDeploymentStatusBuilder description(String description) {

‎src/main/java/org/kohsuke/github/GHIssueSearchBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHIssueSearchBuilder.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public GHIssueSearchBuilder isMerged() {
4242
}
4343

4444
public GHIssueSearchBuilder sort(Sort sort) {
45-
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
45+
req.with("sort",sort);
4646
return this;
4747
}
4848

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHMyself.java
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,15 @@ public PagedIterable<GHRepository> listRepositories(final int pageSize) {
159159
public PagedIterable<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
160160
return new PagedIterable<GHRepository>() {
161161
public PagedIterator<GHRepository> _iterator(int pageSize) {
162-
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos?per_page=" + pageSize +
163-
"&type=" + repoType.name().toLowerCase(Locale.ENGLISH), GHRepository[].class, pageSize)) {
162+
return new PagedIterator<GHRepository>(root.retrieve().with("type",repoType).asIterator("/user/repos", GHRepository[].class, pageSize)) {
164163
@Override
165164
protected void wrapUp(GHRepository[] page) {
166165
for (GHRepository c : page)
167166
c.wrap(root);
168167
}
169168
};
170169
}
171-
};
170+
}.withPageSize(pageSize);
172171
}
173172

174173
/**

‎src/main/java/org/kohsuke/github/GHOrganization.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHOrganization.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public enum Permission { ADMIN, PUSH, PULL }
175175
* Creates a new team and assigns the repositories.
176176
*/
177177
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
178-
Requester post = new Requester(root).with("name", name).with("permission", p.name().toLowerCase(Locale.ENGLISH));
178+
Requester post = new Requester(root).with("name", name).with("permission", p);
179179
List<String> repo_names = new ArrayList<String>();
180180
for (GHRepository r : repositories) {
181181
repo_names.add(r.getName());

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+9-14Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,10 @@ public List<GHIssue> getIssues(GHIssueState state) throws IOException {
228228

229229
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
230230
return Arrays.asList(GHIssue.wrap(root.retrieve()
231-
.to(getApiTailUrl(String.format("issues?state=%s&milestone=%s",
232-
state.toString().toLowerCase(Locale.ENGLISH),
233-
milestone == null ? "none" : "" + milestone.getNumber())),
234-
GHIssue[].class
235-
), this));
231+
.with("state", state)
232+
.with("milestone", milestone == null ? "none" : "" + milestone.getNumber())
233+
.to(getApiTailUrl("issues"),
234+
GHIssue[].class), this));
236235
}
237236

238237
/**
@@ -241,7 +240,7 @@ public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws
241240
public PagedIterable<GHIssue> listIssues(final GHIssueState state) {
242241
return new PagedIterable<GHIssue>() {
243242
public PagedIterator<GHIssue> _iterator(int pageSize) {
244-
return new PagedIterator<GHIssue>(root.retrieve().asIterator(getApiTailUrl("issues?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHIssue[].class, pageSize)) {
243+
return new PagedIterator<GHIssue>(root.retrieve().with("state",state).asIterator(getApiTailUrl("issues"), GHIssue[].class, pageSize)) {
245244
@Override
246245
protected void wrapUp(GHIssue[] page) {
247246
for (GHIssue c : page)
@@ -538,7 +537,7 @@ public void delete() throws IOException {
538537
/**
539538
* Sort orders for listing forks
540539
*/
541-
public static enum ForkSort { NEWEST, OLDEST, STARGAZERS }
540+
public enum ForkSort { NEWEST, OLDEST, STARGAZERS }
542541

543542
/**
544543
* Lists all the direct forks of this repository, sorted by
@@ -556,11 +555,7 @@ public PagedIterable<GHRepository> listForks() {
556555
public PagedIterable<GHRepository> listForks(final ForkSort sort) {
557556
return new PagedIterable<GHRepository>() {
558557
public PagedIterator<GHRepository> _iterator(int pageSize) {
559-
String sortParam = "";
560-
if (sort != null) {
561-
sortParam = "?sort=" + sort.toString().toLowerCase(Locale.ENGLISH);
562-
}
563-
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("forks" + sortParam), GHRepository[].class, pageSize)) {
558+
return new PagedIterator<GHRepository>(root.retrieve().with("sort",sort).asIterator(getApiTailUrl("forks"), GHRepository[].class, pageSize)) {
564559
@Override
565560
protected void wrapUp(GHRepository[] page) {
566561
for (GHRepository c : page) {
@@ -857,7 +852,7 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
857852
*/
858853
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException {
859854
return new Requester(root)
860-
.with("state", state.name().toLowerCase(Locale.ENGLISH))
855+
.with("state", state)
861856
.with("target_url", targetUrl)
862857
.with("description", description)
863858
.with("context", context)
@@ -1089,7 +1084,7 @@ public Map<Integer, GHMilestone> getMilestones() throws IOException {
10891084
public PagedIterable<GHMilestone> listMilestones(final GHIssueState state) {
10901085
return new PagedIterable<GHMilestone>() {
10911086
public PagedIterator<GHMilestone> _iterator(int pageSize) {
1092-
return new PagedIterator<GHMilestone>(root.retrieve().asIterator(getApiTailUrl("milestones?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHMilestone[].class, pageSize)) {
1087+
return new PagedIterator<GHMilestone>(root.retrieve().with("state",state).asIterator(getApiTailUrl("milestones"), GHMilestone[].class, pageSize)) {
10931088
@Override
10941089
protected void wrapUp(GHMilestone[] page) {
10951090
for (GHMilestone c : page)

‎src/main/java/org/kohsuke/github/GHRepositorySearchBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepositorySearchBuilder.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public GHRepositorySearchBuilder stars(String v) {
5858
}
5959

6060
public GHRepositorySearchBuilder sort(Sort sort) {
61-
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
61+
req.with("sort",sort);
6262
return this;
6363
}
6464

‎src/main/java/org/kohsuke/github/GHUserSearchBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHUserSearchBuilder.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public GHUserSearchBuilder followers(String v) {
5050
}
5151

5252
public GHUserSearchBuilder sort(Sort sort) {
53-
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
53+
req.with("sort",sort);
5454
return this;
5555
}
5656

‎src/main/java/org/kohsuke/github/PagedIterable.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/PagedIterable.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public abstract class PagedIterable<T> implements Iterable<T> {
2323
* <p>
2424
* When set to non-zero, each API call will retrieve this many entries.
2525
*/
26-
public PagedIterable<T> withPageSize(int size) throws IOException {
26+
public PagedIterable<T> withPageSize(int size) {
2727
this.size = size;
2828
return this;
2929
}

‎src/main/java/org/kohsuke/github/PagedSearchIterable.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/PagedSearchIterable.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public abstract class PagedSearchIterable<T> extends PagedIterable<T> {
2525
}
2626

2727
@Override
28-
public PagedSearchIterable<T> withPageSize(int size) throws IOException {
28+
public PagedSearchIterable<T> withPageSize(int size) {
2929
return (PagedSearchIterable<T>)super.withPageSize(size);
3030
}
3131

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.