diff --git a/README.md b/README.md index cb86fc528aae5ed4ee9de488a5067deb8a0bd086..80f5d99b82632480173bcf2da0d97a0190eb0f2d 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.14.11' + compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.14.12' } ``` @@ -64,7 +64,7 @@ dependencies { org.gitlab4j gitlab4j-api - 4.14.11 + 4.14.12 ``` @@ -287,6 +287,7 @@ The following is a list of the available sub APIs along with a sample use of eac   [ReleasesApi](#releasesapi)
  [RepositoryApi](#repositoryapi)
  [RepositoryFileApi](#repositoryfileapi)
+  [ReourceLabelEventsApi](#resourcelabeleventsapi)
  [RunnersApi](#runnersapi)
  [SearchApi](#searchapi)
  [ServicesApi](#servicesapi)
@@ -508,6 +509,13 @@ List branches = gitLabApi.getRepositoryApi().getBranches(); RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile("file-path", 1234, "ref"); ``` +#### ResouceLabelEventsApi +```java +// Get the label events for the specified merge request +List labelEvents = gitLabApi.getResourceLabelEventsApi() + .getMergeRequestLabelEvents(projectId, mergeRequestIid); +``` + #### RunnersApi ```java // Get All Runners. diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index 9d419e25e54a294a486706913fd87a4a971faa3c..962e9528208f24197840fdb5f8ed0057315e8732 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -83,6 +83,7 @@ public class GitLabApi { private ReleasesApi releasesApi; private RepositoryApi repositoryApi; private RepositoryFileApi repositoryFileApi; + private ResourceLabelEventsApi resourceLabelEventsApi; private RunnersApi runnersApi; private SearchApi searchApi; private ServicesApi servicesApi; @@ -1506,6 +1507,25 @@ public class GitLabApi { return (repositoryFileApi); } + /** + * Gets the ResourceLabelEventsApi instance owned by this GitLabApi instance. The ResourceLabelEventsApi + * is used to perform all Resource Label Events related API calls. + * + * @return the ResourceLabelEventsApi instance owned by this GitLabApi instance + */ + public ResourceLabelEventsApi getResourceLabelEventsApi() { + + if (resourceLabelEventsApi == null) { + synchronized (this) { + if (resourceLabelEventsApi == null) { + resourceLabelEventsApi = new ResourceLabelEventsApi(this); + } + } + } + + return (resourceLabelEventsApi); + } + /** * Gets the RunnersApi instance owned by this GitLabApi instance. The RunnersApi is used * to perform all Runner related API calls. diff --git a/src/main/java/org/gitlab4j/api/ResourceLabelEventsApi.java b/src/main/java/org/gitlab4j/api/ResourceLabelEventsApi.java new file mode 100644 index 0000000000000000000000000000000000000000..5e7b2bfca46742bc8d3237855cd9a1413bb65f27 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/ResourceLabelEventsApi.java @@ -0,0 +1,267 @@ +package org.gitlab4j.api; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +import javax.ws.rs.core.Response; + +import org.gitlab4j.api.models.LabelEvent; + + +/** + * This class provides an entry point to all the GitLab Resource label events API + * @see Resource label events API at GitLab + */ +public class ResourceLabelEventsApi extends AbstractApi { + + public ResourceLabelEventsApi(GitLabApi gitLabApi) { + super(gitLabApi); + } + + /** + * Gets a list of all label events for a single issue. + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param issueIid the IID of the issue + * @return a List of LabelEvent for the specified issue + * @throws GitLabApiException if any exception occurs + */ + public List getIssueLabelEvents(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { + return (getIssueLabelEvents(projectIdOrPath, issueIid, getDefaultPerPage()).all()); + } + + /** + * Gets a Pager of all label events for a single issue. + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param issueIid the IID of the issue + * @param itemsPerPage the number of LabelEvent instances that will be fetched per page + * @return the Pager of LabelEvent instances for the specified issue IID + * @throws GitLabApiException if any exception occurs + */ + public Pager getIssueLabelEvents(Object projectIdOrPath, Integer issueIid, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, LabelEvent.class, itemsPerPage, null, + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "resource_label_events")); + } + + /** + * Gets a Stream of all label events for a single issue. + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param issueIid the IID of the issue + * @return a Stream of LabelEvent for the specified issue + * @throws GitLabApiException if any exception occurs + */ + public Stream getIssueLabelEventsStream(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { + return (getIssueLabelEvents(projectIdOrPath, issueIid, getDefaultPerPage()).stream()); + } + + /** + * Get a single label event for a specific project issue. + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events/:resource_label_event_id
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param issueIid the IID of the issue + * @param resourceLabelEventId the ID of a label event + * @return LabelEvent instance for the specified project issue + * @throws GitLabApiException if any exception occurs + */ + public LabelEvent getIssueLabelEvent(Object projectIdOrPath, Integer issueIid, Integer resourceLabelEventId) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), + "issues", issueIid, "resource_label_events", resourceLabelEventId); + return (response.readEntity(LabelEvent.class)); + } + + /** + * Get an Optional instance holding a LabelEvent for a specific project issue + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events/:resource_label_event_id
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param issueIid the IID of the issue + * @param resourceLabelEventId the ID of a label event + * @return an Optional instance with the specified LabelEvent as the value + * @throws GitLabApiException if any exception occurs + */ + public Optional getOptionalIssueLabelEvent(Object projectIdOrPath, + Integer issueIid, Integer resourceLabelEventId) throws GitLabApiException { + + try { + return (Optional.ofNullable(getIssueLabelEvent(projectIdOrPath, issueIid, resourceLabelEventId))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Gets a list of all label events for an epic. + * + *
GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param epicId the ID of the epic + * @return a List of LabelEvent for the specified epic + * @throws GitLabApiException if any exception occurs + */ + public List getEpicLabelEvents(Object projectIdOrPath, Integer epicId) throws GitLabApiException { + return (getEpicLabelEvents(projectIdOrPath, epicId, getDefaultPerPage()).all()); + } + + /** + * Gets a Pager of all label events for the specified epic. + * + *
GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param epicId the ID of the epic + * @param itemsPerPage the number of LabelEvent instances that will be fetched per page + * @return the Pager of LabelEvent instances for the specified epic + * @throws GitLabApiException if any exception occurs + */ + public Pager getEpicLabelEvents(Object projectIdOrPath, Integer epicId, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, LabelEvent.class, itemsPerPage, null, + "projects", getProjectIdOrPath(projectIdOrPath), "epics", epicId, "resource_label_events")); + } + + /** + * Gets a Stream of all label events for he specified epic. + * + *
GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param epicId the ID of the epic + * @return a Stream of LabelEvent for the specified epic + * @throws GitLabApiException if any exception occurs + */ + public Stream getEpicLabelEventsStream(Object projectIdOrPath, Integer epicId) throws GitLabApiException { + return (getEpicLabelEvents(projectIdOrPath, epicId, getDefaultPerPage()).stream()); + } + + /** + * Get a single label event for a specific epic label event. + * + *
GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events/:resource_label_event_id
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param epicId the ID of the epic + * @param resourceLabelEventId the ID of a label event + * @return LabelEvent instance for the specified epic label event + * @throws GitLabApiException if any exception occurs + */ + public LabelEvent getEpicLabelEvent(Object projectIdOrPath, Integer epicId, Integer resourceLabelEventId) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), + "epics", epicId, "resource_label_events", resourceLabelEventId); + return (response.readEntity(LabelEvent.class)); + } + + /** + * Get an Optional instance holding a LabelEvent for a specific epic label event. + * + *
GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events/:resource_label_event_id
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param epicId the ID of the epic + * @param resourceLabelEventId the ID of a label event + * @return an Optional instance with the specified LabelEvent as the value + * @throws GitLabApiException if any exception occurs + */ + public Optional getOptionalEpicLabelEvent(Object projectIdOrPath, + Integer epicId, Integer resourceLabelEventId) throws GitLabApiException { + + try { + return (Optional.ofNullable(getEpicLabelEvent(projectIdOrPath, epicId, resourceLabelEventId))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Gets a list of all label events for a merge request. + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:epic_id/resource_label_events
+ * + * @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 + * @return a List of LabelEvent for the specified merge request + * @throws GitLabApiException if any exception occurs + */ + public List getMergeRequestLabelEvents(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException { + return (getMergeRequestLabelEvents(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all()); + } + + /** + * Gets a Pager of all label events for the specified merge request. + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:epic_id/resource_label_events
+ * + * @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 + * @param itemsPerPage the number of LabelEvent instances that will be fetched per page + * @return the Pager of LabelEvent instances for the specified merge request + * @throws GitLabApiException if any exception occurs + */ + public Pager getMergeRequestLabelEvents(Object projectIdOrPath, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, LabelEvent.class, itemsPerPage, null, + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "resource_label_events")); + } + + /** + * Gets a Stream of all label events for he specified merge request. + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:issue_iid/resource_label_events
+ * + * @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 + * @return a Stream of LabelEvent for the specified merge request + * @throws GitLabApiException if any exception occurs + */ + public Stream getMergeRequestLabelEventsStream(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException { + return (getMergeRequestLabelEvents(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream()); + } + + /** + * Get a single label event for a specific merge request label event. + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:epic_id/resource_label_events/:resource_label_event_id
+ * + * @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 + * @param resourceLabelEventId the ID of a label event + * @return LabelEvent instance for the specified epic label event + * @throws GitLabApiException if any exception occurs + */ + public LabelEvent getMergeRequestLabelEvent(Object projectIdOrPath, Integer mergeRequestIid, Integer resourceLabelEventId) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), + "merge_requests", mergeRequestIid, "resource_label_events", resourceLabelEventId); + return (response.readEntity(LabelEvent.class)); + } + + /** + * Get an Optional instance holding a LabelEvent for a specific merge request label event. + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:issue_iid/resource_label_events/:resource_label_event_id
+ * + * @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 + * @param resourceLabelEventId the ID of a label event + * @return an Optional instance with the specified LabelEvent as the value + * @throws GitLabApiException if any exception occurs + */ + public Optional getOptionalMergeRequestLabelEvent(Object projectIdOrPath, + Integer mergeRequestIid, Integer resourceLabelEventId) throws GitLabApiException { + + try { + return (Optional.ofNullable(getMergeRequestLabelEvent(projectIdOrPath, mergeRequestIid, resourceLabelEventId))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } +} diff --git a/src/main/java/org/gitlab4j/api/models/LabelEvent.java b/src/main/java/org/gitlab4j/api/models/LabelEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..191dd4c940aa68ee4b49b3b7a1f21b624b3a4a7b --- /dev/null +++ b/src/main/java/org/gitlab4j/api/models/LabelEvent.java @@ -0,0 +1,103 @@ +package org.gitlab4j.api.models; + +import org.gitlab4j.api.utils.JacksonJson; +import org.gitlab4j.api.utils.JacksonJsonEnumHelper; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public class LabelEvent { + + /** Enum to use for specifying the label event resource type. */ + public enum ResourceType { + + ISSUE, EPIC, MERGE_REQUEST; + + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(ResourceType.class, + true, true); + + @JsonCreator + public static ResourceType forValue(String value) { + return enumHelper.forValue(value); + } + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } + + private int id; + private User user; + private String createdAt; + private ResourceType resourceType; + private int resourceId; + private Label label; + private String action; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + public ResourceType getResourceType() { + return resourceType; + } + + public void setResourceType(ResourceType resourceType) { + this.resourceType = resourceType; + } + + public int getResourceId() { + return resourceId; + } + + public void setResourceId(int resourceId) { + this.resourceId = resourceId; + } + + public Label getLabel() { + return label; + } + + public void setLabel(Label label) { + this.label = label; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + @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 f107ca09f1bda5c62f89dfaaa2ee7dd59f8c5331..1d42a82f08f3f604b1a8a4eb26c6230427dfe947 100644 --- a/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java +++ b/src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java @@ -69,6 +69,7 @@ import org.gitlab4j.api.models.IssuesStatistics; import org.gitlab4j.api.models.Job; import org.gitlab4j.api.models.Key; import org.gitlab4j.api.models.Label; +import org.gitlab4j.api.models.LabelEvent; import org.gitlab4j.api.models.Member; import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.Milestone; @@ -289,6 +290,12 @@ public class TestGitLabApiBeans { assertTrue(compareJson(issueLink, "issue-link.json")); } + @Test + public void testLabelEvents() throws Exception { + List events = unmarshalResourceList(LabelEvent.class, "label-events.json"); + assertTrue(compareJson(events, "label-events.json")); + } + @Test public void testLinkedIssues() throws Exception { List linkedIssues = unmarshalResourceList(Issue.class, "linked-issues.json"); diff --git a/src/test/resources/org/gitlab4j/api/label-events.json b/src/test/resources/org/gitlab4j/api/label-events.json new file mode 100644 index 0000000000000000000000000000000000000000..c5ca4879604ecc73860ce8c259ff01a6b47f1d3a --- /dev/null +++ b/src/test/resources/org/gitlab4j/api/label-events.json @@ -0,0 +1,128 @@ +[ + { + "id": 142, + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2018-08-20T13:38:20.077Z", + "resource_type": "Issue", + "resource_id": 253, + "label": { + "id": 73, + "name": "a1", + "color": "#34495E", + "description": "" + }, + "action": "add" + }, + { + "id": 143, + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2018-08-20T13:38:20.077Z", + "resource_type": "Issue", + "resource_id": 253, + "label": { + "id": 74, + "name": "p1", + "color": "#0033CC", + "description": "" + }, + "action": "remove" + }, + { + "id": 106, + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2018-08-19T11:43:01.746Z", + "resource_type": "Epic", + "resource_id": 33, + "label": { + "id": 73, + "name": "a1", + "color": "#34495E", + "description": "" + }, + "action": "add" + }, + { + "id": 107, + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2018-08-19T11:43:01.746Z", + "resource_type": "Epic", + "resource_id": 33, + "label": { + "id": 37, + "name": "glabel2", + "color": "#A8D695", + "description": "" + }, + "action": "add" + }, + { + "id": 119, + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2018-08-20T06:17:28.394Z", + "resource_type": "MergeRequest", + "resource_id": 28, + "label": { + "id": 74, + "name": "p1", + "color": "#0033CC", + "description": "" + }, + "action": "add" + }, + { + "id": 120, + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2018-08-20T06:17:28.394Z", + "resource_type": "MergeRequest", + "resource_id": 28, + "label": { + "id": 41, + "name": "project", + "color": "#D1D100", + "description": "" + }, + "action": "add" + } +] \ No newline at end of file