org.gitlab4j.api.models.Project Java Examples

The following examples show how to use org.gitlab4j.api.models.Project. 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: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testListProjects() throws GitLabApiException {

    List<Project> projects = gitLabApi.getProjectApi().getProjects();
    assertNotNull(projects);
    assertTrue(projects.size() >= 2);

    int matchCount = 0;
    for (Project project : projects) {
        if (TEST_PROJECT_NAME_1.equals(project.getName()))
            matchCount++;
        else if (TEST_PROJECT_NAME_2.equals(project.getName()))
            matchCount++;
    }

    assertEquals(2, matchCount);

    projects = gitLabApi.getProjectApi().getProjects(TEST_PROJECT_NAME_1);
    assertNotNull(projects);
    assertEquals(2, projects.size());
    assertEquals(TEST_PROJECT_NAME_2, projects.get(0).getName());
    assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName());
}
 
Example #2
Source File: TestGitLabApiException.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testValidationErrors() throws GitLabApiException {

    Project project = new Project()
            .withName(TEST_PROJECT_NAME_DUPLICATE)
            .withDescription("GitLab4J test project.")
            .withVisibility(Visibility.PUBLIC);

    Project newProject = gitLabApi.getProjectApi().createProject(project);
    assertNotNull(newProject);

    try {
        newProject = gitLabApi.getProjectApi().createProject(project);
        fail("GitLabApiException not thrown");
    } catch (GitLabApiException gae) {
        assertTrue(gae.hasValidationErrors());
        Map<String, List<String>> validationErrors = gae.getValidationErrors();
        assertNotNull(validationErrors);
        assertFalse(validationErrors.isEmpty());
    }
}
 
Example #3
Source File: TestPager.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testStream() throws GitLabApiException {

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

    Pager<Commit> pager = gitLabApi.getCommitsApi().getCommits(project, 1);
    assertNotNull(pager);
    assertEquals(1, pager.getItemsPerPage());
    assertTrue(0 < pager.getTotalPages());

    int numCommits = pager.getTotalItems();
    assertTrue(0 < numCommits);

    System.out.println("Streamed commits:");
   assertEquals(numCommits, pager.stream().map(Commit::getId).peek(System.out::println).count());
}
 
Example #4
Source File: ProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
/**
 * Get a specific project, which is owned by the authentication user.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
 *
 * @param namespace the name of the project namespace or group
 * @param project the name of the project to get
 * @param includeStatistics include project statistics
 * @return the specified project
 * @throws GitLabApiException if any exception occurs
 */
public Project getProject(String namespace, String project, Boolean includeStatistics) throws GitLabApiException {

    if (namespace == null) {
        throw new RuntimeException("namespace cannot be null");
    }

    if (project == null) {
        throw new RuntimeException("project cannot be null");
    }

    String projectPath = null;
    try {
        projectPath = URLEncoder.encode(namespace + "/" + project, "UTF-8");
    } catch (UnsupportedEncodingException uee) {
        throw (new GitLabApiException(uee));
    }

    Form formData = new GitLabApiForm().withParam("statistics", includeStatistics);
    Response response = get(Response.Status.OK, formData.asMap(), "projects", projectPath);
    return (response.readEntity(Project.class));
}
 
Example #5
Source File: TestPager.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testAll() throws GitLabApiException {

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

    Pager<Commit> pager = gitLabApi.getCommitsApi().getCommits(project, 1);
    assertNotNull(pager);
    assertEquals(1, pager.getItemsPerPage());
    assertTrue(0 < pager.getTotalPages());

    int numCommits = pager.getTotalItems();
    assertTrue(0 < numCommits);

    List<Commit> allCommits = pager.all();
    System.out.println("All commits:");
    allCommits.stream().map(Commit::getId).forEach(System.out::println);

    assertEquals(numCommits, allCommits.size());
}
 
Example #6
Source File: ProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
/**
 * Get a specific project, which is owned by the authentication user.
 *
 * <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
 *
 * @param namespace the name of the project namespace or group
 * @param project the name of the project to get
 * @return the specified project
 * @throws GitLabApiException if any exception occurs
 */
public Project getProject(String namespace, String project) throws GitLabApiException {

    if (namespace == null) {
        throw new RuntimeException("namespace cannot be null");
    }

    if (project == null) {
        throw new RuntimeException("project cannot be null");
    }

    String projectPath = null;
    try {
        projectPath = URLEncoder.encode(namespace + "/" + project, "UTF-8");
    } catch (UnsupportedEncodingException uee) {
        throw (new GitLabApiException(uee));
    }

    Response response = get(Response.Status.OK, null, "projects", projectPath);
    return (response.readEntity(Project.class));
}
 
Example #7
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 #8
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testListProjectsWithParams() throws GitLabApiException {

    List<Project> projects = gitLabApi.getProjectApi().getProjects(false, Visibility.PUBLIC,
            Constants.ProjectOrderBy.NAME, Constants.SortOrder.DESC, null, true, true, true, false, true);
    assertNotNull(projects);
    assertTrue(projects.size() >= 2);

    int matchCount = 0;
    for (Project project : projects) {
        if (TEST_PROJECT_NAME_1.equals(project.getName()))
            matchCount++;
        else if (TEST_PROJECT_NAME_2.equals(project.getName()))
            matchCount++;
    }

    assertEquals(2, matchCount);

    projects = gitLabApi.getProjectApi().getProjects(TEST_PROJECT_NAME_1);
    assertNotNull(projects);
    assertEquals(2, projects.size());
    assertEquals(TEST_PROJECT_NAME_2, projects.get(0).getName());
    assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName());
}
 
Example #9
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testListProjectsWithParamsViaPager() throws GitLabApiException {

    Pager<Project> pager = gitLabApi.getProjectApi().getProjects(false, Visibility.PUBLIC,
            Constants.ProjectOrderBy.NAME, Constants.SortOrder.DESC, null, true, true, true, false, true, 10);
    assertNotNull(pager);
    assertTrue(pager.getTotalItems() >= 2);

    List<Project> projects = pager.next();
    int matchCount = 0;
    for (Project project : projects) {
        if (TEST_PROJECT_NAME_1.equals(project.getName()))
            matchCount++;
        else if (TEST_PROJECT_NAME_2.equals(project.getName()))
            matchCount++;
    }

    assertEquals(2, matchCount);

    projects = gitLabApi.getProjectApi().getProjects(TEST_PROJECT_NAME_1);
    assertNotNull(projects);
    assertEquals(2, projects.size());
    assertEquals(TEST_PROJECT_NAME_2, projects.get(0).getName());
    assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName());
}
 
Example #10
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testListProjectsWithParamByPage() throws GitLabApiException {

    List<Project> projects = gitLabApi.getProjectApi().getProjects(false, Visibility.PUBLIC,
            Constants.ProjectOrderBy.NAME, Constants.SortOrder.DESC, null, true, true, true, false, true, 1, 10);
    assertNotNull(projects);
    assertTrue(projects.size() >= 2);

    int matchCount = 0;
    for (Project project : projects) {
        if (TEST_PROJECT_NAME_1.equals(project.getName()))
            matchCount++;
        else if (TEST_PROJECT_NAME_2.equals(project.getName()))
            matchCount++;
    }

    assertEquals(2, matchCount);

    projects = gitLabApi.getProjectApi().getProjects(TEST_PROJECT_NAME_1);
    assertNotNull(projects);
    assertEquals(2, projects.size());
    assertEquals(TEST_PROJECT_NAME_2, projects.get(0).getName());
    assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName());
}
 
Example #11
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testStarAndUnstarProject() throws GitLabApiException {

    assumeNotNull(testProject);

    try {
        gitLabApi.getProjectApi().unstarProject(testProject);
    } catch (Exception ignore) {
    }

    Project starredProject = gitLabApi.getProjectApi().starProject(testProject);
    assertNotNull(starredProject);
    assertEquals(1, (int)starredProject.getStarCount());

    Project unstarredProject = gitLabApi.getProjectApi().unstarProject(testProject);
    assertNotNull(unstarredProject);
    assertEquals(0, (int)unstarredProject.getStarCount());
}
 
Example #12
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testProjectsWithAccessLevelFilter() throws GitLabApiException {

    ProjectFilter filter = new ProjectFilter().withMinAccessLevel(AccessLevel.GUEST);
    List<Project> guestProjects = gitLabApi.getProjectApi().getProjects(filter);
    assertTrue(guestProjects != null);
    assertTrue(guestProjects.size() > 0);

    // Use sudo to impersonate a non-admin user
    try {

        gitLabApi.sudo(TEST_SUDO_AS_USERNAME);
        filter = new ProjectFilter().withMinAccessLevel(AccessLevel.OWNER);
        List<Project> ownedProjects = gitLabApi.getProjectApi().getProjects(filter);
        assertTrue(ownedProjects != null);
        assertTrue(guestProjects.size() > ownedProjects.size());

    } finally {
        gitLabApi.unsudo();
    }
}
 
Example #13
Source File: TestRepositoryApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testCompare() throws GitLabApiException {

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

    List<Commit> commits = gitLabApi.getCommitsApi().getCommits(project.getId());
    assertNotNull(commits);
    assertTrue(commits.size() > 1);

    int numCommits = commits.size();
    CompareResults compareResults = gitLabApi.getRepositoryApi().compare(project.getId(), commits.get(numCommits - 1).getId(), commits.get(numCommits - 2).getId());
    assertNotNull(compareResults);

    compareResults = gitLabApi.getRepositoryApi().compare(TEST_NAMESPACE + "/" + TEST_PROJECT_NAME, commits.get(numCommits - 1).getId(), commits.get(numCommits - 2).getId());
    assertNotNull(compareResults);
}
 
Example #14
Source File: GitLabSCMNavigator.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@NonNull
private String getProjectName(int projectNamingStrategy, Project project) {
    String projectName;
    switch (projectNamingStrategy) {
        default:
            // for legacy reasons default naming strategy is set to full path
        case 1:
            projectName = project.getPathWithNamespace();
            break;
        case 2:
            projectName = project.getNameWithNamespace()
                .replace(String.format("%s / ", getGitlabOwner().getFullName()), "");
            break;
    }
    return projectName;
}
 
Example #15
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testForkProject() throws GitLabApiException {

    assumeTrue(TEST_GROUP != null && TEST_GROUP_PROJECT != null);
    assumeTrue(TEST_GROUP.trim().length() > 0 && TEST_GROUP_PROJECT.trim().length() > 0);

    Project project = gitLabApi.getProjectApi().getProject(TEST_GROUP, TEST_GROUP_PROJECT);
    assertNotNull(project);

    Project forkedProject = null;
    try {
        forkedProject = gitLabApi.getProjectApi().forkProject(project.getId(), TEST_NAMESPACE);
        assertNotNull(forkedProject);
    } finally {
        if (forkedProject != null) {
            try {
                gitLabApi.getProjectApi().deleteProject(forkedProject);
            } catch (Exception ignore) {}
        }
    }
}
 
Example #16
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 #17
Source File: TestRepositoryFileApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testRepositoryFileGetOptionalFile() throws GitLabApiException, IOException {

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

    Optional<RepositoryFile> fileInfo = gitLabApi.getRepositoryFileApi().getOptionalFileInfo(project.getId(), "README.md", "master");
    assertNotNull(fileInfo.get());

    fileInfo = gitLabApi.getRepositoryFileApi().getOptionalFileInfo(project.getId(), "I-DONT-EXIST", "master");
    assertFalse(fileInfo.isPresent());

    GitLabApiException e = GitLabApi.getOptionalException(fileInfo);
    assertNotNull(e);
    assertEquals(404, e.getHttpStatus());
}
 
Example #18
Source File: TestPager.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testMemberProjectPager() throws GitLabApiException {

    Pager<Project> pager = gitLabApi.getProjectApi().getMemberProjects(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<Project> projects = pager.next();

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

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

        for (Project project : projects) {
            itemNumber++;
            System.out.format("page=%d, item=%d, projectId=%d, projectName=%s%n", pageIndex, itemNumber, project.getId(), project.getName());
        }
    }
}
 
Example #19
Source File: ProjectApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
/**
 * Creates a Project
 *
 * @param name The name of the project
 * @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
 * @param description A description for the project, null otherwise
 * @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
 * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
 * @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
 * @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default
 * @param isPublic Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default
 * @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
 * @param importUrl The Import URL for the project, otherwise null
 * @return the GitLab Project
 * @throws GitLabApiException if any exception occurs
 * @deprecated As of release 4.2.0, replaced by {@link #createProject(String, Integer, String, Boolean, Boolean,
 *      Boolean, Boolean, Visibility, Integer, String)}
 */
@Deprecated
public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean mergeRequestsEnabled,
        Boolean wikiEnabled, Boolean snippetsEnabled, Boolean isPublic, Integer visibilityLevel, String importUrl) throws GitLabApiException {

    if (name == null || name.trim().length() == 0) {
        return (null);
    }

    GitLabApiForm formData = new GitLabApiForm()
            .withParam("name", name, true)
            .withParam("namespace_id", namespaceId)
            .withParam("description", description)
            .withParam("issues_enabled", issuesEnabled)
            .withParam("merge_requests_enabled", mergeRequestsEnabled)
            .withParam("wiki_enabled", wikiEnabled)
            .withParam("snippets_enabled", snippetsEnabled)
            .withParam("visibility_level", visibilityLevel)
            .withParam("import_url", importUrl);

    if (isApiVersion(ApiVersion.V3)) {
        formData.withParam("public", isPublic);
    } else if (isPublic) {
        formData.withParam("visibility", Visibility.PUBLIC);
    }

    Response response = post(Response.Status.CREATED, formData, "projects");
    return (response.readEntity(Project.class));
}
 
Example #20
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 #21
Source File: ProjectApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
/**
 * Creates a Project
 *
 * @param name The name of the project
 * @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
 * @param description A description for the project, null otherwise
 * @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
 * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
 * @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
 * @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default
 * @param visibility The visibility of the project, otherwise null indicates to use GitLab default
 * @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
 * @param printingMergeRequestLinkEnabled Show link to create/view merge request when pushing from the command line
 * @param importUrl The Import URL for the project, otherwise null
 * @return the GitLab Project
 * @throws GitLabApiException if any exception occurs
 */
public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean mergeRequestsEnabled,
        Boolean wikiEnabled, Boolean snippetsEnabled, Visibility visibility, Integer visibilityLevel,
        Boolean printingMergeRequestLinkEnabled, String importUrl) throws GitLabApiException {

    if (isApiVersion(ApiVersion.V3)) {
        Boolean isPublic = Visibility.PUBLIC == visibility;
        return (createProject(name, namespaceId, description, issuesEnabled, mergeRequestsEnabled,
                wikiEnabled, snippetsEnabled, isPublic, visibilityLevel, importUrl));
    }

    if (name == null || name.trim().length() == 0) {
        return (null);
    }

    GitLabApiForm formData = new GitLabApiForm()
            .withParam("name", name, true)
            .withParam("namespace_id", namespaceId)
            .withParam("description", description)
            .withParam("issues_enabled", issuesEnabled)
            .withParam("merge_requests_enabled", mergeRequestsEnabled)
            .withParam("wiki_enabled", wikiEnabled)
            .withParam("snippets_enabled", snippetsEnabled)
            .withParam("visibility_level", visibilityLevel)
            .withParam("visibility", visibility)
            .withParam("printing_merge_request_link_enabled", printingMergeRequestLinkEnabled)
            .withParam("import_url", importUrl);

    Response response = post(Response.Status.CREATED, formData, "projects");
    return (response.readEntity(Project.class));
}
 
Example #22
Source File: TestRepositoryFileApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testRepositoryFileViaInputStream() throws GitLabApiException, IOException {

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

    InputStream in = gitLabApi.getRepositoryFileApi().getRawFile(project.getId(), "master", "README.md");

    Path target = Files.createTempFile(TEST_PROJECT_NAME + "-README", "md");
    Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);

    assertTrue(target.toFile().length() > 0);
    Files.delete(target);
}
 
Example #23
Source File: TestRepositoryFileApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testRawFileViaFile() throws GitLabApiException, IOException {

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

    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File file = gitLabApi.getRepositoryFileApi().getRawFile(project.getId(), "master", "README.md", tempDir);
    assertTrue(file.length() > 0);
    file.delete();
}
 
Example #24
Source File: TestNotesApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testIssueNotesPager() throws GitLabApiException {

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

    for (Issue issue : gitLabApi.getIssuesApi().getIssues(project.getId())) {
        Pager<Note> pager = gitLabApi.getNotesApi().getIssueNotes(project.getId(), issue.getIid(), 10);
        assertNotNull(pager);
    }
}
 
Example #25
Source File: TestFileUpload.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testFileUploadWithMediaType() throws GitLabApiException {

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

    File fileToUpload = new File("README.md");
    FileUpload fileUpload = gitLabApi.getProjectApi().uploadFile(project.getId(), fileToUpload, "text/markdown");
    assertNotNull(fileUpload);
}
 
Example #26
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testProjectLanguages() throws GitLabApiException {

    assumeTrue(TEST_GROUP != null && TEST_GROUP_PROJECT != null);
    assumeTrue(TEST_GROUP.trim().length() > 0 && TEST_GROUP_PROJECT.trim().length() > 0);

    Project project = gitLabApi.getProjectApi().getProject(TEST_GROUP, TEST_GROUP_PROJECT);
    assertNotNull(project);
    Map<String, Float> projectLanguages = gitLabApi.getProjectApi().getProjectLanguages(project.getId());
    assertNotNull(projectLanguages);
}
 
Example #27
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 #28
Source File: ProjectApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
/**
 * Creates a Project
 *
 * @param name The name of the project
 * @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
 * @param description A description for the project, null otherwise
 * @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
 * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
 * @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
 * @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default
 * @param visibility The visibility of the project, otherwise null indicates to use GitLab default
 * @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
 * @param importUrl The Import URL for the project, otherwise null
 * @return the GitLab Project
 * @throws GitLabApiException if any exception occurs
 */
public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean mergeRequestsEnabled,
        Boolean wikiEnabled, Boolean snippetsEnabled, Visibility visibility, Integer visibilityLevel, String importUrl) throws GitLabApiException {

    if (isApiVersion(ApiVersion.V3)) {
        Boolean isPublic = Visibility.PUBLIC == visibility;
        return (createProject(name, namespaceId, description, issuesEnabled, mergeRequestsEnabled,
                wikiEnabled, snippetsEnabled, isPublic, visibilityLevel, importUrl));
    }

    if (name == null || name.trim().length() == 0) {
        return (null);
    }

    GitLabApiForm formData = new GitLabApiForm()
            .withParam("name", name, true)
            .withParam("namespace_id", namespaceId)
            .withParam("description", description)
            .withParam("issues_enabled", issuesEnabled)
            .withParam("merge_requests_enabled", mergeRequestsEnabled)
            .withParam("wiki_enabled", wikiEnabled)
            .withParam("snippets_enabled", snippetsEnabled)
            .withParam("visibility_level", visibilityLevel)
            .withParam("visibility", visibility)
            .withParam("import_url", importUrl);

    Response response = post(Response.Status.CREATED, formData, "projects");
    return (response.readEntity(Project.class));
}
 
Example #29
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testCreateParameterBased() throws GitLabApiException {

    Project newProject = gitLabApi.getProjectApi().createProject(
            TEST_PROJECT_NAME_2, null, "GitLab4J test project.", true, true, true, true, Visibility.PUBLIC, null, null);
    assertNotNull(newProject);
    assertEquals(TEST_PROJECT_NAME_2, newProject.getName());
    assertEquals("GitLab4J test project.", newProject.getDescription());
    assertEquals(true, newProject.getIssuesEnabled());
    assertEquals(true, newProject.getMergeRequestsEnabled());
    assertEquals(true, newProject.getWikiEnabled());
    assertEquals(true, newProject.getSnippetsEnabled());
    assertTrue(Visibility.PUBLIC == newProject.getVisibility() || Boolean.TRUE == newProject.getPublic());
}
 
Example #30
Source File: TestPager.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testMembersPager() throws GitLabApiException {

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

    Pager<Member> pager = gitLabApi.getProjectApi().getMembers(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<Member> members = pager.next();

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

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

        for (Member member : members) {
            itemNumber++;
            System.out.format("page=%d, item=%d, name=%s, username=%s%n", pageIndex, itemNumber, member.getName(), member.getUsername());
        }
    }
}