diff --git a/README.md b/README.md
index 33453aa8620dd370485cda31c58dada424510a27..ae4d4b9f07f216116adf68c603a75379325b5d02 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,7 @@ To utilize GitLab4J™ API in your Java project, simply add the following de
```java
dependencies {
...
- compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.12.18'
+ compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.14.0'
}
```
@@ -64,7 +64,7 @@ dependencies {
org.gitlab4j
gitlab4j-api
- 4.12.18
+ 4.14.0
```
diff --git a/pom.xml b/pom.xml
index 7b4dcc793bd43d61164cbc9d0b4dda5c6af6524e..3e1269c85694e86278453ad658971bd7d8c24f5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.gitlab4j
gitlab4j-api
jar
- 4.12.19-SNAPSHOT
+ 4.14.0-SNAPSHOT
GitLab4J-API - GitLab API Java Client
GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.
https://github.com/gitlab4j/gitlab4j-api
diff --git a/src/main/java/org/gitlab4j/api/MergeRequestApi.java b/src/main/java/org/gitlab4j/api/MergeRequestApi.java
index b1f41e7e0da2e6168c2bbfa506bb98a02bf8e841..30c0a51072a71874a3bfec3cc0a9f60ed9e943f8 100644
--- a/src/main/java/org/gitlab4j/api/MergeRequestApi.java
+++ b/src/main/java/org/gitlab4j/api/MergeRequestApi.java
@@ -10,6 +10,9 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
+import org.gitlab4j.api.models.ApprovalRule;
+import org.gitlab4j.api.models.ApprovalRuleParams;
+import org.gitlab4j.api.models.ApprovalState;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.MergeRequest;
@@ -19,6 +22,8 @@ import org.gitlab4j.api.models.Participant;
/**
* This class implements the client side API for the GitLab merge request calls.
+ * @see Merge requests API at GitLab
+ * @see Merge request approvals API at GitLab
*/
public class MergeRequestApi extends AbstractApi {
@@ -664,7 +669,7 @@ public class MergeRequestApi extends AbstractApi {
/**
* Get the merge request with approval information.
*
- * Note: This API endpoint is only available on 8.9 EE and above.
+ * Note: This API endpoint is only available on 8.9 Starter and above.
*
*
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approvals
*
@@ -674,6 +679,22 @@ public class MergeRequestApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest getMergeRequestApprovals(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
+ return (getApprovals(projectIdOrPath, mergeRequestIid));
+ }
+
+ /**
+ * Get the merge request with approval information.
+ *
+ * Note: This API endpoint is only available on 8.9 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approvals
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @return a MergeRequest instance with approval information included
+ * @throws GitLabApiException if any exception occurs
+ */
+ public MergeRequest getApprovals(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
@@ -683,6 +704,162 @@ public class MergeRequestApi extends AbstractApi {
return (response.readEntity(MergeRequest.class));
}
+ /**
+ * Get the approval state of a merge request.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_state
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @return a ApprovalState instance with approval state
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ApprovalState getApprovalState(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
+
+ if (mergeRequestIid == null) {
+ throw new RuntimeException("mergeRequestIid cannot be null");
+ }
+
+ Response response = get(Response.Status.OK, null,
+ "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "approval_state");
+ return (response.readEntity(ApprovalState.class));
+ }
+
+ /**
+ * Get a list of the merge request level approval rules.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @return a List of ApprovalRule instances for the specified merge request.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public List getApprovalRules(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
+ return (getApprovalRules(projectIdOrPath, mergeRequestIid, -1).all());
+ }
+
+ /**
+ * Get a Pager of the merge request level approval rules.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @param itemsPerPage the number of ApprovalRule instances that will be fetched per page
+ * @return a Pager of ApprovalRule instances for the specified merge request.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public Pager getApprovalRules(Object projectIdOrPath, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException {
+
+ if (mergeRequestIid == null) {
+ throw new RuntimeException("mergeRequestIid cannot be null");
+ }
+
+ return (new Pager(this, ApprovalRule.class, itemsPerPage, null,
+ "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "approval_rules"));
+ }
+
+ /**
+ * Get a Stream of the merge request level approval rules.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @return a Stream of ApprovalRule instances for the specified merge request.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public Stream getApprovalRulesStream(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
+ return (getApprovalRules(projectIdOrPath, mergeRequestIid, -1).stream());
+ }
+
+ /**
+ * Create a merge request level approval rule.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: POST /projects/:id/merge_requests/:merge_request_iid/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @param projectRuleId the ID of a project-level approval rule
+ * @param params the ApprovalRuleParams instance holding the parameters for the approval rule
+ * @return a ApprovalRule instance with approval configuration
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ApprovalRule createApprovalRule(Object projectIdOrPath, Integer mergeRequestIid,
+ Integer projectRuleId, ApprovalRuleParams params) throws GitLabApiException {
+
+ if (mergeRequestIid == null) {
+ throw new RuntimeException("mergeRequestIid cannot be null");
+ }
+
+ GitLabApiForm formData = params.getForm();
+ formData.withParam("approval_project_rule_id", projectRuleId);
+ Response response = post(Response.Status.OK, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "approval_rules");
+ return (response.readEntity(ApprovalRule.class));
+ }
+
+ /**
+ * Update the specified the merge request level approval rule.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid/approval_rules/:approval_rule_id
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @param approvalRuleId the ID of the approval rule
+ * @param params the ApprovalRuleParams instance holding the parameters for the approval rule update
+ * @return a ApprovalRule instance with approval configuration
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ApprovalRule updateApprovalRule(Object projectIdOrPath, Integer mergeRequestIid,
+ Integer approvalRuleId, ApprovalRuleParams params) throws GitLabApiException {
+
+ if (mergeRequestIid == null) {
+ throw new RuntimeException("mergeRequestIid cannot be null");
+ }
+
+ if (approvalRuleId == null) {
+ throw new RuntimeException("approvalRuleId cannot be null");
+ }
+
+ GitLabApiForm formData = params.getForm();
+ Response response = putWithFormData(Response.Status.OK, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "approval_rules", approvalRuleId);
+ return (response.readEntity(ApprovalRule.class));
+ }
+
+ /**
+ * Delete the specified the merge request level approval rule.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: DELETE /projects/:id/merge_requests/:merge_request_iid/approval_rules/:approval_rule_id
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param mergeRequestIid the internal ID of the merge request
+ * @param approvalRuleId the ID of the approval rule
+ * @throws GitLabApiException if any exception occurs
+ */
+ public void deleteApprovalRule(Object projectIdOrPath, Integer mergeRequestIid, Integer approvalRuleId) throws GitLabApiException {
+
+ if (mergeRequestIid == null) {
+ throw new RuntimeException("mergeRequestIid cannot be null");
+ }
+
+ if (approvalRuleId == null) {
+ throw new RuntimeException("approvalRuleId cannot be null");
+ }
+
+ delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath),
+ "merge_requests", mergeRequestIid, "approval_rules", approvalRuleId);
+ }
+
/**
* Approve a merge request.
*
@@ -867,4 +1044,18 @@ public class MergeRequestApi extends AbstractApi {
public Stream getClosesIssuesStream(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
return (getClosesIssues(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}
+
+ /**
+ * Get list containing all the issues that would be closed by merging the provided merge request.
+ *
+ * GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/closes_issues
+ *
+ * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
+ * @param mergeRequestIid the IID of the merge request to get the closes issues for
+ * @return a List containing all the issues that would be closed by merging the provided merge request
+ * @throws GitLabApiException if any exception occurs
+ */
+ public List getApprovalStatus(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
+ return (getClosesIssues(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
+ }
}
diff --git a/src/main/java/org/gitlab4j/api/Pager.java b/src/main/java/org/gitlab4j/api/Pager.java
index a0c608e515f9b32c5d0277d008a8c47b368e4732..57fb1351a70d1384aed6d067fa76af8df67bc092 100644
--- a/src/main/java/org/gitlab4j/api/Pager.java
+++ b/src/main/java/org/gitlab4j/api/Pager.java
@@ -73,6 +73,10 @@ public class Pager implements Iterator>, Constants {
javaType = mapper.getTypeFactory().constructCollectionType(List.class, type);
+ if (itemsPerPage < 1) {
+ itemsPerPage = api.getDefaultPerPage();
+ }
+
// Make sure the per_page parameter is present
if (queryParams == null) {
queryParams = new GitLabApiForm().withParam(PER_PAGE_PARAM, itemsPerPage).asMap();
diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java
index c31c83b860b5373162f2b8219b8e78f2e0b19549..1299e5d0e65ec8ae14d82922a2b901108ca906c3 100644
--- a/src/main/java/org/gitlab4j/api/ProjectApi.java
+++ b/src/main/java/org/gitlab4j/api/ProjectApi.java
@@ -40,6 +40,8 @@ import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.AccessRequest;
+import org.gitlab4j.api.models.ApprovalRule;
+import org.gitlab4j.api.models.ApprovalRuleParams;
import org.gitlab4j.api.models.Badge;
import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.FileUpload;
@@ -47,6 +49,7 @@ import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Namespace;
import org.gitlab4j.api.models.Project;
+import org.gitlab4j.api.models.ProjectApprovalsConfig;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectFilter;
import org.gitlab4j.api.models.ProjectHook;
@@ -64,6 +67,8 @@ import org.gitlab4j.api.models.Visibility;
* @see Group and project members API at GitLab
* @see Group and project access requests API
* @see Project badges API
+ * @see
+ * Merge request approvals API (Project-level) at GitLab
*/
public class ProjectApi extends AbstractApi implements Constants {
@@ -3063,4 +3068,142 @@ public class ProjectApi extends AbstractApi implements Constants {
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "badges", "render");
return (response.readEntity(Badge.class));
}
+
+ /**
+ * Get the project's approval information.
+ * Note: This API endpoint is only available on 10.6 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/approvals
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @return a ProjectApprovalsConfig instance with the project's approvals configuration
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ProjectApprovalsConfig getApprovalsConfiguration(Object projectIdOrPath) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "approvals");
+ return (response.readEntity(ProjectApprovalsConfig.class));
+ }
+
+ /**
+ * Set the project's approvals configuration.
+ * Note: This API endpoint is only available on 10.6 Starter and above.
+ *
+ * GitLab Endpoint: POST /projects/:id/approvals
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param config a ProjectApprovalsConfig instance with the approval configuration
+ * @return a ProjectApprovalsConfig instance with the project's approvals configuration
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ProjectApprovalsConfig getApprovalsConfiguration(Object projectIdOrPath, ProjectApprovalsConfig config) throws GitLabApiException {
+ GitLabApiForm formData = config.getForm();
+ Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "approvals");
+ return (response.readEntity(ProjectApprovalsConfig.class));
+ }
+
+ /**
+ * Get a list of the project-level approval rules.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @return a List of ApprovalRuke instances for the specified project.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public List getApprovalRules(Object projectIdOrPath) throws GitLabApiException {
+ return (getApprovalRules(projectIdOrPath, -1).all());
+ }
+
+ /**
+ * Get a Pager of the project-level approval rules.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param itemsPerPage the number of ApprovalRule instances that will be fetched per page
+ * @return a Pager of ApprovalRuke instances for the specified project.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public Pager getApprovalRules(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
+
+ return (new Pager(this, ApprovalRule.class, itemsPerPage, null,
+ "projects", getProjectIdOrPath(projectIdOrPath), "approval_rules"));
+ }
+
+ /**
+ * Get a Stream of the project-level approval rules.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: GET /projects/:id/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @return a Stream of ApprovalRule instances for the specified project.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public Stream getApprovalRulesStream(Object projectIdOrPath) throws GitLabApiException {
+ return (getApprovalRules(projectIdOrPath, -1).stream());
+ }
+
+ /**
+ * Create a project-level approval rule.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: POST /projects/:id/approval_rules
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param params the ApprovalRuleParams instance holding the parameters for the approval rule
+ * @return a ApprovalRule instance with approval configuration
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ApprovalRule createApprovalRule(Object projectIdOrPath, ApprovalRuleParams params) throws GitLabApiException {
+ GitLabApiForm formData = params.getForm();
+ Response response = post(Response.Status.OK, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath), "approval_rules");
+ return (response.readEntity(ApprovalRule.class));
+ }
+
+ /**
+ * Update the specified the project-level approval rule.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: PUT /projects/:id/approval_rules/:approval_rule_id
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param approvalRuleId the ID of the approval rule
+ * @param params the ApprovalRuleParams instance holding the parameters for the approval rule update
+ * @return a ApprovalRule instance with approval configuration
+ * @throws GitLabApiException if any exception occurs
+ */
+ public ApprovalRule updateApprovalRule(Object projectIdOrPath, Integer approvalRuleId, ApprovalRuleParams params) throws GitLabApiException {
+
+ if (approvalRuleId == null) {
+ throw new RuntimeException("approvalRuleId cannot be null");
+ }
+
+ GitLabApiForm formData = params.getForm();
+ Response response = putWithFormData(Response.Status.OK, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath), "approval_rules", approvalRuleId);
+ return (response.readEntity(ApprovalRule.class));
+ }
+
+ /**
+ * Delete the specified the project-level approval rule.
+ * Note: This API endpoint is only available on 12.3 Starter and above.
+ *
+ * GitLab Endpoint: DELETE /projects/:id/approval_rules/:approval_rule_id
+ *
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param approvalRuleId the ID of the approval rule
+ * @throws GitLabApiException if any exception occurs
+ */
+ public void deleteApprovalRule(Object projectIdOrPath, Integer approvalRuleId) throws GitLabApiException {
+
+ if (approvalRuleId == null) {
+ throw new RuntimeException("approvalRuleId cannot be null");
+ }
+
+ delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "approval_rules", approvalRuleId);
+ }
}
diff --git a/src/main/java/org/gitlab4j/api/models/ApprovalRule.java b/src/main/java/org/gitlab4j/api/models/ApprovalRule.java
new file mode 100644
index 0000000000000000000000000000000000000000..ac1f3b8734225c0d6e49af7449f1ff86ea414111
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/ApprovalRule.java
@@ -0,0 +1,119 @@
+package org.gitlab4j.api.models;
+
+import java.util.List;
+
+import org.gitlab4j.api.utils.JacksonJson;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+public class ApprovalRule {
+
+ private Integer id;
+ private String name;
+ private String ruleType;
+ private List eligibleApprovers;
+ private Integer approvalsRequired;
+ private ApprovalRule sourceRule;
+ private List users;
+ private List groups;
+ private Boolean containsHiddenGroups;
+
+ @JsonSerialize(using = JacksonJson.UserListSerializer.class)
+ @JsonDeserialize(using = JacksonJson.UserListDeserializer.class)
+ private List approvedBy;
+ private Boolean approved;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getRuleType() {
+ return ruleType;
+ }
+
+ public void setRuleType(String ruleType) {
+ this.ruleType = ruleType;
+ }
+
+ public List getEligibleApprovers() {
+ return eligibleApprovers;
+ }
+
+ public void setEligibleApprovers(List eligibleApprovers) {
+ this.eligibleApprovers = eligibleApprovers;
+ }
+
+ public Integer getApprovalsRequired() {
+ return approvalsRequired;
+ }
+
+ public void setApprovalsRequired(Integer approvalsRequired) {
+ this.approvalsRequired = approvalsRequired;
+ }
+
+ public ApprovalRule getSourceRule() {
+ return sourceRule;
+ }
+
+ public void setSourceRule(ApprovalRule sourceRule) {
+ this.sourceRule = sourceRule;
+ }
+
+ public List getUsers() {
+ return users;
+ }
+
+ public void setUsers(List users) {
+ this.users = users;
+ }
+
+ public List getGroups() {
+ return groups;
+ }
+
+ public void setGroups(List groups) {
+ this.groups = groups;
+ }
+
+ public Boolean getContainsHiddenGroups() {
+ return containsHiddenGroups;
+ }
+
+ public void setContainsHiddenGroups(Boolean containsHiddenGroups) {
+ this.containsHiddenGroups = containsHiddenGroups;
+ }
+
+ public List getApprovedBy() {
+ return approvedBy;
+ }
+
+ public void setApprovedBy(List approvedBy) {
+ this.approvedBy = approvedBy;
+ }
+
+ public Boolean getApproved() {
+ return approved;
+ }
+
+ public void setApproved(Boolean approved) {
+ this.approved = approved;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+}
diff --git a/src/main/java/org/gitlab4j/api/models/ApprovalRuleParams.java b/src/main/java/org/gitlab4j/api/models/ApprovalRuleParams.java
new file mode 100644
index 0000000000000000000000000000000000000000..680a78cc08b0b2a627832914563455d96fcbd3b5
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/ApprovalRuleParams.java
@@ -0,0 +1,46 @@
+package org.gitlab4j.api.models;
+
+import java.util.List;
+
+import org.gitlab4j.api.GitLabApiForm;
+
+public class ApprovalRuleParams {
+
+ private String name;
+ private Integer approvalsRequired;
+ private List userIds;
+ private List groupIds;
+
+ public ApprovalRuleParams withName(String name) {
+ this.name = name;
+ return (this);
+ }
+
+ public ApprovalRuleParams withApprovalsRequired(Integer approvalsRequired) {
+ this.approvalsRequired = approvalsRequired;
+ return (this);
+ }
+
+ public ApprovalRuleParams withUserIds(List userIds) {
+ this.userIds = userIds;
+ return (this);
+ }
+
+ public ApprovalRuleParams withGroupIds(List groupIds) {
+ this.groupIds = groupIds;
+ return (this);
+ }
+
+ /**
+ * Get the form params specified by this instance.
+ *
+ * @return a GitLabApiForm instance holding the form parameters for this ApprovalRuleParams instance
+ */
+ public GitLabApiForm getForm() {
+ return new GitLabApiForm()
+ .withParam("name", name)
+ .withParam("approvals_required", approvalsRequired, true)
+ .withParam("user_ids", userIds)
+ .withParam("group_ids", groupIds);
+ }
+}
diff --git a/src/main/java/org/gitlab4j/api/models/ApprovalState.java b/src/main/java/org/gitlab4j/api/models/ApprovalState.java
new file mode 100644
index 0000000000000000000000000000000000000000..bc8ef912dbe043a2f16ee321c1caeec87ceea9c7
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/ApprovalState.java
@@ -0,0 +1,32 @@
+package org.gitlab4j.api.models;
+
+import java.util.List;
+
+import org.gitlab4j.api.utils.JacksonJson;
+
+public class ApprovalState {
+
+ private Boolean approvalRulesOverwritten;
+ private List rules;
+
+ public Boolean getApprovalRulesOverwritten() {
+ return approvalRulesOverwritten;
+ }
+
+ public void setApprovalRulesOverwritten(Boolean approvalRulesOverwritten) {
+ this.approvalRulesOverwritten = approvalRulesOverwritten;
+ }
+
+ public List getRules() {
+ return rules;
+ }
+
+ public void setRules(List rules) {
+ this.rules = rules;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+}
diff --git a/src/main/java/org/gitlab4j/api/models/ApprovedBy.java b/src/main/java/org/gitlab4j/api/models/ApprovedBy.java
new file mode 100644
index 0000000000000000000000000000000000000000..55271c90292eaa399e93ae102670c650250472f2
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/ApprovedBy.java
@@ -0,0 +1,51 @@
+
+package org.gitlab4j.api.models;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+/**
+ * This class is used by various models to represent the approved_by property,
+ * which can contain a User or Group instance.
+ *
+ * @since 4.19.0
+ */
+public class ApprovedBy {
+
+ private User user;
+ private Group group;
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ if (group != null) {
+ throw new RuntimeException("ApprovedBy is already set to a group, cannot be set to a user");
+ }
+
+ this.user = user;
+ }
+
+ public Group getGroup() {
+ return group;
+ }
+
+ public void setGroup(Group group) {
+ if (user != null) {
+ throw new RuntimeException("ApprovedBy is already set to a user, cannot be set to a group");
+ }
+
+ this.group = group;
+ }
+
+ /**
+ * Return the user or group that represents this ApprovedBy instance. Returned
+ * object will either be an instance of a User or Group.
+ *
+ * @return the user or group that represents this ApprovedBy instance
+ */
+ @JsonIgnore
+ public Object getApprovedBy() {
+ return (user != null ? user : group);
+ }
+}
diff --git a/src/main/java/org/gitlab4j/api/models/ProjectApprovalsConfig.java b/src/main/java/org/gitlab4j/api/models/ProjectApprovalsConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..5fa52f9f3bbd9bf66fd2d2d32b69d3a599ac834e
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/ProjectApprovalsConfig.java
@@ -0,0 +1,94 @@
+package org.gitlab4j.api.models;
+
+import org.gitlab4j.api.GitLabApiForm;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class ProjectApprovalsConfig {
+
+ private Integer approvalsBeforeMerge;
+ private Boolean resetApprovalsOnPush;
+ private Boolean disableOverridingApproversPerMergeRequest;
+ private Boolean mergeRequestsAuthorApproval;
+ private Boolean mergeRequestsDisableCommittersApproval;
+
+ public Integer getApprovalsBeforeMerge() {
+ return approvalsBeforeMerge;
+ }
+
+ public void setApprovalsBeforeMerge(Integer approvalsBeforeMerge) {
+ this.approvalsBeforeMerge = approvalsBeforeMerge;
+ }
+
+ public ProjectApprovalsConfig withApprovalsBeforeMerge(Integer approvalsBeforeMerge) {
+ this.approvalsBeforeMerge = approvalsBeforeMerge;
+ return (this);
+ }
+
+ public Boolean getResetApprovalsOnPush() {
+ return resetApprovalsOnPush;
+ }
+
+ public void setResetApprovalsOnPush(Boolean resetApprovalsOnPush) {
+ this.resetApprovalsOnPush = resetApprovalsOnPush;
+ }
+
+ public ProjectApprovalsConfig withResetApprovalsOnPush(Boolean resetApprovalsOnPush) {
+ this.resetApprovalsOnPush = resetApprovalsOnPush;
+ return (this);
+ }
+
+ public Boolean getDisableOverridingApproversPerMergeRequest() {
+ return disableOverridingApproversPerMergeRequest;
+ }
+
+ public void setDisableOverridingApproversPerMergeRequest(Boolean disableOverridingApproversPerMergeRequest) {
+ this.disableOverridingApproversPerMergeRequest = disableOverridingApproversPerMergeRequest;
+ }
+
+ public ProjectApprovalsConfig withDisableOverridingApproversPerMergeRequest(Boolean disableOverridingApproversPerMergeRequest) {
+ this.disableOverridingApproversPerMergeRequest = disableOverridingApproversPerMergeRequest;
+ return (this);
+ }
+
+ public Boolean getMergeRequestsAuthorApproval() {
+ return mergeRequestsAuthorApproval;
+ }
+
+ public void setMergeRequestsAuthorApproval(Boolean mergeRequestsAuthorApproval) {
+ this.mergeRequestsAuthorApproval = mergeRequestsAuthorApproval;
+ }
+
+ public ProjectApprovalsConfig withMergeRequestsAuthorApproval(Boolean mergeRequestsAuthorApproval) {
+ this.mergeRequestsAuthorApproval = mergeRequestsAuthorApproval;
+ return (this);
+ }
+
+ public Boolean getMergeRequestsDisableCommittersApproval() {
+ return mergeRequestsDisableCommittersApproval;
+ }
+
+ public void setMergeRequestsDisableCommittersApproval(Boolean mergeRequestsDisableCommittersApproval) {
+ this.mergeRequestsDisableCommittersApproval = mergeRequestsDisableCommittersApproval;
+ }
+
+ public ProjectApprovalsConfig withMergeRequestsDisableCommittersApproval(Boolean mergeRequestsDisableCommittersApproval) {
+ this.mergeRequestsDisableCommittersApproval = mergeRequestsDisableCommittersApproval;
+ return (this);
+ }
+
+ /**
+ * Get the form params specified by this instance.
+ *
+ * @return a GitLabApiForm instance holding the form parameters for this ProjectApprovalsConfig instance
+ */
+ @JsonIgnore
+ public GitLabApiForm getForm() {
+ return new GitLabApiForm()
+ .withParam("approvals_before_merge", approvalsBeforeMerge)
+ .withParam("reset_approvals_on_push", resetApprovalsOnPush)
+ .withParam("disable_overriding_approvers_per_merge_reques", disableOverridingApproversPerMergeRequest)
+ .withParam("merge_requests_author_approval", mergeRequestsAuthorApproval)
+ .withParam("merge_requests_disable_committers_approval", mergeRequestsDisableCommittersApproval);
+ }
+}
diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
index cb4f2b1c6b909104f7547a669a7ea43e5822b193..284d49b8b522f1a6d78748cde3322c311539e39a 100644
--- a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
+++ b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
@@ -36,6 +36,7 @@ import java.util.Map;
import org.gitlab4j.api.models.AccessRequest;
import org.gitlab4j.api.models.Application;
import org.gitlab4j.api.models.ApplicationSettings;
+import org.gitlab4j.api.models.ApprovalRule;
import org.gitlab4j.api.models.ArtifactsFile;
import org.gitlab4j.api.models.AwardEmoji;
import org.gitlab4j.api.models.Badge;
@@ -79,6 +80,7 @@ import org.gitlab4j.api.models.PackageFile;
import org.gitlab4j.api.models.Pipeline;
import org.gitlab4j.api.models.PipelineSchedule;
import org.gitlab4j.api.models.Project;
+import org.gitlab4j.api.models.ProjectApprovalsConfig;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
@@ -406,6 +408,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(variable, "project-variable-details.json"));
}
+ @Test
+ public void testProjectApprovalsCofig() throws Exception {
+ ProjectApprovalsConfig approvalsConfig = unmarshalResource(ProjectApprovalsConfig.class, "project-approvals-config.json");
+ assertTrue(compareJson(approvalsConfig, "project-approvals-config.json"));
+ }
+
@Test
public void testProtectedBranch() throws Exception {
ProtectedBranch protectedBranch = unmarshalResource(ProtectedBranch.class, "protected-branch.json");
@@ -479,6 +487,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(mergeRequestApprovals, "approvals.json"));
}
+ @Test
+ public void testMergeRequestApprovalRule() throws Exception {
+ ApprovalRule approvalRule = unmarshalResource(ApprovalRule.class, "approval-rule.json");
+ assertTrue(compareJson(approvalRule, "approval-rule.json"));
+ }
+
@Test
public void testMergeRequest() throws Exception {
MergeRequest mergeRequest = unmarshalResource(MergeRequest.class, "merge-request.json");
diff --git a/src/test/resources/org/gitlab4j/api/approval-rule.json b/src/test/resources/org/gitlab4j/api/approval-rule.json
new file mode 100644
index 0000000000000000000000000000000000000000..da210476362398712b36a1c8e8a1df5335dd4727
--- /dev/null
+++ b/src/test/resources/org/gitlab4j/api/approval-rule.json
@@ -0,0 +1,49 @@
+{
+ "id": 1,
+ "name": "security",
+ "rule_type": "regular",
+ "eligible_approvers": [
+ {
+ "id": 2,
+ "name": "John Doe",
+ "username": "jdoe",
+ "state": "active",
+ "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
+ "web_url": "http://localhost/jdoe"
+ },
+ {
+ "id": 50,
+ "name": "Group Member 1",
+ "username": "group_member_1",
+ "state": "active",
+ "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
+ "web_url": "http://localhost/group_member_1"
+ }
+ ],
+ "approvals_required": 1,
+ "users": [
+ {
+ "id": 2,
+ "name": "John Doe",
+ "username": "jdoe",
+ "state": "active",
+ "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
+ "web_url": "http://localhost/jdoe"
+ }
+ ],
+ "groups": [
+ {
+ "id": 5,
+ "name": "group1",
+ "path": "group1",
+ "description": "",
+ "visibility": "public",
+ "lfs_enabled": false,
+ "web_url": "http://localhost/groups/group1",
+ "request_access_enabled": false,
+ "full_name": "group1",
+ "full_path": "group1"
+ }
+ ],
+ "contains_hidden_groups": false
+}
\ No newline at end of file
diff --git a/src/test/resources/org/gitlab4j/api/approval-state.json b/src/test/resources/org/gitlab4j/api/approval-state.json
new file mode 100644
index 0000000000000000000000000000000000000000..24c16e8565335e538c4a5a17d7cf2398d2a79b16
--- /dev/null
+++ b/src/test/resources/org/gitlab4j/api/approval-state.json
@@ -0,0 +1,44 @@
+{
+ "approval_rules_overwritten": true,
+ "rules": [
+ {
+ "id": 1,
+ "name": "Ruby",
+ "rule_type": "regular",
+ "eligible_approvers": [
+ {
+ "id": 4,
+ "name": "John Doe",
+ "username": "jdoe",
+ "state": "active",
+ "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
+ "web_url": "http://localhost/jdoe"
+ }
+ ],
+ "approvals_required": 2,
+ "users": [
+ {
+ "id": 4,
+ "name": "John Doe",
+ "username": "jdoe",
+ "state": "active",
+ "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
+ "web_url": "http://localhost/jdoe"
+ }
+ ],
+ "groups": [],
+ "contains_hidden_groups": false,
+ "approved_by": [
+ {
+ "id": 4,
+ "name": "John Doe",
+ "username": "jdoe",
+ "state": "active",
+ "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
+ "web_url": "http://localhost/jdoe"
+ }
+ ],
+ "approved": true
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/org/gitlab4j/api/project-approvals-config.json b/src/test/resources/org/gitlab4j/api/project-approvals-config.json
new file mode 100644
index 0000000000000000000000000000000000000000..cec0d68c0bbc3ccc5185205668cdd4fc658f8472
--- /dev/null
+++ b/src/test/resources/org/gitlab4j/api/project-approvals-config.json
@@ -0,0 +1,7 @@
+{
+ "approvals_before_merge": 2,
+ "reset_approvals_on_push": true,
+ "disable_overriding_approvers_per_merge_request": false,
+ "merge_requests_author_approval": false,
+ "merge_requests_disable_committers_approval": false
+}
\ No newline at end of file