Java Code Examples for org.gitlab4j.api.models.Project#getPublic()

The following examples show how to use org.gitlab4j.api.models.Project#getPublic() . 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: ProjectApi.java    From gitlab4j-api with MIT License 4 votes vote down vote up
/**
 * Updates a project. The following properties on the Project instance
 * are utilized in the edit of the project, null values are not updated:
 *
 * id (required) - existing project id, either id or path must be provided
 * name (optional) - project name
 * path (optional) - project path, either id or path must be provided
 * defaultBranch (optional) - master by default
 * description (optional) - short project description
 * visibility (optional) - Limit by visibility public, internal, or private
 * issuesEnabled (optional) - Enable issues for this project
 * mergeMethod (optional) - Set the merge method used
 * mergeRequestsEnabled (optional) - Enable merge requests for this project
 * wikiEnabled (optional) - Enable wiki for this project
 * snippetsEnabled (optional) - Enable snippets for this project
 * jobsEnabled (optional) - Enable jobs for this project
 * containerRegistryEnabled (optional) - Enable container registry for this project
 * sharedRunnersEnabled (optional) - Enable shared runners for this project
 * publicJobs (optional) - If true, jobs can be viewed by non-project-members
 * onlyAllowMergeIfPipelineSucceeds (optional) - Set whether merge requests can only be merged with successful jobs
 * onlyAllowMergeIfAllDiscussionsAreResolved (optional) - Set whether merge requests can only be merged when all the discussions are resolved
 * lfsEnabled (optional) - Enable LFS
 * requestAccessEnabled (optional) - Allow users to request member access
 * repositoryStorage (optional) - Which storage shard the repository is on. Available only to admins
 * approvalsBeforeMerge (optional) - How many approvers should approve merge request by default
 * printingMergeRequestLinkEnabled (optional) - Show link to create/view merge request when pushing from the command line
 * resolveOutdatedDiffDiscussions (optional) - Automatically resolve merge request diffs discussions on lines changed with a push
 * packagesEnabled (optional) - Enable or disable mvn packages repository feature
 *
 * NOTE: The following parameters specified by the GitLab API edit project are not supported:
 *     import_url
 *     tag_list array
 *     avatar
 *     ci_config_path
 *     initialize_with_readme
 *
 * @param project the Project instance with the configuration for the new project
 * @return a Project instance with the newly updated project info
 * @throws GitLabApiException if any exception occurs
 */
public Project updateProject(Project project) throws GitLabApiException {

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

    // This will throw an exception if both id and path are not present
    Object projectIdentifier = getProjectIdOrPath(project);

    GitLabApiForm formData = new GitLabApiForm()
        .withParam("name", project.getName())
        .withParam("path", project.getPath())
        .withParam("default_branch", project.getDefaultBranch())
        .withParam("description", project.getDescription())
        .withParam("issues_enabled", project.getIssuesEnabled())
        .withParam("merge_method",  project.getMergeMethod())
        .withParam("merge_requests_enabled", project.getMergeRequestsEnabled())
        .withParam("jobs_enabled", project.getJobsEnabled())
        .withParam("wiki_enabled", project.getWikiEnabled())
        .withParam("snippets_enabled", project.getSnippetsEnabled())
        .withParam("container_registry_enabled", project.getContainerRegistryEnabled())
        .withParam("shared_runners_enabled", project.getSharedRunnersEnabled())
        .withParam("public_jobs", project.getPublicJobs())
        .withParam("only_allow_merge_if_pipeline_succeeds", project.getOnlyAllowMergeIfPipelineSucceeds())
        .withParam("only_allow_merge_if_all_discussions_are_resolved", project.getOnlyAllowMergeIfAllDiscussionsAreResolved())
        .withParam("lfs_enabled", project.getLfsEnabled())
        .withParam("request_access_enabled", project.getRequestAccessEnabled())
        .withParam("repository_storage", project.getRepositoryStorage())
        .withParam("approvals_before_merge", project.getApprovalsBeforeMerge())
        .withParam("printing_merge_request_link_enabled", project.getPrintingMergeRequestLinkEnabled())
        .withParam("resolve_outdated_diff_discussions", project.getResolveOutdatedDiffDiscussions())
        .withParam("packages_enabled", project.getPackagesEnabled());

    if (isApiVersion(ApiVersion.V3)) {
        formData.withParam("visibility_level", project.getVisibilityLevel());
        boolean isPublic = (project.getPublic() != null ? project.getPublic() : project.getVisibility() == Visibility.PUBLIC);
        formData.withParam("public", isPublic);

        if (project.getTagList() != null && !project.getTagList().isEmpty()) {
            throw new IllegalArgumentException("GitLab API v3 does not support tag lists when updating projects");
        }
    } else {
        Visibility visibility = (project.getVisibility() != null ? project.getVisibility() :
            project.getPublic() == Boolean.TRUE ? Visibility.PUBLIC : null);
        formData.withParam("visibility", visibility);

        if (project.getTagList() != null && !project.getTagList().isEmpty()) {
            formData.withParam("tag_list", String.join(",", project.getTagList()));
        }
    }

    Response response = putWithFormData(Response.Status.OK, formData, "projects", projectIdentifier);
    return (response.readEntity(Project.class));
}