Commit cf4bd19f authored by Jean-Christophe Sirot's avatar Jean-Christophe Sirot Committed by Tim Olshansky

Repository file create update and delete support (#215)

* Add create/update/delete Repository files

* Fix create/update verb
parent 8c8c1bb9
......@@ -1458,6 +1458,72 @@ public class GitlabAPI {
return retrieve().to(tailUrl, GitlabRepositoryFile.class);
}
/**
* Creates a new file in the repository
*
* @param project The Project
* @param path The file path inside the repository
* @param branchName The name of a repository branch
* @param commitMsg The commit message
* @param content The base64 encoded content of the file
* @throws IOException on gitlab api call error
*/
public GitlabSimpleRepositoryFile createRepositoryFile(GitlabProject project, String path, String branchName, String commitMsg, String content) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/files";
GitlabHTTPRequestor requestor = dispatch();
return requestor
.with("file_path", sanitizePath(path))
.with("branch_name", branchName)
.with("encoding", "base64")
.with("commit_message", commitMsg)
.with("content", content)
.to(tailUrl, GitlabSimpleRepositoryFile.class);
}
/**
* Updates the content of an existing file in the repository
*
* @param project The Project
* @param path The file path inside the repository
* @param branchName The name of a repository branch
* @param commitMsg The commit message
* @param content The base64 encoded content of the file
* @throws IOException on gitlab api call error
*/
public GitlabSimpleRepositoryFile updateRepositoryFile(GitlabProject project, String path, String branchName, String commitMsg, String content) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/files";
GitlabHTTPRequestor requestor = retrieve().method("PUT");
return requestor
.with("file_path", sanitizePath(path))
.with("branch_name", branchName)
.with("encoding", "base64")
.with("commit_message", commitMsg)
.with("content", content)
.to(tailUrl, GitlabSimpleRepositoryFile.class);
}
/**
* Deletes an existing file in the repository
*
* @param project The Project
* @param path The file path inside the repository
* @param branchName The name of a repository branch
* @param commitMsg The commit message
* @throws IOException on gitlab api call error
*/
public GitlabSimpleRepositoryFile deleteRepositoryFile(GitlabProject project, String path, String branchName, String commitMsg) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/files";
GitlabHTTPRequestor requestor = retrieve().method("DELETE");
return requestor
.with("file_path", sanitizePath(path))
.with("branch_name", branchName)
.with("commit_message", commitMsg)
.to(tailUrl, GitlabSimpleRepositoryFile.class);
}
/**
* Update a Merge Request Note
*
......
package org.gitlab.api.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabSimpleRepositoryFile {
/*
"file_name": "app/project.rb",
"branch_name": "master"
*/
@JsonProperty("file_name")
private String fileName;
@JsonProperty("branch_name")
private String branchName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getBranchName() {
return branchName;
}
public void setBranchName(String branchName) {
this.branchName = branchName;
}
}
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