Commit 5f1b0a35 authored by Nick Albion's avatar Nick Albion

Added support for un/protectBranch

parent f26d72c9
......@@ -187,6 +187,16 @@ public class GitlabAPI {
return dispatch().with("body", body).to(tailUrl, GitlabNote.class);
}
public void protectBranch(GitlabProject project, String branchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/branches" + "/" + branchName + "/protect";
retrieve().method("PUT").to(tailUrl, Void.class);
}
public void unprotectBranch(GitlabProject project, String branchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/branches" + "/" + branchName + "/unprotect";
retrieve().method("PUT").to(tailUrl, Void.class);
}
private List<GitlabMergeRequest> fetchMergeRequests(String tailUrl) throws IOException {
GitlabMergeRequest[] mergeRequests = retrieve().to(tailUrl, GitlabMergeRequest[].class);
......
......@@ -113,6 +113,10 @@ public class GitlabHTTPRequestor {
if (hasOutput()) {
submitData(connection);
} else if( "PUT".equals(_method) ) {
// PUT requires Content-Length: 0 even when there is no body (eg: API for protecting a branch)
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);
}
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment