Commit 47883737 authored by Greg Messner's avatar Greg Messner
Browse files

Added getOptionalFile() and getOptionalFileInfo() methods (#224).

parent 19094fcd
......@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Optional;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
......@@ -22,6 +23,26 @@ public class RepositoryFileApi extends AbstractApi {
super(gitLabApi);
}
/**
* Get an Optional instance with the value holding information on a file in the repository.
* Allows you to receive information about file in repository like name, size.
* Only works with GitLab 11.1.0+, value will be an empty object for earlier versions of GitLab.
*
* HEAD /projects/:id/repository/files
*
* @param projectIdOrPath the id, path of the project, or a Project instance holding the project ID or path
* @param filePath (required) - Full path to the file. Ex. lib/class.rb
* @param ref (required) - The name of branch, tag or commit
* @return an Optional instance with the specified RepositoryFile as a value
*/
public Optional<RepositoryFile> getOptionalFileInfo(Object projectIdOrPath, String filePath, String ref) {
try {
return (Optional.ofNullable(getFileInfo(projectIdOrPath, filePath, ref)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Get information on a file in the repository. Allows you to receive information about file in repository like name, size.
* Only works with GitLab 11.1.0+, returns an empty object for earlier versions of GitLab.
......@@ -57,6 +78,26 @@ public class RepositoryFileApi extends AbstractApi {
return (file);
}
/**
* Get an Optional instance with the value holding information and content for a file in the repository.
* Allows you to receive information about file in repository like name, size, and content.
* Only works with GitLab 11.1.0+, value will be an empty object for earlier versions of GitLab.
*
* HEAD /projects/:id/repository/files
*
* @param projectIdOrPath the id, path of the project, or a Project instance holding the project ID or path
* @param filePath (required) - Full path to the file. Ex. lib/class.rb
* @param ref (required) - The name of branch, tag or commit
* @return an Optional instance with the specified RepositoryFile as a value
*/
public Optional<RepositoryFile> getOptionalFile(Object projectIdOrPath, String filePath, String ref) {
try {
return (Optional.ofNullable(getFile(projectIdOrPath, filePath, ref, true)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Get file from repository. Allows you to receive information about file in repository like name, size, content.
* Note that file content is Base64 encoded.
......
Supports Markdown
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