From 804c264135596274793d55a656b560289ff2c5f6 Mon Sep 17 00:00:00 2001 From: "Weimann, Simon" Date: Tue, 19 Dec 2023 13:48:42 +0100 Subject: [PATCH 1/2] add group api parameters - adds protected_against_pushes and full_protection_after_initial_push branch protection level - adds prevent_sharing_groups_outside_of_hierarchy - adds prevent_forking_outside_group --- .../org/gitlab4j/api/models/GroupParams.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/models/GroupParams.java b/src/main/java/org/gitlab4j/api/models/GroupParams.java index c196f24ea..779b00643 100644 --- a/src/main/java/org/gitlab4j/api/models/GroupParams.java +++ b/src/main/java/org/gitlab4j/api/models/GroupParams.java @@ -32,7 +32,9 @@ public String toString() { public enum DefaultBranchProtectionLevel { NOT_PROTECTED(0), PARTIALLY_PROTECTED(1), - FULLY_PROTECTED(2); + FULLY_PROTECTED(2), + PROTECTED_AGAINST_PUSHES(3), + FULL_PROTECTION_AFTER_INITIAL_PUSH(4); private final int value; @@ -63,6 +65,9 @@ public String toString() { private Integer extraSharedRunnersMinutesLimit; private DefaultBranchProtectionLevel defaultBranchProtection; + private Boolean preventSharingGroupsOutsideHierarchy; + private Boolean preventForkingOutsideGroup; + private Boolean membershipLock; private Long fileTemplateProjectId; @@ -179,6 +184,16 @@ public GroupParams withDefaultBranchProtection(DefaultBranchProtectionLevel defa return (this); } + public GroupParams withPreventSharingGroupsOutsideHierarchy(Boolean preventSharingGroupsOutsideHierarchy) { + this.preventSharingGroupsOutsideHierarchy = preventSharingGroupsOutsideHierarchy; + return (this); + } + + public GroupParams withPreventForkingOutsideGroup(Boolean preventForkingOutsideGroup) { + this.preventForkingOutsideGroup = preventForkingOutsideGroup; + return (this); + } + /** * Get the form params for a group create oir update call. * @@ -204,7 +219,9 @@ public GitLabApiForm getForm(boolean isCreate) { .withParam("request_access_enabled", requestAccessEnabled) .withParam("shared_runners_minutes_limit", sharedRunnersMinutesLimit) .withParam("extra_shared_runners_minutes_limit", extraSharedRunnersMinutesLimit) - .withParam("default_branch_protection", defaultBranchProtection); + .withParam("default_branch_protection", defaultBranchProtection) + .withParam("prevent_sharing_groups_outside_hierarchy", preventSharingGroupsOutsideHierarchy) + .withParam("prevent_forking_outside_group", preventForkingOutsideGroup); if (isCreate) { form.withParam("parent_id", parentId); From c7fcd88c4900f5685dcc6d5dd746741ad1486a6c Mon Sep 17 00:00:00 2001 From: Simon Weimann Date: Fri, 22 Dec 2023 13:46:36 +0100 Subject: [PATCH 2/2] extend groupApi to return more details - default_branch_protection - subgroup_creation_level - project_creation_level - prevent_forking_outside_group - prevent_sharing_groups_outside_hierarchy --- src/main/java/org/gitlab4j/api/Constants.java | 68 ++++++++++ .../java/org/gitlab4j/api/models/Group.java | 74 +++++++++++ .../org/gitlab4j/api/models/GroupParams.java | 119 ++++++------------ .../resources/org/gitlab4j/api/group.json | 5 + 4 files changed, 188 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/Constants.java b/src/main/java/org/gitlab4j/api/Constants.java index b6c8f7834..f51047ef2 100644 --- a/src/main/java/org/gitlab4j/api/Constants.java +++ b/src/main/java/org/gitlab4j/api/Constants.java @@ -1029,5 +1029,73 @@ public String toString() { return (enumHelper.toString(this)); } } + + /** + * Constant to specify the project_creation_level for the group. + */ + public enum ProjectCreationLevel { + NOONE, DEVELOPER, MAINTAINER; + + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(ProjectCreationLevel.class); + + @JsonCreator + public static ProjectCreationLevel forValue(String value) { + return enumHelper.forValue(value); + } + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } + + /** + * Constant to specify the subgroup_creation_level for the group. + */ + public enum SubgroupCreationLevel { + OWNER, MAINTAINER; + + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(SubgroupCreationLevel.class); + + @JsonCreator + public static SubgroupCreationLevel forValue(String value) { + return enumHelper.forValue(value); + } + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } + + public enum DefaultBranchProtectionLevel { + NOT_PROTECTED(0), + PARTIALLY_PROTECTED(1), + FULLY_PROTECTED(2), + PROTECTED_AGAINST_PUSHES(3), + FULL_PROTECTION_AFTER_INITIAL_PUSH(4); + + @JsonValue + private final int value; + + private DefaultBranchProtectionLevel(int value) { + this.value = value; + } + + @Override + public String toString() { + return Integer.toString(value); + } + } } diff --git a/src/main/java/org/gitlab4j/api/models/Group.java b/src/main/java/org/gitlab4j/api/models/Group.java index 4df3895b9..a1f196080 100644 --- a/src/main/java/org/gitlab4j/api/models/Group.java +++ b/src/main/java/org/gitlab4j/api/models/Group.java @@ -2,6 +2,10 @@ package org.gitlab4j.api.models; import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import org.gitlab4j.api.Constants.DefaultBranchProtectionLevel; +import org.gitlab4j.api.Constants.ProjectCreationLevel; +import org.gitlab4j.api.Constants.SubgroupCreationLevel; import org.gitlab4j.api.utils.JacksonJson; import java.util.Date; @@ -62,6 +66,11 @@ public void setJobArtifactsSize(Long jobArtifactsSize) { private Date createdAt; private List sharedWithGroups; private String runnersToken; + private Boolean preventSharingGroupsOutsideHierarchy; + private Boolean preventForkingOutsideGroup; + private ProjectCreationLevel projectCreationLevel; + private SubgroupCreationLevel subgroupCreationLevel; + private DefaultBranchProtectionLevel defaultBranchProtection; @JsonSerialize(using = JacksonJson.DateOnlySerializer.class) private Date markedForDeletionOn; @@ -178,6 +187,46 @@ public void setRunnersToken(String runnersToken) { this.runnersToken = runnersToken; } + public Boolean getPreventSharingGroupsOutsideHierarchy() { + return preventSharingGroupsOutsideHierarchy; + } + + public void setPreventSharingGroupsOutsideHierarchy(Boolean preventSharingGroupsOutsideHierarchy) { + this.preventSharingGroupsOutsideHierarchy = preventSharingGroupsOutsideHierarchy; + } + + public Boolean getPreventForkingOutsideGroup() { + return preventForkingOutsideGroup; + } + + public void setPreventForkingOutsideGroup(Boolean preventForkingOutsideGroup) { + this.preventForkingOutsideGroup = preventForkingOutsideGroup; + } + + public ProjectCreationLevel getProjectCreationLevel() { + return this.projectCreationLevel; + } + + public void setProjectCreationLevel(ProjectCreationLevel projectCreationLevel) { + this.projectCreationLevel = projectCreationLevel; + } + + public SubgroupCreationLevel getSubgroupCreationLevel() { + return this.subgroupCreationLevel; + } + + public void setSubgroupCreationLevel(SubgroupCreationLevel subgroupCreationLevel) { + this.subgroupCreationLevel = subgroupCreationLevel; + } + + public DefaultBranchProtectionLevel getDefaultBranchProtection() { + return this.defaultBranchProtection; + } + + public void setDefaultBranchProtection(DefaultBranchProtectionLevel defaultBranchProtection) { + this.defaultBranchProtection = defaultBranchProtection; + } + public Group withPath(String path) { this.path = path; return this; @@ -228,6 +277,31 @@ public Group withSharedProjects(List sharedProjects) { return this; } + public Group withPreventSharingGroupsOutsideHierarchy(Boolean preventSharingGroupsOutsideHierarchy) { + this.preventSharingGroupsOutsideHierarchy = preventSharingGroupsOutsideHierarchy; + return this; + } + + public Group withPreventForkingOutsideGroup(Boolean preventForkingOutsideGroup) { + this.preventForkingOutsideGroup = preventForkingOutsideGroup; + return this; + } + + public Group withProjectCreationLevel(ProjectCreationLevel projectCreationLevel) { + this.projectCreationLevel = projectCreationLevel; + return this; + } + + public Group withSubgroupCreationLevel(SubgroupCreationLevel subgroupCreationLevel) { + this.subgroupCreationLevel = subgroupCreationLevel; + return this; + } + + public Group withDefaultBranchProtection(DefaultBranchProtectionLevel defaultBranchProtection) { + this.defaultBranchProtection = defaultBranchProtection; + return this; + } + @Override public String toString() { return (JacksonJson.toJsonString(this)); diff --git a/src/main/java/org/gitlab4j/api/models/GroupParams.java b/src/main/java/org/gitlab4j/api/models/GroupParams.java index 779b00643..e293bd088 100644 --- a/src/main/java/org/gitlab4j/api/models/GroupParams.java +++ b/src/main/java/org/gitlab4j/api/models/GroupParams.java @@ -1,6 +1,9 @@ package org.gitlab4j.api.models; import org.gitlab4j.api.GitLabApiForm; +import org.gitlab4j.api.Constants.DefaultBranchProtectionLevel; +import org.gitlab4j.api.Constants.ProjectCreationLevel; +import org.gitlab4j.api.Constants.SubgroupCreationLevel; /** * This class is utilized by the {@link org.gitlab4j.api.GroupApi#createGroup(GroupParams)} @@ -9,44 +12,6 @@ */ public class GroupParams { - /** - * Constant to specify the project_creation_level for the group. - */ - public enum ProjectCreationLevel { - NOONE, DEVELOPER, MAINTAINER; - public String toString() { - return (name().toLowerCase()); - } - } - - /** - * Constant to specify the subgroup_creation_level for the group. - */ - public enum SubgroupCreationLevel { - OWNER, MAINTAINER; - public String toString() { - return (name().toLowerCase()); - } - } - - public enum DefaultBranchProtectionLevel { - NOT_PROTECTED(0), - PARTIALLY_PROTECTED(1), - FULLY_PROTECTED(2), - PROTECTED_AGAINST_PUSHES(3), - FULL_PROTECTION_AFTER_INITIAL_PUSH(4); - - private final int value; - - private DefaultBranchProtectionLevel(int value) { - this.value = value; - } - - public String toString() { - return Integer.toString(value); - } - } - private String name; private String path; private String description; @@ -64,10 +29,8 @@ public String toString() { private Integer sharedRunnersMinutesLimit; private Integer extraSharedRunnersMinutesLimit; private DefaultBranchProtectionLevel defaultBranchProtection; - private Boolean preventSharingGroupsOutsideHierarchy; private Boolean preventForkingOutsideGroup; - private Boolean membershipLock; private Long fileTemplateProjectId; @@ -78,8 +41,8 @@ public String toString() { * @return this GroupParms instance */ public GroupParams withParentId(Long parentId) { - this.parentId = parentId; - return (this); + this.parentId = parentId; + return (this); } /** @@ -89,8 +52,8 @@ public GroupParams withParentId(Long parentId) { * @return this GroupParms instance */ public GroupParams withMembershipLock(Boolean membershipLock) { - this.membershipLock = membershipLock; - return (this); + this.membershipLock = membershipLock; + return (this); } /** @@ -100,88 +63,88 @@ public GroupParams withMembershipLock(Boolean membershipLock) { * @return this GroupParms instance */ public GroupParams withFileTemplateProjectId(Long fileTemplateProjectId) { - this.fileTemplateProjectId = fileTemplateProjectId; - return (this); + this.fileTemplateProjectId = fileTemplateProjectId; + return (this); } public GroupParams withName(String name) { - this.name = name; - return (this); + this.name = name; + return (this); } public GroupParams withPath(String path) { - this.path = path; - return (this); + this.path = path; + return (this); } public GroupParams withDescription(String description) { - this.description = description; - return (this); + this.description = description; + return (this); } public GroupParams withVisibility(String visibility) { - this.visibility = visibility; - return (this); + this.visibility = visibility; + return (this); } public GroupParams withShareWithGroupLock(Boolean shareWithGroupLock) { - this.shareWithGroupLock = shareWithGroupLock; - return (this); + this.shareWithGroupLock = shareWithGroupLock; + return (this); } public GroupParams withRequireTwoFactorAuthentication(Boolean requireTwoFactorAuthentication) { - this.requireTwoFactorAuthentication = requireTwoFactorAuthentication; - return (this); + this.requireTwoFactorAuthentication = requireTwoFactorAuthentication; + return (this); } public GroupParams withTwoFactorGracePeriod(Integer twoFactorGracePeriod) { - this.twoFactorGracePeriod = twoFactorGracePeriod; - return (this); + this.twoFactorGracePeriod = twoFactorGracePeriod; + return (this); } public GroupParams withProjectCreationLevel(ProjectCreationLevel projectCreationLevel) { - this.projectCreationLevel = projectCreationLevel; - return (this); + this.projectCreationLevel = projectCreationLevel; + return (this); } public GroupParams withAutoDevopsEnabled(Boolean autoDevopsEnabled) { - this.autoDevopsEnabled = autoDevopsEnabled; - return (this); + this.autoDevopsEnabled = autoDevopsEnabled; + return (this); } public GroupParams withSubgroupCreationLevel(SubgroupCreationLevel subgroupCreationLevel) { - this.subgroupCreationLevel = subgroupCreationLevel; - return (this); + this.subgroupCreationLevel = subgroupCreationLevel; + return (this); } public GroupParams withEmailsDisabled(Boolean emailsDisabled) { - this.emailsDisabled = emailsDisabled; - return (this); + this.emailsDisabled = emailsDisabled; + return (this); } public GroupParams withLfsEnabled(Boolean lfsEnabled) { - this.lfsEnabled = lfsEnabled; - return (this); + this.lfsEnabled = lfsEnabled; + return (this); } public GroupParams withRequestAccessEnabled(Boolean requestAccessEnabled) { - this.requestAccessEnabled = requestAccessEnabled; - return (this); + this.requestAccessEnabled = requestAccessEnabled; + return (this); } public GroupParams withSharedRunnersMinutesLimit(Integer sharedRunnersMinutesLimit) { - this.sharedRunnersMinutesLimit = sharedRunnersMinutesLimit; - return (this); + this.sharedRunnersMinutesLimit = sharedRunnersMinutesLimit; + return (this); } public GroupParams withExtraSharedRunnersMinutesLimit(Integer extraSharedRunnersMinutesLimit) { - this.extraSharedRunnersMinutesLimit = extraSharedRunnersMinutesLimit; - return (this); + this.extraSharedRunnersMinutesLimit = extraSharedRunnersMinutesLimit; + return (this); } public GroupParams withDefaultBranchProtection(DefaultBranchProtectionLevel defaultBranchProtection) { - this.defaultBranchProtection = defaultBranchProtection; - return (this); + this.defaultBranchProtection = defaultBranchProtection; + return (this); } public GroupParams withPreventSharingGroupsOutsideHierarchy(Boolean preventSharingGroupsOutsideHierarchy) { diff --git a/src/test/resources/org/gitlab4j/api/group.json b/src/test/resources/org/gitlab4j/api/group.json index ea84f6e07..ab0d99d5e 100644 --- a/src/test/resources/org/gitlab4j/api/group.json +++ b/src/test/resources/org/gitlab4j/api/group.json @@ -6,6 +6,11 @@ "visibility": "public", "web_url": "https://gitlab.example.com/groups/twitter", "request_access_enabled": false, + "prevent_sharing_groups_outside_hierarchy": false, + "prevent_forking_outside_group": false, + "project_creation_level": "developer", + "subgroup_creation_level": "owner", + "default_branch_protection": 2, "full_name": "Twitter", "full_path": "twitter", "parent_id": 1234,