Make withUrlPath() overwrite instead of append

I had some ideas about having multiple calls to  apend to build up paths,
but it turns out that idea is pretty bad.  `with*()` methods should
overwrite when called for the same field.

If we want to create and , we can do that later.
This commit is contained in:
Liam Newman
2020-07-27 13:12:41 -07:00
parent 9c7de767e9
commit fb1adbd1ef
2 changed files with 7 additions and 10 deletions

View File

@@ -980,12 +980,13 @@ public class GHRepository extends GHObject {
private void modifyCollaborators(@NonNull Collection<GHUser> users,
@NonNull String method,
@CheckForNull GHOrganization.Permission permission) throws IOException {
Requester requester = root.createRequest().method(method);
if (permission != null) {
requester = requester.with("permission", permission).inBody();
}
// Make sure that the users collection doesn't have any duplicates
for (GHUser user : new LinkedHashSet<GHUser>(users)) {
Requester requester = root.createRequest().method(method);
if (permission != null) {
requester = requester.with("permission", permission).inBody();
}
requester.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
}
}

View File

@@ -671,13 +671,9 @@ class GitHubRequest {
tailUrlPath += "/" + String.join("/", urlPathItems);
}
if (this.urlPath.endsWith("/")) {
tailUrlPath = StringUtils.stripStart(tailUrlPath, "/");
} else {
tailUrlPath = StringUtils.prependIfMissing(tailUrlPath, "/");
}
tailUrlPath = StringUtils.prependIfMissing(tailUrlPath, "/");
this.urlPath += urlPathEncode(tailUrlPath);
this.urlPath = urlPathEncode(tailUrlPath);
return (B) this;
}