Remove String.format from GitHub issues URL builder
@@ -113,31 +113,30 @@ class GitHubTicketFetcher {
private static class GitHubIssuesBuilder {
private final String apiUrl;
- private final String readOnlyAuthToken;
private final String repository;
- private String state;
- private String filter;
- private String direction;
- private String labels;
+
+ private Map<String, String> parameters;
GitHubIssuesBuilder(String apiUrl, String repository, String readOnlyAuthToken) {
this.apiUrl = apiUrl;
this.repository = repository;
- this.readOnlyAuthToken = readOnlyAuthToken;
+
+ parameters = new HashMap<String, String>();
+ parameters.put("access_token", readOnlyAuthToken);
}
GitHubIssuesBuilder state(String state) {
- this.state = state;
+ parameters.put("state", state);
return this;
}
GitHubIssuesBuilder filter(String filter) {
- this.filter = filter;
+ parameters.put("filter", filter);
return this;
}
GitHubIssuesBuilder direction(String direction) {
- this.direction = direction;
+ parameters.put("direction", direction);
return this;
}
@@ -146,22 +145,21 @@ class GitHubTicketFetcher {
* Empty string is ok and means that we are interested in all issues, regardless of the label.
*/
public GitHubIssuesBuilder labels(String labels) {
- this.labels = labels;
+ parameters.put("labels", labels);
return this;
}
GitHubIssues browse() {
// see API doc: https://developer.github.com/v3/issues/
- String nextPageUrl = String.format("%s%s%s%s%s%s%s",
- apiUrl + "/repos/" + repository + "/issues",
- "?access_token=" + readOnlyAuthToken,
- state == null ? "" : "&state=" + state,
- filter == null ? "" : "&filter=" + filter,
- "&labels=" + labels,
- direction == null ? "" : "&direction=" + direction,
- "&page=1"
- );
- return new GitHubIssues(nextPageUrl);
+ StringBuilder urlBuilder = new StringBuilder(apiUrl)
+ .append("/repos/").append(repository)
+ .append("/issues?page=1");
+
+ for (Map.Entry<String, String> parameter : parameters.entrySet()) {
+ urlBuilder.append("&").append(parameter.getKey()).append("=").append(parameter.getValue());
+ }
+
+ return new GitHubIssues(urlBuilder.toString());
}
}
}
