Skip to content

Commit 133623a

Browse files
committed
Fixed PUT with no entity (#101).
1 parent 0e33be2 commit 133623a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/main/java/org/gitlab4j/api/GitLabApiClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@ protected Response put(MultivaluedMap<String, String> queryParams, Object... pat
403403
* @return a ClientResponse instance with the data returned from the endpoint
404404
*/
405405
protected Response put(MultivaluedMap<String, String> queryParams, URL url) {
406-
return (invocation(url, null).put(Entity.entity(queryParams, MediaType.APPLICATION_FORM_URLENCODED_TYPE)));
406+
if (queryParams == null || queryParams.isEmpty()) {
407+
Entity<?> empty = Entity.text("");
408+
return (invocation(url, null).put(empty));
409+
} else {
410+
return (invocation(url, null).put(Entity.entity(queryParams, MediaType.APPLICATION_FORM_URLENCODED_TYPE)));
411+
}
407412
}
408413

409414
/**

src/main/java/org/gitlab4j/api/RepositoryApi.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ public Branch createBranch(Integer projectId, String branchName, String ref) thr
112112

113113

114114
/**
115-
* Delete a single project repository branch. This is an idempotent function,
116-
* protecting an already protected repository branch will not produce an error.
115+
* Delete a single project repository branch.
117116
*
118117
* DELETE /projects/:id/repository/branches/:branch
119118
*
@@ -138,7 +137,7 @@ public void deleteBranch(Integer projectId, String branchName) throws GitLabApiE
138137
* @throws GitLabApiException if any exception occurs
139138
*/
140139
public Branch protectBranch(Integer projectId, String branchName) throws GitLabApiException {
141-
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "protect");
140+
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", urlEncode(branchName), "protect");
142141
return (response.readEntity(Branch.class));
143142
}
144143

@@ -154,7 +153,7 @@ public Branch protectBranch(Integer projectId, String branchName) throws GitLabA
154153
* @throws GitLabApiException if any exception occurs
155154
*/
156155
public Branch unprotectBranch(Integer projectId, String branchName) throws GitLabApiException {
157-
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "unprotect");
156+
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", urlEncode(branchName), "unprotect");
158157
return (response.readEntity(Branch.class));
159158
}
160159

0 commit comments

Comments
 (0)