Skip to content

Added missing attributes for ProjectApi #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 109 additions & 2 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -1128,7 +1129,60 @@ public Project createProject(Project project, String importUrl) throws GitLabApi
.withParam("suggestion_commit_message", project.getSuggestionCommitMessage())
.withParam("remove_source_branch_after_merge", project.getRemoveSourceBranchAfterMerge())
.withParam("auto_devops_enabled", project.getAutoDevopsEnabled())
.withParam("squash_option", project.getSquashOption());
.withParam("squash_option", project.getSquashOption())
.withParam("use_custom_template", project.getUseCustomTemplate())
.withParam(
"external_authorization_classification_label",
project.getExternalAuthorizationClassificationLabel())
.withParam("group_runners_enabled", project.getGroupRunnersEnabled())
.withParam("show_default_award_emojis", project.getShowDefaultAwardEmojis())
.withParam(
"warn_about_potentially_unwanted_characters",
project.getWarnAboutPotentiallyUnwantedCharacters())
.withParam("mirror_trigger_builds", project.getMirrorTriggerBuilds())
.withParam("auto_cancel_pending_pipelines", project.getAutoCancelPendingPipelines())
.withParam("repository_object_format", project.getRepositoryObjectFormat())
.withParam(
"only_allow_merge_if_all_status_checks_passed",
project.getOnlyAllowMergeIfAllStatusChecksPassed())
.withParam("group_with_project_templates_id", project.getGroupWithProjectTemplatesId())
.withParam("public_builds", project.getPublicBuilds())
.withParam("build_timeout", project.getBuildTimeout())
.withParam("template_name", project.getTemplateName())
.withParam("emails_enabled", project.getEmailsEnabled())
.withParam("mirror", project.getMirror())
.withParam("analytics_access_level", project.getAnalyticsAccessLevel())
.withParam("builds_access_level", project.getBuildsAccessLevel())
.withParam("container_registry_access_level", project.getContainerRegistryAccessLevel())
.withParam("environments_access_level", project.getEnvironmentsAccessLevel())
.withParam("feature_flags_access_level", project.getFeatureFlagsAccessLevel())
.withParam("forking_access_level", project.getForkingAccessLevel())
.withParam("infrastructure_access_level", project.getInfrastructureAccessLevel())
.withParam("issues_access_level", project.getIssuesAccessLevel())
.withParam("merge_requests_access_level", project.getMergeRequestsAccessLevel())
.withParam("model_experiments_access_level", project.getModelExperimentsAccessLevel())
.withParam("model_registry_access_level", project.getModelRegistryAccessLevel())
.withParam("monitor_access_level", project.getMonitorAccessLevel())
.withParam("pages_access_level", project.getPagesAccessLevel())
.withParam("releases_access_level", project.getReleasesAccessLevel())
.withParam("repository_access_level", project.getRepositoryAccessLevel())
.withParam("requirements_access_level", project.getRequirementsAccessLevel())
.withParam("security_and_compliance_access_level", project.getSecurityAndComplianceAccessLevel())
.withParam("snippets_access_level", project.getSnippetsAccessLevel())
.withParam("wiki_access_level", project.getWikiAccessLevel());

if (project.getContainerExpirationPolicy() != null) {
Map<String, Object> attributes = new HashMap<>();
attributes.put("cadence", project.getContainerExpirationPolicy().getCadence());
attributes.put("enabled", project.getContainerExpirationPolicy().getEnabled());
attributes.put("keep_n", project.getContainerExpirationPolicy().getKeepN());
attributes.put("older_than", project.getContainerExpirationPolicy().getOlderThan());
attributes.put("name_regex", project.getContainerExpirationPolicy().getNameRegex());
attributes.put(
"name_regex_keep", project.getContainerExpirationPolicy().getNameRegexKeep());

formData.withParam("container_expiration_policy_attributes", attributes, false);
}

Namespace namespace = project.getNamespace();
if (namespace != null && namespace.getId() != null) {
Expand Down Expand Up @@ -1490,7 +1544,60 @@ public Project updateProject(Project project) throws GitLabApiException {
.withParam("merge_method", project.getMergeMethod())
.withParam("suggestion_commit_message", project.getSuggestionCommitMessage())
.withParam("remove_source_branch_after_merge", project.getRemoveSourceBranchAfterMerge())
.withParam("squash_option", project.getSquashOption());
.withParam("squash_option", project.getSquashOption())
.withParam("use_custom_template", project.getUseCustomTemplate())
.withParam(
"external_authorization_classification_label",
project.getExternalAuthorizationClassificationLabel())
.withParam("group_runners_enabled", project.getGroupRunnersEnabled())
.withParam("show_default_award_emojis", project.getShowDefaultAwardEmojis())
.withParam(
"warn_about_potentially_unwanted_characters",
project.getWarnAboutPotentiallyUnwantedCharacters())
.withParam("mirror_trigger_builds", project.getMirrorTriggerBuilds())
.withParam("auto_cancel_pending_pipelines", project.getAutoCancelPendingPipelines())
.withParam("repository_object_format", project.getRepositoryObjectFormat())
.withParam(
"only_allow_merge_if_all_status_checks_passed",
project.getOnlyAllowMergeIfAllStatusChecksPassed())
.withParam("group_with_project_templates_id", project.getGroupWithProjectTemplatesId())
.withParam("public_builds", project.getPublicBuilds())
.withParam("build_timeout", project.getBuildTimeout())
.withParam("template_name", project.getTemplateName())
.withParam("emails_enabled", project.getEmailsEnabled())
.withParam("mirror", project.getMirror())
.withParam("analytics_access_level", project.getAnalyticsAccessLevel())
.withParam("builds_access_level", project.getBuildsAccessLevel())
.withParam("container_registry_access_level", project.getContainerRegistryAccessLevel())
.withParam("environments_access_level", project.getEnvironmentsAccessLevel())
.withParam("feature_flags_access_level", project.getFeatureFlagsAccessLevel())
.withParam("forking_access_level", project.getForkingAccessLevel())
.withParam("infrastructure_access_level", project.getInfrastructureAccessLevel())
.withParam("issues_access_level", project.getIssuesAccessLevel())
.withParam("merge_requests_access_level", project.getMergeRequestsAccessLevel())
.withParam("model_experiments_access_level", project.getModelExperimentsAccessLevel())
.withParam("model_registry_access_level", project.getModelRegistryAccessLevel())
.withParam("monitor_access_level", project.getMonitorAccessLevel())
.withParam("pages_access_level", project.getPagesAccessLevel())
.withParam("releases_access_level", project.getReleasesAccessLevel())
.withParam("repository_access_level", project.getRepositoryAccessLevel())
.withParam("requirements_access_level", project.getRequirementsAccessLevel())
.withParam("security_and_compliance_access_level", project.getSecurityAndComplianceAccessLevel())
.withParam("snippets_access_level", project.getSnippetsAccessLevel())
.withParam("wiki_access_level", project.getWikiAccessLevel());

if (project.getContainerExpirationPolicy() != null) {
Map<String, Object> attributes = new HashMap<>();
attributes.put("cadence", project.getContainerExpirationPolicy().getCadence());
attributes.put("enabled", project.getContainerExpirationPolicy().getEnabled());
attributes.put("keep_n", project.getContainerExpirationPolicy().getKeepN());
attributes.put("older_than", project.getContainerExpirationPolicy().getOlderThan());
attributes.put("name_regex", project.getContainerExpirationPolicy().getNameRegex());
attributes.put(
"name_regex_keep", project.getContainerExpirationPolicy().getNameRegexKeep());

formData.withParam("container_expiration_policy_attributes", attributes, false);
}

if (isApiVersion(ApiVersion.V3)) {
formData.withParam("visibility_level", project.getVisibilityLevel());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.gitlab4j.api.models;

import java.io.Serializable;

import org.gitlab4j.models.utils.JacksonJson;

public class ContainerExpirationPolicy implements Serializable {
private static final long serialVersionUID = 1L;

private String cadence;
private Boolean enabled;
private Integer keepN;
private String olderThan;
private String nameRegex;
private String nameRegexKeep;

private String nextRunAt;

public String getCadence() {
return cadence;
}

public void setCadence(String cadence) {
this.cadence = cadence;
}

public ContainerExpirationPolicy withCadence(String cadence) {
this.cadence = cadence;
return this;
}

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public ContainerExpirationPolicy withEnabled(Boolean enabled) {
this.enabled = enabled;
return this;
}

public Integer getKeepN() {
return keepN;
}

public void setKeepN(Integer keepN) {
this.keepN = keepN;
}

public ContainerExpirationPolicy withKeepN(Integer keepN) {
this.keepN = keepN;
return this;
}

public String getOlderThan() {
return olderThan;
}

public void setOlderThan(String olderThan) {
this.olderThan = olderThan;
}

public ContainerExpirationPolicy withOlderThan(String olderThan) {
this.olderThan = olderThan;
return this;
}

public String getNameRegex() {
return nameRegex;
}

public void setNameRegex(String nameRegex) {
this.nameRegex = nameRegex;
}

public ContainerExpirationPolicy withNameRegex(String nameRegex) {
this.nameRegex = nameRegex;
return this;
}

public String getNameRegexKeep() {
return nameRegexKeep;
}

public void setNameRegexKeep(String nameRegexKeep) {
this.nameRegexKeep = nameRegexKeep;
}

public ContainerExpirationPolicy withNameRegexKeep(String nameRegexKeep) {
this.nameRegexKeep = nameRegexKeep;
return this;
}

public String getNextRunAt() {
return nextRunAt;
}

public void setNextRunAt(String nextRunAt) {
this.nextRunAt = nextRunAt;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Loading