getAuditEventsStream(Object groupIdOrPath, Date created_after, Date created_before) throws GitLabApiException {
+ return (getAuditEvents(groupIdOrPath, created_after, created_before, getDefaultPerPage()).stream());
+ }
+
+ /**
+ * Get a specific audit event of a group.
+ *
+ * GitLab Endpoint: GET /groups/:id/audit_events/:id_audit_event
+ *
+ * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
+ * @param auditEventId the auditEventId, required
+ * @return the group Audit event
+ * @throws GitLabApiException if any exception occurs
+ */
+ public AuditEvent getAuditEvent(Object groupIdOrPath, Integer auditEventId) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "audit_events", auditEventId);
+ return (response.readEntity(AuditEvent.class));
+ }
+
/**
* Get a List of the group access requests viewable by the authenticated user.
*
diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java
index e63b176dbcbcce8e8072e08f3e7686fe08762cdc..9a645f419dae912368bc64f163fa372be96dd542 100644
--- a/src/main/java/org/gitlab4j/api/ProjectApi.java
+++ b/src/main/java/org/gitlab4j/api/ProjectApi.java
@@ -23,25 +23,12 @@
package org.gitlab4j.api;
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import javax.ws.rs.core.Form;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MultivaluedMap;
-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.AuditEvent;
import org.gitlab4j.api.models.Badge;
import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.FileUpload;
@@ -58,16 +45,31 @@ import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
+import org.gitlab4j.api.utils.ISO8601;
+
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Stream;
/**
* This class provides an entry point to all the GitLab API project calls.
- *
+ *
* @see Projects API at GitLab
* @see Project statistics API
* @see Group and project members API at GitLab
* @see Group and project access requests API
* @see Project badges API
* @see
+ * @see Project audit events API
* Merge request approvals API (Project-level) at GitLab
*/
public class ProjectApi extends AbstractApi implements Constants {
@@ -1559,7 +1561,7 @@ public class ProjectApi extends AbstractApi implements Constants {
return (GitLabApi.createOptionalFromException(glae));
}
}
-
+
/**
* Gets a project team member, optionally including inherited member.
*
@@ -2732,6 +2734,71 @@ public class ProjectApi extends AbstractApi implements Constants {
return (response.readEntity(Project.class));
}
+ /**
+ * Get a List of the project audit events viewable by Maintainer or an Owner of the group.
+ *
+ * GET /projects/:id/audit_events
+ *
+ * @param projectIdOrPath the project ID, path of the project, or a project instance holding the project ID or path
+ * @param created_after Project audit events created on or after the given time.
+ * @param created_before Project audit events created on or before the given time.
+ * @return a List of project Audit events
+ * @throws GitLabApiException if any exception occurs
+ */
+ public List getAuditEvents(Object projectIdOrPath, Date created_after, Date created_before) throws GitLabApiException {
+ return (getAuditEvents(projectIdOrPath, created_after, created_before, getDefaultPerPage()).all());
+ }
+
+ /**
+ * Get a Pager of the group audit events viewable by Maintainer or an Owner of the group.
+ *
+ * GET /projects/:id/audit_events
+ *
+ * @param projectIdOrPath the project ID, path of the project, or a Project instance holding the project ID or path
+ * @param created_after Project audit events created on or after the given time.
+ * @param created_before Project audit events created on or before the given time.
+ * @param itemsPerPage the number of Audit Event instances that will be fetched per page
+ * @return a Pager of project Audit events
+ * @throws GitLabApiException if any exception occurs
+ */
+ public Pager getAuditEvents(Object projectIdOrPath, Date created_after, Date created_before, int itemsPerPage) throws GitLabApiException {
+ Form form = new GitLabApiForm()
+ .withParam("created_before", ISO8601.toString(created_before, false))
+ .withParam("created_after", ISO8601.toString(created_after, false));
+ return (new Pager(this, AuditEvent.class, itemsPerPage, form.asMap(),
+ "projects", getProjectIdOrPath(projectIdOrPath), "audit_events"));
+ }
+
+ /**
+ * Get a Stream of the group audit events viewable by Maintainer or an Owner of the group.
+ *
+ * GET /projects/:id/audit_events
+ *
+ * @param projectIdOrPath the project ID, path of the project, or a Project instance holding the project ID or path
+ * @param created_after Project audit events created on or after the given time.
+ * @param created_before Project audit events created on or before the given time.
+ * @return a Stream of project Audit events
+ * @throws GitLabApiException if any exception occurs
+ */
+ public Stream getAuditEventsStream(Object projectIdOrPath, Date created_after, Date created_before) throws GitLabApiException {
+ return (getAuditEvents(projectIdOrPath, created_after, created_before, getDefaultPerPage()).stream());
+ }
+
+ /**
+ * Get a specific audit event of a project.
+ *
+ * GitLab Endpoint: GET /projects/:id/audit_events/:id_audit_event
+ *
+ * @param projectIdOrPath the project ID, path of the project, or a Project instance holding the project ID or path
+ * @param auditEventId the auditEventId, required
+ * @return the project Audit event
+ * @throws GitLabApiException if any exception occurs
+ */
+ public AuditEvent getAuditEvent(Object projectIdOrPath, Integer auditEventId) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "audit_events", auditEventId);
+ return (response.readEntity(AuditEvent.class));
+ }
+
/**
* Get list of a project's variables.
*
@@ -2867,7 +2934,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param value the value for the variable, required
* @param variableType the type of variable. Available types are: env_var (default) and file
* @param isProtected whether the variable is protected, optional
- * @param isMasked whether the variable is masked, optional
+ * @param isMasked whether the variable is masked, optional
* @return a Variable instance with the newly created variable
* @throws GitLabApiException if any exception occurs during execution
*/
@@ -2888,7 +2955,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param value the value for the variable, required
* @param variableType the type of variable. Available types are: env_var (default) and file
* @param isProtected whether the variable is protected, optional
- * @param isMasked whether the variable is masked, optional
+ * @param isMasked whether the variable is masked, optional
* @param environmentScope the environment_scope of the variable, optional
* @return a Variable instance with the newly created variable
* @throws GitLabApiException if any exception occurs during execution
diff --git a/src/main/java/org/gitlab4j/api/models/AuditEvent.java b/src/main/java/org/gitlab4j/api/models/AuditEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..05d6c2e0cb3f953496af2efab6e88f7bfb2b1df2
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/AuditEvent.java
@@ -0,0 +1,69 @@
+
+package org.gitlab4j.api.models;
+
+import org.gitlab4j.api.utils.JacksonJson;
+
+import java.util.Date;
+
+public class AuditEvent {
+
+ private Integer id;
+ private Integer authorId;
+ private Integer entityId;
+ private String entityType;
+ private AuditEventDetail details;
+ private Date createdAt;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Integer getAuthorId() {
+ return authorId;
+ }
+
+ public void setAuthorId(Integer authorId) {
+ this.authorId = authorId;
+ }
+
+ public Integer getEntityId() {
+ return entityId;
+ }
+
+ public void setEntityId(Integer entityId) {
+ this.entityId = entityId;
+ }
+
+ public String getEntityType() {
+ return entityType;
+ }
+
+ public void setEntityType(String entityType) {
+ this.entityType = entityType;
+ }
+
+ public AuditEventDetail getDetails() {
+ return details;
+ }
+
+ public void setDetails(AuditEventDetail details) {
+ this.details = details;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+}
diff --git a/src/main/java/org/gitlab4j/api/models/AuditEventDetail.java b/src/main/java/org/gitlab4j/api/models/AuditEventDetail.java
new file mode 100644
index 0000000000000000000000000000000000000000..cc4af61dcb9a50c27484f2a5934e88965839e75f
--- /dev/null
+++ b/src/main/java/org/gitlab4j/api/models/AuditEventDetail.java
@@ -0,0 +1,112 @@
+
+package org.gitlab4j.api.models;
+
+import org.gitlab4j.api.utils.JacksonJson;
+
+public class AuditEventDetail {
+
+ private String change;
+ private String from;
+ private String to;
+ private String add;
+ private String customMessage;
+ private String authorName;
+ private Object targetId;
+ private String targetType;
+ private String targetDetails;
+ private String ipAddress;
+ private String entityPath;
+
+ public String getCustomMessage() {
+ return customMessage;
+ }
+
+ public void setCustomMessage(String customMessage) {
+ this.customMessage = customMessage;
+ }
+
+ public String getAuthorName() {
+ return authorName;
+ }
+
+ public void setAuthorName(String authorName) {
+ this.authorName = authorName;
+ }
+
+ public Object getTargetId() {
+ return targetId;
+ }
+
+ public void setTargetId(Object targetId) {
+ this.targetId = targetId;
+ }
+
+ public String getTargetType() {
+ return targetType;
+ }
+
+ public void setTargetType(String targetType) {
+ this.targetType = targetType;
+ }
+
+ public String getTargetDetails() {
+ return targetDetails;
+ }
+
+ public void setTargetDetails(String targetDetails) {
+ this.targetDetails = targetDetails;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
+ public void setIpAddress(String ipAddress) {
+ this.ipAddress = ipAddress;
+ }
+
+ public String getEntityPath() {
+ return entityPath;
+ }
+
+ public void setEntityPath(String entityPath) {
+ this.entityPath = entityPath;
+ }
+
+ public String getChange() {
+ return change;
+ }
+
+ public void setChange(String change) {
+ this.change = change;
+ }
+
+ public String getFrom() {
+ return from;
+ }
+
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ public String getTo() {
+ return to;
+ }
+
+ public void setTo(String to) {
+ this.to = to;
+ }
+
+ public String getAdd() {
+ return add;
+ }
+
+ public void setAdd(String add) {
+ this.add = add;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+}
diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
index 668c336ca24f734632aa6355bc7cbd4890e1754e..b90dc35c4cb7324e5babcb05f7a7fad44b79403c 100644
--- a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
+++ b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
@@ -23,21 +23,13 @@
package org.gitlab4j.api;
-import static org.gitlab4j.api.JsonUtils.compareJson;
-import static org.gitlab4j.api.JsonUtils.readTreeFromResource;
-import static org.gitlab4j.api.JsonUtils.unmarshalResource;
-import static org.gitlab4j.api.JsonUtils.unmarshalResourceList;
-import static org.gitlab4j.api.JsonUtils.unmarshalResourceMap;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import java.util.Map;
-
+import com.fasterxml.jackson.databind.JsonNode;
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.AuditEvent;
import org.gitlab4j.api.models.AwardEmoji;
import org.gitlab4j.api.models.Badge;
import org.gitlab4j.api.models.Blame;
@@ -111,7 +103,15 @@ import org.gitlab4j.api.services.JiraService;
import org.gitlab4j.api.services.SlackService;
import org.junit.Test;
-import com.fasterxml.jackson.databind.JsonNode;
+import java.util.List;
+import java.util.Map;
+
+import static org.gitlab4j.api.JsonUtils.compareJson;
+import static org.gitlab4j.api.JsonUtils.readTreeFromResource;
+import static org.gitlab4j.api.JsonUtils.unmarshalResource;
+import static org.gitlab4j.api.JsonUtils.unmarshalResourceList;
+import static org.gitlab4j.api.JsonUtils.unmarshalResourceMap;
+import static org.junit.Assert.assertTrue;
public class TestGitLabApiBeans {
@@ -127,6 +127,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(applications, "applications.json"));
}
+ @Test
+ public void testAuditEvent() throws Exception {
+ List auditEvents = unmarshalResourceList(AuditEvent.class, "audit-events.json");
+ assertTrue(compareJson(auditEvents, "audit-events.json"));
+ }
+
@Test
public void testAwardEmoji() throws Exception {
AwardEmoji awardEmoji = unmarshalResource(AwardEmoji.class, "award-emoji.json");
diff --git a/src/test/resources/org/gitlab4j/api/audit-events.json b/src/test/resources/org/gitlab4j/api/audit-events.json
new file mode 100644
index 0000000000000000000000000000000000000000..aad859b7afe3f1ea077ece6af60650aa425fcf17
--- /dev/null
+++ b/src/test/resources/org/gitlab4j/api/audit-events.json
@@ -0,0 +1,51 @@
+[
+ {
+ "id": 1,
+ "author_id": 1,
+ "entity_id": 6,
+ "entity_type": "Project",
+ "details": {
+ "custom_message": "Project archived",
+ "author_name": "Administrator",
+ "target_id": "flightjs/flight",
+ "target_type": "Project",
+ "target_details": "flightjs/flight",
+ "ip_address": "127.0.0.1",
+ "entity_path": "flightjs/flight"
+ },
+ "created_at": "2019-08-30T07:00:41.885Z"
+ },
+ {
+ "id": 2,
+ "author_id": 1,
+ "entity_id": 60,
+ "entity_type": "Group",
+ "details": {
+ "add": "group",
+ "author_name": "Administrator",
+ "target_id": "flightjs",
+ "target_type": "Group",
+ "target_details": "flightjs",
+ "ip_address": "127.0.0.1",
+ "entity_path": "flightjs"
+ },
+ "created_at": "2019-08-27T18:36:44.162Z"
+ },
+ {
+ "id": 3,
+ "author_id": 51,
+ "entity_id": 51,
+ "entity_type": "User",
+ "details": {
+ "change": "email address",
+ "from": "hello@flightjs.com",
+ "to": "maintainer@flightjs.com",
+ "author_name": "Andreas",
+ "target_id": 51,
+ "target_type": "User",
+ "target_details": "Andreas",
+ "entity_path": "Andreas"
+ },
+ "created_at": "2019-08-22T16:34:25.639Z"
+ }
+]
diff --git a/src/test/resources/org/gitlab4j/api/project-audit-events.json b/src/test/resources/org/gitlab4j/api/project-audit-events.json
new file mode 100644
index 0000000000000000000000000000000000000000..a0b971e4f41f2052d588b6f673ebd7723c30eedf
--- /dev/null
+++ b/src/test/resources/org/gitlab4j/api/project-audit-events.json
@@ -0,0 +1,38 @@
+[
+ {
+ "id": 5,
+ "author_id": 1,
+ "entity_id": 7,
+ "entity_type": "Project",
+ "details": {
+ "change": "prevent merge request approval from reviewers",
+ "from": "",
+ "to": "true",
+ "author_name": "Administrator",
+ "target_id": 7,
+ "target_type": "Project",
+ "target_details": "twitter/typeahead-js",
+ "ip_address": "127.0.0.1",
+ "entity_path": "twitter/typeahead-js"
+ },
+ "created_at": "2020-05-26T22:55:04.230Z"
+ },
+ {
+ "id": 4,
+ "author_id": 1,
+ "entity_id": 7,
+ "entity_type": "Project",
+ "details": {
+ "change": "prevent merge request approval from authors",
+ "from": "false",
+ "to": "true",
+ "author_name": "Administrator",
+ "target_id": 7,
+ "target_type": "Project",
+ "target_details": "twitter/typeahead-js",
+ "ip_address": "127.0.0.1",
+ "entity_path": "twitter/typeahead-js"
+ },
+ "created_at": "2020-05-26T22:55:04.218Z"
+ }
+]