org.gitlab4j.api.models.Branch Java Examples

The following examples show how to use org.gitlab4j.api.models.Branch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRepositoryApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testProtectBranch() throws GitLabApiException {

    Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
    assertNotNull(project);

    Branch branch = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_PROTECT_BRANCH_NAME, "master");
    assertNotNull(branch);

    Branch protectedBranch = gitLabApi.getRepositoryApi().protectBranch(project.getId(), TEST_PROTECT_BRANCH_NAME);
    assertNotNull(protectedBranch);
    assertTrue(protectedBranch.getProtected());

    Branch unprotectedBranch = gitLabApi.getRepositoryApi().unprotectBranch(project.getId(), TEST_PROTECT_BRANCH_NAME);
    assertNotNull(unprotectedBranch);
    assertFalse(unprotectedBranch.getProtected());
}
 
Example #2
Source File: TestRepositoryApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testCreateBranch() throws GitLabApiException {
    Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
    assertNotNull(project);

    Branch branch = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH_NAME, "master");
    assertNotNull(branch);

    Branch fetchedBranch = gitLabApi.getRepositoryApi().getBranch(project.getId(), TEST_BRANCH_NAME);
    assertNotNull(fetchedBranch);

    List<Branch> searchBranches = gitLabApi.getRepositoryApi().getBranches(project.getId(), TEST_BRANCH_SEARCH_TERM);
    assertEquals(searchBranches.size(), 1);

    searchBranches = gitLabApi.getRepositoryApi().getBranches(project.getId());
    assertTrue(searchBranches.size() > 1);

    assertEquals(branch.getName(), fetchedBranch.getName());
}
 
Example #3
Source File: TestRepositoryFileApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testCreateFileWithEmptyContent() throws GitLabApiException {

    Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
    assertNotNull(project);

    Branch branch = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH_NAME, "master");
    assertNotNull(branch);

    RepositoryFile file = new RepositoryFile();
    file.setFilePath(TEST_FILEPATH);
    file.setContent("");
    RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile().");
    assertNotNull(createdFile);

    gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile().");
    gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME);
}
 
Example #4
Source File: TestRepositoryFileApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testCreateFileAndDeleteFile() throws GitLabApiException {

    Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
    assertNotNull(project);

    Branch branch = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH_NAME, "master");
    assertNotNull(branch);

    RepositoryFile file = new RepositoryFile();
    file.setFilePath(TEST_FILEPATH);
    file.setContent(TEST_CONTENT);
    RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile().");
    assertNotNull(createdFile);

    gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile().");
    gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME);
}
 
Example #5
Source File: TestPager.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testBranchesPager() throws GitLabApiException {

    Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
    assertNotNull(project);

    Pager<Branch> pager = gitLabApi.getRepositoryApi().getBranches(project.getId(), 2);
    assertNotNull(pager);
    assertEquals(2, pager.getItemsPerPage());
    assertTrue(0 < pager.getTotalPages());
    assertTrue(0 < pager.getTotalItems());

    int itemNumber = 0;
    int pageIndex = 0;
    while (pager.hasNext() && pageIndex < 10) {

        List<Branch> branches = pager.next();

        pageIndex++;
        assertEquals(pageIndex, pager.getCurrentPage());

        if (pageIndex < pager.getTotalPages())
            assertEquals(2, branches.size());

        for (Branch branch : branches) {
            itemNumber++;
            System.out.format("page=%d, item=%d, branchName=%s, isMerged=%b%n", pageIndex, itemNumber, branch.getName(), branch.getMerged());
        }
    }
}
 
Example #6
Source File: TestRepositoryApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testMergeBase() throws GitLabApiException {

    Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
    assertNotNull(project);

    Branch branch1 = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH1, "master");
    assertNotNull(branch1);
    Branch branch2 = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH2, "master");
    assertNotNull(branch2);

    List<String> refs = Arrays.asList(TEST_BRANCH1, TEST_BRANCH2);
    Commit mergeBase = gitLabApi.getRepositoryApi().getMergeBase(project, refs);
    assertNotNull(mergeBase);
}
 
Example #7
Source File: TestGitLabApiBeans.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testBranch() throws Exception {

    Branch branch = unmarshalResource(Branch.class, "branch.json");
    assertTrue(compareJson(branch, "branch.json"));

    branch = unmarshalResource(Branch.class, "bad-branch.json");
    assertTrue(!Branch.isValid(branch));
}
 
Example #8
Source File: TestCommitsApi.java    From gitlab4j-api with MIT License 4 votes vote down vote up
@Test
public void testCherryPickCommit() throws GitLabApiException {
    
    // Make sure the branch to cherry pick does not exist
    if(gitLabApi.getRepositoryApi().getOptionalBranch(testProject, "cherry-pick-branch").isPresent()) {
       gitLabApi.getRepositoryApi().deleteBranch(testProject, "cherry-pick-branch");
    }
    
    // Make sure the file to create does not exist.
    String filePath = TEST_CREATE_COMMIT_FILEPATH + ".test";
    if (gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, "master").isPresent()) {
        gitLabApi.getRepositoryFileApi().deleteFile(testProject, filePath, "master", "Deleted test file");
    }

    // Act
    Branch branch = gitLabApi.getRepositoryApi().createBranch(testProject, "cherry-pick-branch", "master");
    
    // Assert
    assertNotNull(branch);
    Optional<RepositoryFile> repoFileBranch = gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, branch.getName());
    assertFalse(repoFileBranch.isPresent());
    
    // Arrange
    CommitAction commitAction = new CommitAction()
            .withAction(Action.CREATE)
            .withContent("This is the original data in the file")
            .withFilePath(filePath);

    // Act
    Commit commit = gitLabApi.getCommitsApi().createCommit(
            testProject, "master", "Testing createCommit() create action", null, null, null, commitAction);

    // Assert
    assertNotNull(commit);
    Optional<RepositoryFile> repoFile = gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, "master");
    assertTrue(repoFile.isPresent());
    
    // Act
    Commit cherryPickedCommit = gitLabApi.getCommitsApi().cherryPickCommit(testProject, commit.getId(), "cherry-pick-branch");
    
    // Assert
    assertNotNull(cherryPickedCommit);
    Optional<RepositoryFile> repoFileBranchCherryPicked = gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, branch.getName());
    assertTrue(repoFileBranchCherryPicked.isPresent());
}
 
Example #9
Source File: TestCommitsApi.java    From gitlab4j-api with MIT License 4 votes vote down vote up
@Test
public void testCreateCommitWithPayload() throws GitLabApiException {

    String TEST_BRANCH = "create_commit_from_payload";

    Optional<Branch> testBranch = gitLabApi.getRepositoryApi().getOptionalBranch(testProject, TEST_BRANCH);
    if (!testBranch.isPresent()) {
        gitLabApi.getRepositoryApi().createBranch(testProject, TEST_BRANCH, "master");
    }

    if (gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, TEST_CREATE_COMMIT_FILEPATH, TEST_BRANCH).isPresent()) {
        try {
            gitLabApi.getRepositoryFileApi().deleteFile(testProject, TEST_CREATE_COMMIT_FILEPATH, TEST_BRANCH, "Deleted test file");
        } catch (GitLabApiException ignore) {}
    }

    // Arrange
    CommitPayload commitPayload = new CommitPayload()
            .withBranch(TEST_BRANCH)
            .withCommitMessage("Testing createCommit() create action")
            .withAction(Action.CREATE, "This is the original data in the file", TEST_CREATE_COMMIT_FILEPATH);

    // Act
    Commit commit = gitLabApi.getCommitsApi().createCommit(testProject, commitPayload);

    // Assert
    assertNotNull(commit);

    // Arrange
    commitPayload = new CommitPayload()
            .withBranch(TEST_BRANCH)
            .withCommitMessage("Testing createCommit() delete action")
            .withAction(Action.DELETE, TEST_CREATE_COMMIT_FILEPATH);

    // Act
    commit = gitLabApi.getCommitsApi().createCommit(testProject, commitPayload);

    // Assert
    assertNotNull(commit);

    Optional<RepositoryFile> repoFile = gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, TEST_CREATE_COMMIT_FILEPATH, TEST_BRANCH);
    assertFalse(repoFile.isPresent());
}
 
Example #10
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 3 votes vote down vote up
/**
 * Get a Pager of repository branches from a project, sorted by name alphabetically, filter by the search term.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches?search=:search</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param search the branch name search term
 * @param itemsPerPage the number of Project instances that will be fetched per page
 * @return the list of repository branches for the specified project ID and search term
 *
 * @throws GitLabApiException if any exception occurs
 */
public Pager<Branch> getBranches(Object projectIdOrPath, String search, int itemsPerPage) throws GitLabApiException {
    MultivaluedMap<String, String> queryParams = ( search == null ? null :
        new GitLabApiForm().withParam("search", urlEncode(search)).asMap() );

    return (new Pager<Branch>(this, Branch.class, itemsPerPage, queryParams, "projects",
            getProjectIdOrPath(projectIdOrPath), "repository", "branches"));
}
 
Example #11
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 3 votes vote down vote up
/**
 * Creates a branch for the project. Support as of version 6.8.x
 *
 * <pre><code>GitLab Endpoint: POST /projects/:id/repository/branches</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param branchName the name of the branch to create
 * @param ref Source to create the branch from, can be an existing branch, tag or commit SHA
 * @return the branch info for the created branch
 * @throws GitLabApiException if any exception occurs
 */
public Branch createBranch(Object projectIdOrPath, String branchName, String ref) throws GitLabApiException {

    Form formData = new GitLabApiForm()
            .withParam(isApiVersion(ApiVersion.V3) ? "branch_name" : "branch", branchName, true)
            .withParam("ref", ref, true);
    Response response = post(Response.Status.CREATED, formData.asMap(), "projects",
            getProjectIdOrPath(projectIdOrPath), "repository", "branches");
    return (response.readEntity(Branch.class));
}
 
Example #12
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 3 votes vote down vote up
/**
 * Get an Optional instance with the value for the specific repository branch.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches/:branch</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param branchName the name of the branch to get
 * @return an Optional instance with the info for the specified project ID/branch name pair as the value
 * @throws GitLabApiException if any exception occurs
 */
public Optional<Branch> getOptionalBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
    try {
        return (Optional.ofNullable(getBranch(projectIdOrPath, branchName)));
    } catch (GitLabApiException glae) {
        return (GitLabApi.createOptionalFromException(glae));
    }
}
 
Example #13
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a branch for the project. Support as of version 6.8.x
 * <p>
 * POST /projects/:id/repository/branches
 *
 * @param projectId  the project to create the branch for
 * @param branchName the name of the branch to create
 * @param ref        Source to create the branch from, can be an existing branch, tag or commit SHA
 * @return the branch info for the created branch
 * @throws GitLabApiException if any exception occurs
 */
public Branch createBranch(Integer projectId, String branchName, String ref) throws GitLabApiException {

    Form formData = new GitLabApiForm()
            .withParam(isApiVersion(ApiVersion.V3) ? "branch_name" : "branch", branchName, true)
            .withParam("ref", ref, true);
    Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "repository", "branches");
    return (response.readEntity(Branch.class));
}
 
Example #14
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a list of repository branches from a project, sorted by name alphabetically.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @return the list of repository branches for the specified project
 * @throws GitLabApiException if any exception occurs
 */
public List<Branch> getBranches(Object projectIdOrPath) throws GitLabApiException {
    return getBranches(projectIdOrPath, null, getDefaultPerPage()).all();
}
 
Example #15
Source File: GitLabSCMSourceRequest.java    From gitlab-branch-source-plugin with MIT License 2 votes vote down vote up
/**
 * Provides the requests with the branch details.
 *
 * @param branches the branch details.
 */
public final void setBranches(@CheckForNull Iterable<Branch> branches) {
    this.branches = branches;
}
 
Example #16
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * Get a list of repository branches from a project, sorted by name alphabetically.
 * <p>
 * GET /projects/:id/repository/branches
 *
 * @param projectId the project to get the list of branches for
 * @return the list of repository branches for the specified project ID
 * @throws GitLabApiException if any exception occurs
 */
public List<Branch> getBranches(Integer projectId) throws GitLabApiException {
    Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "repository", "branches");
    return (response.readEntity(new GenericType<List<Branch>>() {
    }));
}
 
Example #17
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * Get a list of repository branches from a project, sorted by name alphabetically.
 * <p>
 * GET /projects/:id/repository/branches
 *
 * @param projectId the project to get the list of branches for
 * @param page      the page to get
 * @param perPage   the number of Branch instances per page
 * @return the list of repository branches for the specified project ID
 * @throws GitLabApiException if any exception occurs
 */
public List<Branch> getBranches(Integer projectId, int page, int perPage) throws GitLabApiException {
    Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "repository", "branches");
    return (response.readEntity(new GenericType<List<Branch>>() {
    }));
}
 
Example #18
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * Get a Pager of repository branches from a project, sorted by name alphabetically.
 * <p>
 * GET /projects/:id/repository/branches
 *
 * @param projectId    the project to get the list of branches for
 * @param itemsPerPage the number of Project instances that will be fetched per page
 * @return the list of repository branches for the specified project ID
 * @throws GitLabApiException if any exception occurs
 */
public Pager<Branch> getBranches(Integer projectId, int itemsPerPage) throws GitLabApiException {
    return (new Pager<Branch>(this, Branch.class, itemsPerPage, null, "projects", projectId, "repository", "branches"));
}
 
Example #19
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * Get a single project repository branch.
 * <p>
 * GET /projects/:id/repository/branches/:branch
 *
 * @param projectId  the project to get the branch for
 * @param branchName the name of the branch to get
 * @return the branch info for the specified project ID/branch name pair
 * @throws GitLabApiException if any exception occurs
 */
public Branch getBranch(Integer projectId, String branchName) throws GitLabApiException {
    Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "branches", urlEncode(branchName));
    return (response.readEntity(Branch.class));
}
 
Example #20
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * Protects a single project repository branch. This is an idempotent function,
 * protecting an already protected repository branch will not produce an error.
 * <p>
 * PUT /projects/:id/repository/branches/:branch/protect
 *
 * @param projectId  the ID of the project to protect
 * @param branchName the name of the branch to protect
 * @return the branch info for the protected branch
 * @throws GitLabApiException if any exception occurs
 */
public Branch protectBranch(Integer projectId, String branchName) throws GitLabApiException {
    Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "protect");
    return (response.readEntity(Branch.class));
}
 
Example #21
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * Unprotects a single project repository branch. This is an idempotent function, unprotecting an
 * already unprotected repository branch will not produce an error.
 * <p>
 * PUT /projects/:id/repository/branches/:branch/unprotect
 *
 * @param projectId  the ID of the project to un-protect
 * @param branchName the name of the branch to un-protect
 * @return the branch info for the unprotected branch
 * @throws GitLabApiException if any exception occurs
 */
public Branch unprotectBranch(Integer projectId, String branchName) throws GitLabApiException {
    Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "unprotect");
    return (response.readEntity(Branch.class));
}
 
Example #22
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a Stream of repository branches from a project, sorted by name alphabetically.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @return a Stream of repository branches for the specified project
 * @throws GitLabApiException if any exception occurs
 */
public Stream<Branch> getBranchesStream(Object projectIdOrPath) throws GitLabApiException {
    return getBranches(projectIdOrPath, null, getDefaultPerPage()).stream();
}
 
Example #23
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Unprotects a single project repository branch. This is an idempotent function, unprotecting an
 * already unprotected repository branch will not produce an error.
 *
 * <pre><code>GitLab Endpoint: PUT /projects/:id/repository/branches/:branch/unprotect</code></pre>
 *
 * @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
 * @return the branch info for the unprotected branch
 * @throws GitLabApiException if any exception occurs
 */
public Branch unprotectBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
    Response response = put(Response.Status.OK, null, "projects",
            getProjectIdOrPath(projectIdOrPath), "repository", "branches", urlEncode(branchName), "unprotect");
    return (response.readEntity(Branch.class));
}
 
Example #24
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Protects a single project repository branch. This is an idempotent function,
 * protecting an already protected repository branch will not produce an error.
 *
 * <pre><code>GitLab Endpoint: PUT /projects/:id/repository/branches/:branch/protect</code></pre>
 *
 * @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 Branch protectBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
    Response response = put(Response.Status.OK, null, "projects",
            getProjectIdOrPath(projectIdOrPath), "repository", "branches", urlEncode(branchName), "protect");
    return (response.readEntity(Branch.class));
}
 
Example #25
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a list of repository branches from a project, sorted by name alphabetically.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param page the page to get
 * @param perPage the number of Branch instances per page
 * @return the list of repository branches for the specified project
 * @throws GitLabApiException if any exception occurs
 */
public List<Branch> getBranches(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
    Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects",
            getProjectIdOrPath(projectIdOrPath), "repository", "branches");
    return (response.readEntity(new GenericType<List<Branch>>() {}));
}
 
Example #26
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a Pager of repository branches from a project, sorted by name alphabetically.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param itemsPerPage the number of Project instances that will be fetched per page
 * @return the list of repository branches for the specified project ID
 *
 * @throws GitLabApiException if any exception occurs
 */
public Pager<Branch> getBranches(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
    return getBranches(projectIdOrPath, null, itemsPerPage);
}
 
Example #27
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a Stream of repository branches from a project, sorted by name alphabetically, filter by the search term.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches?search=:search</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param search the branch name search term
 * @return the Stream of repository branches for the specified project ID and search term
 *
 * @throws GitLabApiException if any exception occurs
 */
public Stream<Branch> getBranchesStream(Object projectIdOrPath, String search) throws GitLabApiException {
    return (getBranches(projectIdOrPath, search, getDefaultPerPage()).stream());
}
 
Example #28
Source File: GitLabSCMSourceRequest.java    From gitlab-branch-source-plugin with MIT License 2 votes vote down vote up
/**
 * Returns the branch details or an empty list if either the request did not specify to {@link
 * #isFetchBranches()} or if the branch details have not been provided by {@link
 * #setBranches(Iterable)} yet.
 *
 * @return the branch details (may be empty)
 */
@NonNull
public final Iterable<Branch> getBranches() {
    return Util.fixNull(branches);
}
 
Example #29
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a List of repository branches from a project, sorted by name alphabetically, filter by the search term.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches?search=:search</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param search the branch name search term
 * @return the List of repository branches for the specified project ID and search term
 * @throws GitLabApiException if any exception occurs
 */
public List<Branch> getBranches(Object projectIdOrPath, String search) throws GitLabApiException {
    return (getBranches(projectIdOrPath, search, getDefaultPerPage()).all());
}
 
Example #30
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * Get a single project repository branch.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id/repository/branches/:branch</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param branchName the name of the branch to get
 * @return the branch info for the specified project ID/branch name pair
 * @throws GitLabApiException if any exception occurs
 */
public Branch getBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
    Response response = get(Response.Status.OK, null, "projects",
            getProjectIdOrPath(projectIdOrPath), "repository", "branches", urlEncode(branchName));
    return (response.readEntity(Branch.class));
}