Class RepositoryFileApi

    • 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 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​(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 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 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 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​(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 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​(java.lang.String filePath,
                                      java.lang.Long projectId,
                                      java.lang.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​(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 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​(java.lang.String filePath,
                                           java.lang.Long projectId,
                                           java.lang.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​(java.lang.Object projectIdOrPath,
                                                 RepositoryFile file,
                                                 java.lang.String branchName,
                                                 java.lang.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,
                                                 java.lang.Long projectId,
                                                 java.lang.String branchName,
                                                 java.lang.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​(java.lang.Object projectIdOrPath,
                                                 RepositoryFile file,
                                                 java.lang.String branchName,
                                                 java.lang.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,
                                                 java.lang.Long projectId,
                                                 java.lang.String branchName,
                                                 java.lang.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​(java.lang.Object projectIdOrPath,
                               java.lang.String filePath,
                               java.lang.String branchName,
                               java.lang.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​(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 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 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:
        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 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:
        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,
                                                     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 params
        branchName - the branch name
        commitMessage - 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 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​(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 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 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 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