Class ProtectedBranchesApi

  • All Implemented Interfaces:
    org.gitlab4j.models.Constants

    public class ProtectedBranchesApi
    extends AbstractApi
    This class provides an entry point to all the Protected Branches API calls.
    See Also:
    Protected branches API at GitLab
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.gitlab4j.models.Constants

        org.gitlab4j.models.Constants.ActionType, org.gitlab4j.models.Constants.ApplicationScope, org.gitlab4j.models.Constants.ArchiveFormat, org.gitlab4j.models.Constants.AutoCancelPendingPipelines, org.gitlab4j.models.Constants.AutoDevopsDeployStrategy, org.gitlab4j.models.Constants.BuildGitStrategy, org.gitlab4j.models.Constants.CommitBuildState, org.gitlab4j.models.Constants.ContributorOrderBy, org.gitlab4j.models.Constants.DefaultBranchProtectionLevel, org.gitlab4j.models.Constants.DeploymentOrderBy, org.gitlab4j.models.Constants.DeploymentStatus, org.gitlab4j.models.Constants.DeployTokenScope, org.gitlab4j.models.Constants.Encoding, org.gitlab4j.models.Constants.EpicOrderBy, org.gitlab4j.models.Constants.EventScope, org.gitlab4j.models.Constants.GroupOrderBy, org.gitlab4j.models.Constants.GroupSearchScope<T extends java.lang.Object>, org.gitlab4j.models.Constants.ImpersonationState, org.gitlab4j.models.Constants.IssueOrderBy, org.gitlab4j.models.Constants.IssueScope, org.gitlab4j.models.Constants.IssueState, org.gitlab4j.models.Constants.JobScope, org.gitlab4j.models.Constants.LineType, org.gitlab4j.models.Constants.MergeRequestOrderBy, org.gitlab4j.models.Constants.MergeRequestScope, org.gitlab4j.models.Constants.MergeRequestSearchIn, org.gitlab4j.models.Constants.MergeRequestState, org.gitlab4j.models.Constants.MilestoneState, org.gitlab4j.models.Constants.PackageOrderBy, org.gitlab4j.models.Constants.PackageStatus, org.gitlab4j.models.Constants.PipelineOrderBy, org.gitlab4j.models.Constants.PipelineScope, org.gitlab4j.models.Constants.PipelineSource, org.gitlab4j.models.Constants.ProjectAccessTokenScope, org.gitlab4j.models.Constants.ProjectCreationLevel, org.gitlab4j.models.Constants.ProjectFeatureVisibilityAccessLevel, org.gitlab4j.models.Constants.ProjectOrderBy, org.gitlab4j.models.Constants.ProjectSearchScope<T extends java.lang.Object>, org.gitlab4j.models.Constants.SearchScope<T extends java.lang.Object>, org.gitlab4j.models.Constants.SortOrder, org.gitlab4j.models.Constants.SquashOption, org.gitlab4j.models.Constants.StateEvent, org.gitlab4j.models.Constants.SubgroupCreationLevel, org.gitlab4j.models.Constants.TagOrderBy, org.gitlab4j.models.Constants.TargetType, org.gitlab4j.models.Constants.TodoAction, org.gitlab4j.models.Constants.TodoState, org.gitlab4j.models.Constants.TodoType, org.gitlab4j.models.Constants.TokenType
    • Field Summary

      • Fields inherited from interface org.gitlab4j.models.Constants

        NEXT_PAGE_HEADER, PAGE_HEADER, PAGE_PARAM, PER_PAGE, PER_PAGE_PARAM, PREV_PAGE_HEADER, TOTAL_HEADER, TOTAL_PAGES_HEADER
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<org.gitlab4j.api.models.ProtectedBranch> getOptionalProtectedBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName)
      Get an Optional instance with the value for the specific protected branch.
      org.gitlab4j.api.models.ProtectedBranch getProtectedBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName)
      Get a single protected branch or wildcard protected branch.
      java.util.List<org.gitlab4j.api.models.ProtectedBranch> getProtectedBranches​(java.lang.Object projectIdOrPath)
      Gets a list of protected branches from a project.
      Pager<org.gitlab4j.api.models.ProtectedBranch> getProtectedBranches​(java.lang.Object projectIdOrPath, int itemsPerPage)
      Gets a Pager of protected branches from a project.
      java.util.stream.Stream<org.gitlab4j.api.models.ProtectedBranch> getProtectedBranchesStream​(java.lang.Object projectIdOrPath)
      Gets a Stream of protected branches from a project.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName, java.lang.Long allowedToPushUserId, java.lang.Long allowedToMergeUserId, java.lang.Long allowedToUnprotectUserId, java.lang.Boolean codeOwnerApprovalRequired)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName, java.lang.Long allowedToPushUserId, java.lang.Long allowedToMergeUserId, java.lang.Long allowedToUnprotectUserId, java.lang.Boolean codeOwnerApprovalRequired, java.lang.Boolean allowForcedPush)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName, org.gitlab4j.api.models.AccessLevel pushAccessLevel, org.gitlab4j.api.models.AccessLevel mergeAccessLevel)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName, org.gitlab4j.api.models.AccessLevel pushAccessLevel, org.gitlab4j.api.models.AccessLevel mergeAccessLevel, org.gitlab4j.api.models.AccessLevel unprotectAccessLevel, java.lang.Boolean codeOwnerApprovalRequired)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName, org.gitlab4j.api.models.AccessLevel pushAccessLevel, org.gitlab4j.api.models.AccessLevel mergeAccessLevel, org.gitlab4j.api.models.AccessLevel unprotectAccessLevel, java.lang.Boolean codeOwnerApprovalRequired, java.lang.Boolean allowForcedPush)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName, org.gitlab4j.api.models.AllowedTo allowedToPush, org.gitlab4j.api.models.AllowedTo allowedToMerge, org.gitlab4j.api.models.AllowedTo allowedToUnprotect, java.lang.Boolean codeOwnerApprovalRequired)
      Protects a single repository branch or several project repository branches using a wildcard protected branch.
      org.gitlab4j.api.models.ProtectedBranch setCodeOwnerApprovalRequired​(java.lang.Object projectIdOrPath, java.lang.String branchName, java.lang.Boolean codeOwnerApprovalRequired)
      Sets the code_owner_approval_required flag on the specified protected branch.
      void unprotectBranch​(java.lang.Object projectIdOrPath, java.lang.String branchName)
      Unprotects the given protected branch or wildcard protected branch.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ProtectedBranchesApi

        public ProtectedBranchesApi​(GitLabApi gitLabApi)
    • Method Detail

      • getProtectedBranches

        public java.util.List<org.gitlab4j.api.models.ProtectedBranch> getProtectedBranches​(java.lang.Object projectIdOrPath)
                                                                                     throws GitLabApiException
        Gets a list of protected branches from a project.
        GitLab Endpoint: GET /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        Returns:
        the list of protected branches for the project
        Throws:
        GitLabApiException - if any exception occurs
      • getProtectedBranches

        public Pager<org.gitlab4j.api.models.ProtectedBranch> getProtectedBranches​(java.lang.Object projectIdOrPath,
                                                                                   int itemsPerPage)
                                                                            throws GitLabApiException
        Gets a Pager of protected branches from a project.
        GitLab Endpoint: GET /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        itemsPerPage - the number of instances that will be fetched per page
        Returns:
        the Pager of protected branches for the project
        Throws:
        GitLabApiException - if any exception occurs
      • getProtectedBranchesStream

        public java.util.stream.Stream<org.gitlab4j.api.models.ProtectedBranch> getProtectedBranchesStream​(java.lang.Object projectIdOrPath)
                                                                                                    throws GitLabApiException
        Gets a Stream of protected branches from a project.
        GitLab Endpoint: GET /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        Returns:
        the Stream of protected branches for the project
        Throws:
        GitLabApiException - if any exception occurs
      • getProtectedBranch

        public org.gitlab4j.api.models.ProtectedBranch getProtectedBranch​(java.lang.Object projectIdOrPath,
                                                                          java.lang.String branchName)
                                                                   throws GitLabApiException
        Get a single protected branch or wildcard protected branch.
        GitLab Endpoint: GET /projects/:id/protected_branches/:branch_name
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch or wildcard
        Returns:
        a ProtectedBranch instance with info on the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • getOptionalProtectedBranch

        public java.util.Optional<org.gitlab4j.api.models.ProtectedBranch> getOptionalProtectedBranch​(java.lang.Object projectIdOrPath,
                                                                                                      java.lang.String branchName)
        Get an Optional instance with the value for the specific protected branch.
        GitLab Endpoint: GET /projects/:id/protected_branches/:branch_name
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch or wildcard
        Returns:
        an Optional instance with the specified protected branch as a value
      • unprotectBranch

        public void unprotectBranch​(java.lang.Object projectIdOrPath,
                                    java.lang.String branchName)
                             throws GitLabApiException
        Unprotects the given protected branch or wildcard protected branch.
        GitLab Endpoint: DELETE /projects/:id/protected_branches/:name
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to un-protect, can be a wildcard
        Throws:
        GitLabApiException - if any exception occurs
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.
        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName,
                                                                     org.gitlab4j.api.models.AccessLevel pushAccessLevel,
                                                                     org.gitlab4j.api.models.AccessLevel mergeAccessLevel)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.
        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        pushAccessLevel - Access levels allowed to push (defaults: 40, maintainer access level)
        mergeAccessLevel - Access levels allowed to merge (defaults: 40, maintainer access level)
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName,
                                                                     org.gitlab4j.api.models.AccessLevel pushAccessLevel,
                                                                     org.gitlab4j.api.models.AccessLevel mergeAccessLevel,
                                                                     org.gitlab4j.api.models.AccessLevel unprotectAccessLevel,
                                                                     java.lang.Boolean codeOwnerApprovalRequired)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.
        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        pushAccessLevel - access levels allowed to push (defaults: 40, maintainer access level)
        mergeAccessLevel - access levels allowed to merge (defaults: 40, maintainer access level)
        unprotectAccessLevel - access levels allowed to unprotect (defaults: 40, maintainer access level)
        codeOwnerApprovalRequired - prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
        See Also:
        protectBranch(Object, String, AccessLevel, AccessLevel, AccessLevel, Boolean, Boolean)
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName,
                                                                     org.gitlab4j.api.models.AccessLevel pushAccessLevel,
                                                                     org.gitlab4j.api.models.AccessLevel mergeAccessLevel,
                                                                     org.gitlab4j.api.models.AccessLevel unprotectAccessLevel,
                                                                     java.lang.Boolean codeOwnerApprovalRequired,
                                                                     java.lang.Boolean allowForcedPush)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.
        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        pushAccessLevel - access levels allowed to push (defaults: 40, maintainer access level)
        mergeAccessLevel - access levels allowed to merge (defaults: 40, maintainer access level)
        unprotectAccessLevel - access levels allowed to unprotect (defaults: 40, maintainer access level)
        codeOwnerApprovalRequired - prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
        allowForcedPush - when enabled, members who can push to this branch can also force push. (default: false)
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName,
                                                                     java.lang.Long allowedToPushUserId,
                                                                     java.lang.Long allowedToMergeUserId,
                                                                     java.lang.Long allowedToUnprotectUserId,
                                                                     java.lang.Boolean codeOwnerApprovalRequired)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.

        NOTE: This method is only available to GitLab Starter, Bronze, or higher.

        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        allowedToPushUserId - user ID allowed to push, can be null
        allowedToMergeUserId - user ID allowed to merge, can be null
        allowedToUnprotectUserId - user ID allowed to unprotect, can be null
        codeOwnerApprovalRequired - prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName,
                                                                     java.lang.Long allowedToPushUserId,
                                                                     java.lang.Long allowedToMergeUserId,
                                                                     java.lang.Long allowedToUnprotectUserId,
                                                                     java.lang.Boolean codeOwnerApprovalRequired,
                                                                     java.lang.Boolean allowForcedPush)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.

        NOTE: This method is only available to GitLab Starter, Bronze, or higher.

        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        allowedToPushUserId - user ID allowed to push, can be null
        allowedToMergeUserId - user ID allowed to merge, can be null
        allowedToUnprotectUserId - user ID allowed to unprotect, can be null
        codeOwnerApprovalRequired - prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
        allowForcedPush - when enabled, members who can push to this branch can also force push. (default: false)
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • protectBranch

        public org.gitlab4j.api.models.ProtectedBranch protectBranch​(java.lang.Object projectIdOrPath,
                                                                     java.lang.String branchName,
                                                                     org.gitlab4j.api.models.AllowedTo allowedToPush,
                                                                     org.gitlab4j.api.models.AllowedTo allowedToMerge,
                                                                     org.gitlab4j.api.models.AllowedTo allowedToUnprotect,
                                                                     java.lang.Boolean codeOwnerApprovalRequired)
                                                              throws GitLabApiException
        Protects a single repository branch or several project repository branches using a wildcard protected branch.

        NOTE: This method is only available to GitLab Starter, Bronze, or higher.

        GitLab Endpoint: POST /projects/:id/protected_branches
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        allowedToPush - an AllowedTo instance holding the configuration for "allowed_to_push"
        allowedToMerge - an AllowedTo instance holding the configuration for "allowed_to_merge"
        allowedToUnprotect - an AllowedTo instance holding the configuration for "allowed_to_unprotect" be null
        codeOwnerApprovalRequired - prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs
      • setCodeOwnerApprovalRequired

        public org.gitlab4j.api.models.ProtectedBranch setCodeOwnerApprovalRequired​(java.lang.Object projectIdOrPath,
                                                                                    java.lang.String branchName,
                                                                                    java.lang.Boolean codeOwnerApprovalRequired)
                                                                             throws GitLabApiException
        Sets the code_owner_approval_required flag on the specified protected branch.

        NOTE: This method is only available in GitLab Premium or higher.

        GitLab Endpoint: PATCH /projects/:id/protected_branches/:branch_name?code_owner_approval_required=true
        Parameters:
        projectIdOrPath - the project in the form of an Long(ID), String(path), or Project instance
        branchName - the name of the branch to protect, can be a wildcard
        codeOwnerApprovalRequired - prevent pushes to this branch if it matches an item in the CODEOWNERS file.
        Returns:
        the branch info for the protected branch
        Throws:
        GitLabApiException - if any exception occurs