Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
47883737
Commit
47883737
authored
Jul 25, 2018
by
Greg Messner
Browse files
Added getOptionalFile() and getOptionalFileInfo() methods (#224).
parent
19094fcd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/RepositoryFileApi.java
View file @
47883737
...
...
@@ -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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment