Package org.gitlab4j.api
Class RepositoryFileApi
java.lang.Object
org.gitlab4j.api.AbstractApi
org.gitlab4j.api.RepositoryFileApi
- All Implemented Interfaces:
Constants
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.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
-
Method Summary
Modifier and TypeMethodDescriptioncreateFile
(Object projectIdOrPath, RepositoryFile file, String branchName, String commitMessage) Create new file in repositorycreateFile
(RepositoryFile file, Long projectId, String branchName, String commitMessage) Deprecated.protected jakarta.ws.rs.core.Form
createForm
(RepositoryFile file, String branchName, String commitMessage) Gets the query params based on the API version.void
deleteFile
(Object projectIdOrPath, String filePath, String branchName, String commitMessage) Delete existing file in repositoryvoid
deleteFile
(String filePath, Long projectId, String branchName, String commitMessage) Deprecated.Will be removed in version 6.0, replaced bydeleteFile(Object, String, String, String)
Get a List of file blame from repository.Get a Pager of file blame from repository.getBlameStream
(Object projectIdOrPath, String filePath, String ref) Get a Stream of file blame from repository.Get file from repository.Get file from repository.Deprecated.Will be removed in version 6.0, replaced bygetFile(Object, String, String)
getFileInfo
(Object projectIdOrPath, String filePath, String ref) Get information on a file in the repository.protected RepositoryFile
Deprecated.Will be removed in version 6.0getOptionalFile
(Object projectIdOrPath, String filePath, String ref) Get an Optional instance with the value holding information and content for a file in the repository.getOptionalFileInfo
(Object projectIdOrPath, String filePath, String ref) Get an Optional instance with the value holding information on a file in the repository.getRawFile
(Object projectIdOrPath, String ref, String filepath) Get the raw file contents for a file by commit sha and path.getRawFile
(Object projectIdOrPath, String commitOrBranchName, String filepath, File directory) Get the raw file for the file by commit sha and path.updateFile
(Object projectIdOrPath, RepositoryFile file, String branchName, String commitMessage) Update existing file in repositoryupdateFile
(RepositoryFile file, Long projectId, String branchName, 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 Details
-
RepositoryFileApi
-
-
Method Details
-
getOptionalFileInfo
public Optional<RepositoryFile> getOptionalFileInfo(Object projectIdOrPath, String filePath, 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(Object projectIdOrPath, String filePath, 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 Optional<RepositoryFile> getOptionalFile(Object projectIdOrPath, String filePath, 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(Object projectIdOrPath, String filePath, 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(String filePath, Long projectId, 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(Object projectIdOrPath, String filePath, 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(String filePath, Long projectId, 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(Object projectIdOrPath, RepositoryFile file, String branchName, 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, Long projectId, String branchName, 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(Object projectIdOrPath, RepositoryFile file, String branchName, 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, Long projectId, String branchName, 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(Object projectIdOrPath, String filePath, String branchName, 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(String filePath, Long projectId, String branchName, 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 File getRawFile(Object projectIdOrPath, String commitOrBranchName, String filepath, 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 InputStream getRawFile(Object projectIdOrPath, String ref, 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, String branchName, 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 List<Blame> getBlame(Object projectIdOrPath, String filePath, 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(Object projectIdOrPath, String filePath, 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 Stream<Blame> getBlameStream(Object projectIdOrPath, String filePath, 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
-
createFile(Object, RepositoryFile, String, String)