All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gitlab4j.api.ProtectedBranchesApi Maven / Gradle / Ivy

Go to download

GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.

There is a newer version: 6.0.0-rc.5
Show newest version
package org.gitlab4j.api;

import java.util.List;
import java.util.stream.Stream;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;

import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.ProtectedBranch;

public class ProtectedBranchesApi extends AbstractApi {

    public ProtectedBranchesApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    }

    /**
     * Gets a list of protected branches from a project.
     *
     * 
GitLab Endpoint: GET /projects/:id/protected_branches
* * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @return the list of protected branches for the project * @throws GitLabApiException if any exception occurs */ public List getProtectedBranches(Object projectIdOrPath) throws GitLabApiException { return (getProtectedBranches(projectIdOrPath, this.getDefaultPerPage()).all()); } /** * Gets a Pager of protected branches from a project. * *
GitLab Endpoint: GET /projects/:id/protected_branches
* * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param itemsPerPage the number of instances that will be fetched per page * @return the Pager of protected branches for the project * @throws GitLabApiException if any exception occurs */ public Pager getProtectedBranches(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { return (new Pager(this, ProtectedBranch.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "protected_branches")); } /** * Gets a Stream of protected branches from a project. * *
GitLab Endpoint: GET /projects/:id/protected_branches
* * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @return the Stream of protected branches for the project * @throws GitLabApiException if any exception occurs */ public Stream getProtectedBranchesStream(Object projectIdOrPath) throws GitLabApiException { return (getProtectedBranches(projectIdOrPath, this.getDefaultPerPage()).stream()); } /** * Unprotects the given protected branch or wildcard protected branch. * *
GitLab Endpoint: DELETE /projects/:id/protected_branches/:name
* * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param branchName the name of the branch to un-protect * @throws GitLabApiException if any exception occurs */ public void unprotectBranch(Integer projectIdOrPath, String branchName) throws GitLabApiException { delete(Response.Status.NO_CONTENT, null, "projects", getProjectIdOrPath(projectIdOrPath), "protected_branches", urlEncode(branchName)); } /** * Protects a single repository branch or several project repository branches using a wildcard protected branch. * *
GitLab Endpoint: POST /projects/:id/protected_branches
* * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param branchName the name of the branch to protect * @return the branch info for the protected branch * @throws GitLabApiException if any exception occurs */ public ProtectedBranch protectBranch(Integer projectIdOrPath, String branchName) throws GitLabApiException { return protectBranch(projectIdOrPath, branchName, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER); } /** * Protects a single repository branch or several project repository branches using a wildcard protected branch. * *
GitLab Endpoint: POST /projects/:id/protected_branches
* * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param branchName the name of the branch to protect * @param pushAccessLevel Access levels allowed to push (defaults: 40, maintainer access level) * @param mergeAccessLevel Access levels allowed to merge (defaults: 40, maintainer access level) * @return the branch info for the protected branch * @throws GitLabApiException if any exception occurs */ public ProtectedBranch protectBranch(Integer projectIdOrPath, String branchName, AccessLevel pushAccessLevel, AccessLevel mergeAccessLevel) throws GitLabApiException { Form formData = new GitLabApiForm() .withParam("name", branchName, true) .withParam("push_access_level", pushAccessLevel.toValue(), false) .withParam("merge_access_level", mergeAccessLevel.toValue(), false); Response response = post(Response.Status.CREATED, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "protected_branches"); return (response.readEntity(ProtectedBranch.class)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy