From b1ea42e3609d3e90dfa53b899a5620d8859fde85 Mon Sep 17 00:00:00 2001 From: Julien Millau Date: Wed, 24 Jun 2020 21:54:16 +0200 Subject: [PATCH] Add instance, group, project audit events (#584) --- README.md | 10 ++ pom.xml | 2 +- .../java/org/gitlab4j/api/AuditEventApi.java | 89 ++++++++++++++ src/main/java/org/gitlab4j/api/GitLabApi.java | 43 +++++-- src/main/java/org/gitlab4j/api/GroupApi.java | 89 ++++++++++++-- .../java/org/gitlab4j/api/ProjectApi.java | 103 +++++++++++++--- .../org/gitlab4j/api/models/AuditEvent.java | 69 +++++++++++ .../gitlab4j/api/models/AuditEventDetail.java | 112 ++++++++++++++++++ .../org/gitlab4j/api/TestGitLabApiBeans.java | 28 +++-- .../org/gitlab4j/api/audit-events.json | 51 ++++++++ .../gitlab4j/api/project-audit-events.json | 38 ++++++ 11 files changed, 581 insertions(+), 53 deletions(-) create mode 100644 src/main/java/org/gitlab4j/api/AuditEventApi.java create mode 100644 src/main/java/org/gitlab4j/api/models/AuditEvent.java create mode 100644 src/main/java/org/gitlab4j/api/models/AuditEventDetail.java create mode 100644 src/test/resources/org/gitlab4j/api/audit-events.json create mode 100644 src/test/resources/org/gitlab4j/api/project-audit-events.json diff --git a/README.md b/README.md index bc222837..c4dd1715 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,7 @@ The following is a list of the available sub APIs along with a sample use of eac ---   [ApplicationsApi](#applicationsapi)
  [ApplicationSettingsApi](#applicationsettingsapi)
+  [AuditEventApi](#auditeventapi)
  [AwardEmojiApi](#awardemojiapi)
  [BoardsApi](#boardsapi)
  [CommitsApi](#commitsapi)
@@ -326,6 +327,15 @@ gitLabApi.getApplicationsApi().createApplication("My OAUTH Application", "https/ ApplicationSettings appSettings = gitLabApi.getApplicationSettingsApi().getAppliationSettings(); ``` +#### AuditEventApi +```java +// Get the current GitLab server audit events for entity +// This uses the ISO8601 date utilities the in org.gitlab4j.api.utils.ISO8601 class +Date since = ISO8601.toDate("2017-01-01T00:00:00Z"); +Date until = new Date(); // now +List auditEvents = gitLabApi.getAuditEventApi().getAuditEvents(since, until, EntityType.USER, 1); +``` + #### AwardEmojiApi ```java // Get a list of AwardEmoji belonging to the specified issue (group ID = 1, issues IID = 1) diff --git a/pom.xml b/pom.xml index dc15b540..bcc6c694 100644 --- a/pom.xml +++ b/pom.xml @@ -155,7 +155,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.0 + 3.2.0 8 diff --git a/src/main/java/org/gitlab4j/api/AuditEventApi.java b/src/main/java/org/gitlab4j/api/AuditEventApi.java new file mode 100644 index 00000000..13632b72 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/AuditEventApi.java @@ -0,0 +1,89 @@ +package org.gitlab4j.api; + +import org.gitlab4j.api.models.AuditEvent; +import org.gitlab4j.api.utils.ISO8601; + +import javax.ws.rs.core.Form; +import javax.ws.rs.core.Response; +import java.util.Date; +import java.util.List; +import java.util.stream.Stream; + +/** + * This class implements the client side API for the GitLab Instance Audit Event API. + * See Audit Event API at GitLab for more information. + */ +public class AuditEventApi extends AbstractApi { + + public AuditEventApi(GitLabApi gitLabApi) { + super(gitLabApi); + } + + /** + * Get a List of the group audit events viewable by Maintainer or an Owner of the group. + * + *
GET /audit_events/
+ * + * @param created_after Return group audit events created on or after the given time. + * @param created_before Return group audit events created on or before the given time. + * @param entityType Return audit events for the given entity type. Valid values are: User, Group, or Project. + * @param entityId Return audit events for the given entity ID. Requires entityType attribute to be present. + * @return a List of group Audit events + * @throws GitLabApiException if any exception occurs + */ + public List getAuditEvents(Date created_after, Date created_before, String entityType, Integer entityId) throws GitLabApiException { + return (getAuditEvents(created_after, created_before, entityType, entityId, getDefaultPerPage()).all()); + } + + /** + * Get a Pager of the group audit events viewable by Maintainer or an Owner of the group. + * + *
GET /audit_events
+ * + * @param created_after Return group audit events created on or after the given time. + * @param created_before Return group audit events created on or before the given time. + * @param entityType Return audit events for the given entity type. Valid values are: User, Group, or Project. + * @param entityId Return audit events for the given entity ID. Requires entityType attribute to be present. + * @param itemsPerPage the number of Audit Event instances that will be fetched per page + * @return a Pager of group Audit events + * @throws GitLabApiException if any exception occurs + */ + public Pager getAuditEvents(Date created_after, Date created_before, String entityType, Integer entityId, int itemsPerPage) throws GitLabApiException { + Form form = new GitLabApiForm() + .withParam("created_before", ISO8601.toString(created_before, false)) + .withParam("created_after", ISO8601.toString(created_after, false)) + .withParam("entity_type", entityType) + .withParam("entity_id", entityId); + return (new Pager(this, AuditEvent.class, itemsPerPage, form.asMap(), "audit_events")); + } + + /** + * Get a Stream of the group audit events viewable by Maintainer or an Owner of the group. + * + *
GET /audit_events
+ * + * @param created_after Return group audit events created on or after the given time. + * @param created_before Return group audit events created on or before the given time. + * @param entityType Return audit events for the given entity type. Valid values are: User, Group, or Project. + * @param entityId Return audit events for the given entity ID. Requires entityType attribute to be present. + * @return a Stream of group Audit events + * @throws GitLabApiException if any exception occurs + */ + public Stream getAuditEventsStream(Date created_after, Date created_before, String entityType, Integer entityId) throws GitLabApiException { + return (getAuditEvents(created_after, created_before, entityType, entityId, getDefaultPerPage()).stream()); + } + + /** + * Get a specific instance audit event. + * + *
GitLab Endpoint: GET /audit_events/:id
+ * + * @param auditEventId the auditEventId, required + * @return the group Audit event + * @throws GitLabApiException if any exception occurs + */ + public AuditEvent getAuditEvent(Integer auditEventId) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "audit_events", auditEventId); + return (response.readEntity(AuditEvent.class)); + } +} diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index 9144b6af..7b3027a3 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -1,16 +1,5 @@ package org.gitlab4j.api; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.WeakHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - import org.gitlab4j.api.Constants.TokenType; import org.gitlab4j.api.models.OauthTokenResponse; import org.gitlab4j.api.models.User; @@ -19,6 +8,16 @@ import org.gitlab4j.api.utils.MaskingLoggingFilter; import org.gitlab4j.api.utils.Oauth2LoginStreamingOutput; import org.gitlab4j.api.utils.SecretString; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.WeakHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * This class is provides a simplified interface to a GitLab API server, and divides the API up into * a separate API class for each concern. @@ -51,6 +50,7 @@ public class GitLabApi implements AutoCloseable { private ApplicationsApi applicationsApi; private ApplicationSettingsApi applicationSettingsApi; + private AuditEventApi auditEventApi; private AwardEmojiApi awardEmojiApi; private BoardsApi boardsApi; private CommitsApi commitsApi; @@ -547,7 +547,7 @@ public class GitLabApi implements AutoCloseable { /** * Enable the logging of the requests to and the responses from the GitLab server API using the - * specified logger. Logging will NOT include entity logging and will mask PRIVATE-TOKEN + * specified logger. Logging will NOT include entity logging and will mask PRIVATE-TOKEN * and Authorization headers.. * * @param logger the Logger instance to log to @@ -846,6 +846,25 @@ public class GitLabApi implements AutoCloseable { return (applicationSettingsApi); } + /** + * Gets the AuditEventApi instance owned by this GitLabApi instance. The AuditEventApi is used + * to perform all instance audit event API calls. + * + * @return the AuditEventApi instance owned by this GitLabApi instance + */ + public AuditEventApi getAuditEventApi() { + + if (auditEventApi == null) { + synchronized (this) { + if (auditEventApi == null) { + auditEventApi = new AuditEventApi(this); + } + } + } + + return (auditEventApi); + } + /** * Gets the AwardEmojiApi instance owned by this GitLabApi instance. The AwardEmojiApi is used * to perform all award emoji related API calls. diff --git a/src/main/java/org/gitlab4j/api/GroupApi.java b/src/main/java/org/gitlab4j/api/GroupApi.java index 62614456..dc000168 100644 --- a/src/main/java/org/gitlab4j/api/GroupApi.java +++ b/src/main/java/org/gitlab4j/api/GroupApi.java @@ -1,18 +1,9 @@ package org.gitlab4j.api; -import java.io.File; -import java.util.Date; -import java.util.List; -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.Response; - import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.AccessLevel; import org.gitlab4j.api.models.AccessRequest; +import org.gitlab4j.api.models.AuditEvent; import org.gitlab4j.api.models.Badge; import org.gitlab4j.api.models.Group; import org.gitlab4j.api.models.GroupFilter; @@ -22,6 +13,16 @@ import org.gitlab4j.api.models.Member; import org.gitlab4j.api.models.Project; 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.Response; +import java.io.File; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; /** * This class implements the client side API for the GitLab groups calls. @@ -29,6 +30,7 @@ import org.gitlab4j.api.models.Visibility; * @see Group and project members API at GitLab * @see Group and project access requests API * @see Group badges API + * @see Group audit events API */ public class GroupApi extends AbstractApi { @@ -1356,7 +1358,7 @@ public class GroupApi extends AbstractApi { * * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required - * @return the transfered Project instance + * @return the transferred Project instance * @throws GitLabApiException if any exception occurs during execution */ public Project transferProject(Object groupIdOrPath, Object projectIdOrPath) throws GitLabApiException { @@ -1365,6 +1367,71 @@ public class GroupApi extends AbstractApi { return (response.readEntity(Project.class)); } + /** + * Get a List of the group audit events viewable by Maintainer or an Owner of the group. + * + *
GET /groups/:id/audit_events
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path + * @param created_after Group audit events created on or after the given time. + * @param created_before Group audit events created on or before the given time. + * @return a List of group Audit events + * @throws GitLabApiException if any exception occurs + */ + public List getAuditEvents(Object groupIdOrPath, Date created_after, Date created_before) throws GitLabApiException { + return (getAuditEvents(groupIdOrPath, created_after, created_before, getDefaultPerPage()).all()); + } + + /** + * Get a Pager of the group audit events viewable by Maintainer or an Owner of the group. + * + *
GET /groups/:id/audit_events
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path + * @param created_after Group audit events created on or after the given time. + * @param created_before Group 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 group Audit events + * @throws GitLabApiException if any exception occurs + */ + public Pager getAuditEvents(Object groupIdOrPath, Date created_after, Date created_before, int itemsPerPage) throws GitLabApiException { + Form form = new GitLabApiForm() + .withParam("created_before", ISO8601.toString(created_after, false)) + .withParam("created_after", ISO8601.toString(created_before, false)); + return (new Pager(this, AuditEvent.class, itemsPerPage, form.asMap(), + "groups", getGroupIdOrPath(groupIdOrPath), "audit_events")); + } + + /** + * Get a Stream of the group audit events viewable by Maintainer or an Owner of the group. + * + *
GET /groups/:id/audit_events
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path + * @param created_after Group audit events created on or after the given time. + * @param created_before Group audit events created on or before the given time. + * @return a Stream of group Audit events + * @throws GitLabApiException if any exception occurs + */ + public Stream 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 e63b176d..9a645f41 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 00000000..05d6c2e0 --- /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 00000000..cc4af61d --- /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 668c336c..b90dc35c 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 00000000..aad859b7 --- /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 00000000..a0b971e4 --- /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" + } +] -- GitLab