Package org.gitlab4j.api
Class RepositoryFileApi
- java.lang.Object
-
- org.gitlab4j.api.AbstractApi
-
- org.gitlab4j.api.RepositoryFileApi
-
- All Implemented Interfaces:
Constants
public class RepositoryFileApi extends AbstractApi
This class provides an entry point to all the GitLab API repository files calls. See Repository Files API at GitLab for more information.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gitlab4j.api.Constants
Constants.ActionType, Constants.ApplicationScope, Constants.ArchiveFormat, Constants.AutoDevopsDeployStrategy, Constants.BuildGitStrategy, Constants.CommitBuildState, Constants.ContributorOrderBy, Constants.DeploymentOrderBy, Constants.DeploymentStatus, Constants.DeployTokenScope, Constants.Encoding, Constants.EpicOrderBy, Constants.EventScope, Constants.GroupOrderBy, Constants.GroupSearchScope, Constants.ImpersonationState, Constants.IssueOrderBy, Constants.IssueScope, Constants.IssueState, Constants.JobScope, Constants.LineType, Constants.MergeRequestOrderBy, Constants.MergeRequestScope, Constants.MergeRequestSearchIn, Constants.MergeRequestState, Constants.MilestoneState, Constants.PackageOrderBy, Constants.PackageStatus, Constants.PipelineOrderBy, Constants.PipelineScope, Constants.ProjectAccessTokenScope, Constants.ProjectOrderBy, Constants.ProjectSearchScope, Constants.SearchScope, Constants.SortOrder, Constants.SquashOption, Constants.StateEvent, Constants.TagOrderBy, Constants.TargetType, Constants.TodoAction, Constants.TodoState, Constants.TodoType, Constants.TokenType
-
-
Field Summary
-
Fields inherited from class org.gitlab4j.api.AbstractApi
gitLabApi
-
Fields inherited from interface org.gitlab4j.api.Constants
NEXT_PAGE_HEADER, PAGE_HEADER, PAGE_PARAM, PER_PAGE, PER_PAGE_PARAM, PREV_PAGE_HEADER, TOTAL_HEADER, TOTAL_PAGES_HEADER
-
-
Constructor Summary
Constructors Constructor Description RepositoryFileApi(GitLabApi gitLabApi)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RepositoryFileResponse
createFile(java.lang.Object projectIdOrPath, RepositoryFile file, java.lang.String branchName, java.lang.String commitMessage)
Create new file in repositoryRepositoryFileResponse
createFile(RepositoryFile file, java.lang.Long projectId, java.lang.String branchName, java.lang.String commitMessage)
Deprecated.Will be removed in version 6.0, replaced bycreateFile(Object, RepositoryFile, String, String)
protected jakarta.ws.rs.core.Form
createForm(RepositoryFile file, java.lang.String branchName, java.lang.String commitMessage)
Gets the query params based on the API version.void
deleteFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String branchName, java.lang.String commitMessage)
Delete existing file in repositoryvoid
deleteFile(java.lang.String filePath, java.lang.Long projectId, java.lang.String branchName, java.lang.String commitMessage)
Deprecated.Will be removed in version 6.0, replaced bydeleteFile(Object, String, String, String)
java.util.List<Blame>
getBlame(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
Get a List of file blame from repository.Pager<Blame>
getBlame(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref, int itemsPerPage)
Get a Pager of file blame from repository.java.util.stream.Stream<Blame>
getBlameStream(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
Get a Stream of file blame from repository.RepositoryFile
getFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
Get file from repository.RepositoryFile
getFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref, boolean includeContent)
Get file from repository.RepositoryFile
getFile(java.lang.String filePath, java.lang.Long projectId, java.lang.String ref)
Deprecated.Will be removed in version 6.0, replaced bygetFile(Object, String, String)
RepositoryFile
getFileInfo(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
Get information on a file in the repository.protected RepositoryFile
getFileV3(java.lang.String filePath, java.lang.Long projectId, java.lang.String ref)
Deprecated.Will be removed in version 6.0java.util.Optional<RepositoryFile>
getOptionalFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
Get an Optional instance with the value holding information and content for a file in the repository.java.util.Optional<RepositoryFile>
getOptionalFileInfo(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
Get an Optional instance with the value holding information on a file in the repository.java.io.InputStream
getRawFile(java.lang.Object projectIdOrPath, java.lang.String ref, java.lang.String filepath)
Get the raw file contents for a file by commit sha and path.java.io.File
getRawFile(java.lang.Object projectIdOrPath, java.lang.String commitOrBranchName, java.lang.String filepath, java.io.File directory)
Get the raw file for the file by commit sha and path.RepositoryFileResponse
updateFile(java.lang.Object projectIdOrPath, RepositoryFile file, java.lang.String branchName, java.lang.String commitMessage)
Update existing file in repositoryRepositoryFileResponse
updateFile(RepositoryFile file, java.lang.Long projectId, java.lang.String branchName, java.lang.String commitMessage)
Deprecated.Will be removed in version 6.0, replaced byupdateFile(Object, RepositoryFile, String, String)
-
Methods inherited from class org.gitlab4j.api.AbstractApi
addFormParam, addFormParam, delete, delete, get, get, getApiClient, getApiVersion, getDefaultPerPage, getDefaultPerPageParam, getDefaultPerPageParam, getGroupIdOrPath, getLabelIdOrName, getPageQueryParams, getPageQueryParams, getPerPageQueryParam, getProjectIdOrPath, getUserIdOrUsername, getWithAccepts, handle, head, isApiVersion, patch, patch, post, post, post, post, post, put, put, put, putUpload, putUpload, putWithFormData, upload, upload, upload, upload, urlEncode, validate
-
-
-
-
Constructor Detail
-
RepositoryFileApi
public RepositoryFileApi(GitLabApi gitLabApi)
-
-
Method Detail
-
getOptionalFileInfo
public java.util.Optional<RepositoryFile> getOptionalFileInfo(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
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.GitLab Endpoint: HEAD /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfilePath
- (required) - Full path to the file. Ex. lib/class.rbref
- (required) - The name of branch, tag or commit- Returns:
- an Optional instance with the specified RepositoryFile as a value
- Since:
- GitLab-11.1.0
-
getFileInfo
public RepositoryFile getFileInfo(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref) throws GitLabApiException
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.GitLab Endpoint: HEAD /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfilePath
- (required) - Full path to the file. Ex. lib/class.rbref
- (required) - The name of branch, tag or commit- Returns:
- a RepositoryFile instance with the file info
- Throws:
GitLabApiException
- if any exception occurs- Since:
- GitLab-11.1.0
-
getOptionalFile
public java.util.Optional<RepositoryFile> getOptionalFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref)
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.GitLab Endpoint: HEAD /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfilePath
- (required) - Full path to the file. Ex. lib/class.rbref
- (required) - The name of branch, tag or commit- Returns:
- an Optional instance with the specified RepositoryFile as a value
-
getFile
public RepositoryFile getFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref) throws GitLabApiException
Get file from repository. Allows you to receive information about file in repository like name, size, content. Note that file content is Base64 encoded.GitLab Endpoint: GET /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfilePath
- (required) - Full path to the file. Ex. lib/class.rbref
- (required) - The name of branch, tag or commit- Returns:
- a RepositoryFile instance with the file info and file content
- Throws:
GitLabApiException
- if any exception occurs
-
getFile
@Deprecated public RepositoryFile getFile(java.lang.String filePath, java.lang.Long projectId, java.lang.String ref) throws GitLabApiException
Deprecated.Will be removed in version 6.0, replaced bygetFile(Object, String, String)
Get file from repository. Allows you to receive information about file in repository like name, size, content. Note that file content is Base64 encoded.GitLab Endpoint: GET /projects/:id/repository/files
- Parameters:
filePath
- (required) - Full path to the file. Ex. lib/class.rbprojectId
- (required) - the project IDref
- (required) - The name of branch, tag or commit- Returns:
- a RepositoryFile instance with the file info and file content
- Throws:
GitLabApiException
- if any exception occurs
-
getFile
public RepositoryFile getFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref, boolean includeContent) throws GitLabApiException
Get file from repository. Allows you to receive information about file in repository like name, size, and optionally content. Note that file content is Base64 encoded.GitLab Endpoint: GET /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfilePath
- (required) - Full path to the file. Ex. lib/class.rbref
- (required) - The name of branch, tag or commitincludeContent
- if true will also fetch file content- Returns:
- a RepositoryFile instance with the file info and optionally file content
- Throws:
GitLabApiException
- if any exception occurs
-
getFileV3
@Deprecated protected RepositoryFile getFileV3(java.lang.String filePath, java.lang.Long projectId, java.lang.String ref) throws GitLabApiException
Deprecated.Will be removed in version 6.0Get file from repository. Allows you to receive information about file in repository like name, size, content. Note that file content is Base64 encoded.GitLab Endpoint: GET /projects/:id/repository/files
- Parameters:
filePath
- (required) - Full path to new file. Ex. lib/class.rbprojectId
- (required) - the project IDref
- (required) - The name of branch, tag or commit- Returns:
- a RepositoryFile instance with the file info
- Throws:
GitLabApiException
- if any exception occurs
-
createFile
public RepositoryFileResponse createFile(java.lang.Object projectIdOrPath, RepositoryFile file, java.lang.String branchName, java.lang.String commitMessage) throws GitLabApiException
Create new file in repository
file_path (required) - Full path to new file. Ex. lib/class.rb branch_name (required) - The name of branch encoding (optional) - 'text' or 'base64'. Text is default. content (required) - File content commit_message (required) - Commit messageGitLab Endpoint: POST /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfile
- a ReposityoryFile instance with info for the file to createbranchName
- the name of branchcommitMessage
- the commit message- Returns:
- a RepositoryFile instance with the created file info
- Throws:
GitLabApiException
- if any exception occurs
-
createFile
@Deprecated public RepositoryFileResponse createFile(RepositoryFile file, java.lang.Long projectId, java.lang.String branchName, java.lang.String commitMessage) throws GitLabApiException
Deprecated.Will be removed in version 6.0, replaced bycreateFile(Object, RepositoryFile, String, String)
Create new file in repository
file_path (required) - Full path to new file. Ex. lib/class.rb branch_name (required) - The name of branch encoding (optional) - 'text' or 'base64'. Text is default. content (required) - File content commit_message (required) - Commit messageGitLab Endpoint: POST /projects/:id/repository/files
- Parameters:
file
- a ReposityoryFile instance with info for the file to createprojectId
- the project IDbranchName
- the name of branchcommitMessage
- the commit message- Returns:
- a RepositoryFile instance with the created file info
- Throws:
GitLabApiException
- if any exception occurs
-
updateFile
public RepositoryFileResponse updateFile(java.lang.Object projectIdOrPath, RepositoryFile file, java.lang.String branchName, java.lang.String commitMessage) throws GitLabApiException
Update existing file in repository
file_path (required) - Full path to new file. Ex. lib/class.rb branch_name (required) - The name of branch encoding (optional) - 'text' or 'base64'. Text is default. content (required) - File content commit_message (required) - Commit messageGitLab Endpoint: PUT /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfile
- a ReposityoryFile instance with info for the file to updatebranchName
- the name of branchcommitMessage
- the commit message- Returns:
- a RepositoryFile instance with the updated file info
- Throws:
GitLabApiException
- if any exception occurs
-
updateFile
@Deprecated public RepositoryFileResponse updateFile(RepositoryFile file, java.lang.Long projectId, java.lang.String branchName, java.lang.String commitMessage) throws GitLabApiException
Deprecated.Will be removed in version 6.0, replaced byupdateFile(Object, RepositoryFile, String, String)
Update existing file in repository
file_path (required) - Full path to new file. Ex. lib/class.rb branch_name (required) - The name of branch encoding (optional) - 'text' or 'base64'. Text is default. content (required) - File content commit_message (required) - Commit messageGitLab Endpoint: PUT /projects/:id/repository/files
- Parameters:
file
- a ReposityoryFile instance with info for the file to updateprojectId
- the project IDbranchName
- the name of branchcommitMessage
- the commit message- Returns:
- a RepositoryFile instance with the updated file info
- Throws:
GitLabApiException
- if any exception occurs
-
deleteFile
public void deleteFile(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String branchName, java.lang.String commitMessage) throws GitLabApiException
Delete existing file in repository
file_path (required) - Full path to file. Ex. lib/class.rb branch_name (required) - The name of branch commit_message (required) - Commit messageGitLab Endpoint: DELETE /projects/:id/repository/files
- Parameters:
projectIdOrPath
- the id, path of the project, or a Project instance holding the project ID or pathfilePath
- full path to new file. Ex. lib/class.rbbranchName
- the name of branchcommitMessage
- the commit message- Throws:
GitLabApiException
- if any exception occurs
-
deleteFile
@Deprecated public void deleteFile(java.lang.String filePath, java.lang.Long projectId, java.lang.String branchName, java.lang.String commitMessage) throws GitLabApiException
Deprecated.Will be removed in version 6.0, replaced bydeleteFile(Object, String, String, String)
Delete existing file in repository
file_path (required) - Full path to file. Ex. lib/class.rb branch_name (required) - The name of branch commit_message (required) - Commit messageGitLab Endpoint: DELETE /projects/:id/repository/files
- Parameters:
filePath
- full path to new file. Ex. lib/class.rbprojectId
- the project IDbranchName
- the name of branchcommitMessage
- the commit message- Throws:
GitLabApiException
- if any exception occurs
-
getRawFile
public java.io.File getRawFile(java.lang.Object projectIdOrPath, java.lang.String commitOrBranchName, java.lang.String filepath, java.io.File directory) throws GitLabApiException
Get the raw file for the file by commit sha and path. Thye file will be saved to the specified directory. If the file already exists in the directory it will be overwritten. V3:
V4:GitLab Endpoint: GET /projects/:id/repository/blobs/:sha
GitLab Endpoint: GET /projects/:id/repository/files/:filepath
- Parameters:
projectIdOrPath
- the project in the form of an Long(ID), String(path), or Project instancecommitOrBranchName
- the commit or branch name to get the file forfilepath
- the path of the file to getdirectory
- the File instance of the directory to save the file to, if null will use "java.io.tmpdir"- Returns:
- a File instance pointing to the download of the specified file
- Throws:
GitLabApiException
- if any exception occurs
-
getRawFile
public java.io.InputStream getRawFile(java.lang.Object projectIdOrPath, java.lang.String ref, java.lang.String filepath) throws GitLabApiException
Get the raw file contents for a file by commit sha and path. V3:
V4:GitLab Endpoint: GET /projects/:id/repository/blobs/:sha
GitLab Endpoint: GET /projects/:id/repository/files/:filepath
- Parameters:
projectIdOrPath
- the project in the form of an Long(ID), String(path), or Project instanceref
- the commit or branch name to get the file contents forfilepath
- the path of the file to get- Returns:
- an InputStream to read the raw file from
- Throws:
GitLabApiException
- if any exception occurs
-
createForm
protected jakarta.ws.rs.core.Form createForm(RepositoryFile file, java.lang.String branchName, java.lang.String commitMessage)
Gets the query params based on the API version.- Parameters:
file
- the RepositoryFile instance with the info for the query paramsbranchName
- the branch namecommitMessage
- the commit message- Returns:
- a Form instance with the correct query params.
-
getBlame
public java.util.List<Blame> getBlame(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref) throws GitLabApiException
Get a List of file blame from repository. Allows you to receive blame information. Each blame range contains lines and corresponding commit information.GitLab Endpoint: GET /projects/:id/repository/files/:file_path/blame
- Parameters:
projectIdOrPath
- the project in the form of an Long(ID), String(path), or Project instancefilePath
- the path of the file to get the blame forref
- the name of branch, tag or commit- Returns:
- a List of Blame instances for the specified filePath and ref
- Throws:
GitLabApiException
- if any exception occurs
-
getBlame
public Pager<Blame> getBlame(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref, int itemsPerPage) throws GitLabApiException
Get a Pager of file blame from repository. Allows you to receive blame information. Each blame range contains lines and corresponding commit information.GitLab Endpoint: GET /projects/:id/repository/files/:file_path/blame
- Parameters:
projectIdOrPath
- the project in the form of an Long(ID), String(path), or Project instancefilePath
- the path of the file to get the blame forref
- the name of branch, tag or commititemsPerPage
- the number of Project instances that will be fetched per page- Returns:
- a Pager of Blame instances for the specified filePath and ref
- Throws:
GitLabApiException
- if any exception occurs
-
getBlameStream
public java.util.stream.Stream<Blame> getBlameStream(java.lang.Object projectIdOrPath, java.lang.String filePath, java.lang.String ref) throws GitLabApiException
Get a Stream of file blame from repository. Allows you to receive blame information. Each blame range contains lines and corresponding commit information.GitLab Endpoint: GET /projects/:id/repository/files/:file_path/blame
- Parameters:
projectIdOrPath
- the project in the form of an Long(ID), String(path), or Project instancefilePath
- the path of the file to get the blame forref
- the name of branch, tag or commit- Returns:
- a Stream of Blame instances for the specified filePath and ref
- Throws:
GitLabApiException
- if any exception occurs
-
-