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.
  • Constructor Details

    • RepositoryFileApi

      public RepositoryFileApi(GitLabApi gitLabApi)
  • 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 path
      filePath - (required) - Full path to the file. Ex. lib/class.rb
      ref - (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 path
      filePath - (required) - Full path to the file. Ex. lib/class.rb
      ref - (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 path
      filePath - (required) - Full path to the file. Ex. lib/class.rb
      ref - (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 path
      filePath - (required) - Full path to the file. Ex. lib/class.rb
      ref - (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 by getFile(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.rb
      projectId - (required) - the project ID
      ref - (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 path
      filePath - (required) - Full path to the file. Ex. lib/class.rb
      ref - (required) - The name of branch, tag or commit
      includeContent - 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.0
      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 new file. Ex. lib/class.rb
      projectId - (required) - the project ID
      ref - (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
      GitLab Endpoint: POST /projects/:id/repository/files
      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 message
      Parameters:
      projectIdOrPath - the id, path of the project, or a Project instance holding the project ID or path
      file - a ReposityoryFile instance with info for the file to create
      branchName - the name of branch
      commitMessage - 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 by createFile(Object, RepositoryFile, String, String)
      Create new file in repository
      GitLab Endpoint: POST /projects/:id/repository/files
      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 message
      Parameters:
      file - a ReposityoryFile instance with info for the file to create
      projectId - the project ID
      branchName - the name of branch
      commitMessage - 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
      GitLab Endpoint: PUT /projects/:id/repository/files
      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 message
      Parameters:
      projectIdOrPath - the id, path of the project, or a Project instance holding the project ID or path
      file - a ReposityoryFile instance with info for the file to update
      branchName - the name of branch
      commitMessage - 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 by updateFile(Object, RepositoryFile, String, String)
      Update existing file in repository
      GitLab Endpoint: PUT /projects/:id/repository/files
      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 message
      Parameters:
      file - a ReposityoryFile instance with info for the file to update
      projectId - the project ID
      branchName - the name of branch
      commitMessage - 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
      GitLab Endpoint: DELETE /projects/:id/repository/files
      file_path (required) - Full path to file. Ex. lib/class.rb branch_name (required) - The name of branch commit_message (required) - Commit message
      Parameters:
      projectIdOrPath - the id, path of the project, or a Project instance holding the project ID or path
      filePath - full path to new file. Ex. lib/class.rb
      branchName - the name of branch
      commitMessage - 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 by deleteFile(Object, String, String, String)
      Delete existing file in repository
      GitLab Endpoint: DELETE /projects/:id/repository/files
      file_path (required) - Full path to file. Ex. lib/class.rb branch_name (required) - The name of branch commit_message (required) - Commit message
      Parameters:
      filePath - full path to new file. Ex. lib/class.rb
      projectId - the project ID
      branchName - the name of branch
      commitMessage - 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:
      GitLab Endpoint: GET /projects/:id/repository/blobs/:sha
      V4:
      GitLab Endpoint: GET /projects/:id/repository/files/:filepath
      Parameters:
      projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
      commitOrBranchName - the commit or branch name to get the file for
      filepath - the path of the file to get
      directory - 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:
      GitLab Endpoint: GET /projects/:id/repository/blobs/:sha
      V4:
      GitLab Endpoint: GET /projects/:id/repository/files/:filepath
      Parameters:
      projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
      ref - the commit or branch name to get the file contents for
      filepath - 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 params
      branchName - the branch name
      commitMessage - 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 instance
      filePath - the path of the file to get the blame for
      ref - 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 instance
      filePath - the path of the file to get the blame for
      ref - the name of branch, tag or commit
      itemsPerPage - 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 instance
      filePath - the path of the file to get the blame for
      ref - 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