Commit c403f2d7 authored by Greg Messner's avatar Greg Messner
Browse files

Added support for the Resource Label Events API (#496)

parent 482588be
...@@ -53,7 +53,7 @@ To utilize GitLab4J™ API in your Java project, simply add the following de ...@@ -53,7 +53,7 @@ To utilize GitLab4J™ API in your Java project, simply add the following de
```java ```java
dependencies { 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 { ...@@ -64,7 +64,7 @@ dependencies {
<dependency> <dependency>
<groupId>org.gitlab4j</groupId> <groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId> <artifactId>gitlab4j-api</artifactId>
<version>4.14.11</version> <version>4.14.12</version>
</dependency> </dependency>
``` ```
...@@ -287,6 +287,7 @@ The following is a list of the available sub APIs along with a sample use of eac ...@@ -287,6 +287,7 @@ The following is a list of the available sub APIs along with a sample use of eac
&nbsp;&nbsp;[ReleasesApi](#releasesapi)<br/> &nbsp;&nbsp;[ReleasesApi](#releasesapi)<br/>
&nbsp;&nbsp;[RepositoryApi](#repositoryapi)<br/> &nbsp;&nbsp;[RepositoryApi](#repositoryapi)<br/>
&nbsp;&nbsp;[RepositoryFileApi](#repositoryfileapi)<br/> &nbsp;&nbsp;[RepositoryFileApi](#repositoryfileapi)<br/>
&nbsp;&nbsp;[ReourceLabelEventsApi](#resourcelabeleventsapi)<br/>
&nbsp;&nbsp;[RunnersApi](#runnersapi)<br/> &nbsp;&nbsp;[RunnersApi](#runnersapi)<br/>
&nbsp;&nbsp;[SearchApi](#searchapi)<br/> &nbsp;&nbsp;[SearchApi](#searchapi)<br/>
&nbsp;&nbsp;[ServicesApi](#servicesapi)<br/> &nbsp;&nbsp;[ServicesApi](#servicesapi)<br/>
...@@ -508,6 +509,13 @@ List<Branch> branches = gitLabApi.getRepositoryApi().getBranches(); ...@@ -508,6 +509,13 @@ List<Branch> branches = gitLabApi.getRepositoryApi().getBranches();
RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile("file-path", 1234, "ref"); RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile("file-path", 1234, "ref");
``` ```
#### ResouceLabelEventsApi
```java
// Get the label events for the specified merge request
List<LabelEvent> labelEvents = gitLabApi.getResourceLabelEventsApi()
.getMergeRequestLabelEvents(projectId, mergeRequestIid);
```
#### RunnersApi #### RunnersApi
```java ```java
// Get All Runners. // Get All Runners.
......
...@@ -83,6 +83,7 @@ public class GitLabApi { ...@@ -83,6 +83,7 @@ public class GitLabApi {
private ReleasesApi releasesApi; private ReleasesApi releasesApi;
private RepositoryApi repositoryApi; private RepositoryApi repositoryApi;
private RepositoryFileApi repositoryFileApi; private RepositoryFileApi repositoryFileApi;
private ResourceLabelEventsApi resourceLabelEventsApi;
private RunnersApi runnersApi; private RunnersApi runnersApi;
private SearchApi searchApi; private SearchApi searchApi;
private ServicesApi servicesApi; private ServicesApi servicesApi;
...@@ -1506,6 +1507,25 @@ public class GitLabApi { ...@@ -1506,6 +1507,25 @@ public class GitLabApi {
return (repositoryFileApi); 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 * Gets the RunnersApi instance owned by this GitLabApi instance. The RunnersApi is used
* to perform all Runner related API calls. * to perform all Runner related API calls.
......
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 <a href="https://docs.gitlab.com/ce/api/resource_label_events.html">Resource label events API at GitLab</a>
*/
public class ResourceLabelEventsApi extends AbstractApi {
public ResourceLabelEventsApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Gets a list of all label events for a single issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events</code></pre>
*
* @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<LabelEvent> getIssueLabelEvents(Object projectIdOrPath, Integer issueIid) throws GitLabApiException {
return (getIssueLabelEvents(projectIdOrPath, issueIid, getDefaultPerPage()).all());
}
/**
* Gets a Pager of all label events for a single issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events</code></pre>
*
* @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<LabelEvent> getIssueLabelEvents(Object projectIdOrPath, Integer issueIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<LabelEvent>(this, LabelEvent.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "resource_label_events"));
}
/**
* Gets a Stream of all label events for a single issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events</code></pre>
*
* @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<LabelEvent> getIssueLabelEventsStream(Object projectIdOrPath, Integer issueIid) throws GitLabApiException {
return (getIssueLabelEvents(projectIdOrPath, issueIid, getDefaultPerPage()).stream());
}
/**
* Get a single label event for a specific project issue.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events/:resource_label_event_id</code></pre>
*
* @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
*
* <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/resource_label_events/:resource_label_event_id</code></pre>
*
* @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<LabelEvent> 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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events</code></pre>
*
* @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<LabelEvent> getEpicLabelEvents(Object projectIdOrPath, Integer epicId) throws GitLabApiException {
return (getEpicLabelEvents(projectIdOrPath, epicId, getDefaultPerPage()).all());
}
/**
* Gets a Pager of all label events for the specified epic.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events</code></pre>
*
* @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<LabelEvent> getEpicLabelEvents(Object projectIdOrPath, Integer epicId, int itemsPerPage) throws GitLabApiException {
return (new Pager<LabelEvent>(this, LabelEvent.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "epics", epicId, "resource_label_events"));
}
/**
* Gets a Stream of all label events for he specified epic.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events</code></pre>
*
* @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<LabelEvent> getEpicLabelEventsStream(Object projectIdOrPath, Integer epicId) throws GitLabApiException {
return (getEpicLabelEvents(projectIdOrPath, epicId, getDefaultPerPage()).stream());
}
/**
* Get a single label event for a specific epic label event.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events/:resource_label_event_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/epics/:epic_id/resource_label_events/:resource_label_event_id</code></pre>
*
* @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<LabelEvent> 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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:epic_id/resource_label_events</code></pre>
*
* @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<LabelEvent> 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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:epic_id/resource_label_events</code></pre>
*
* @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<LabelEvent> getMergeRequestLabelEvents(Object projectIdOrPath, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<LabelEvent>(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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:issue_iid/resource_label_events</code></pre>
*
* @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<LabelEvent> 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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:epic_id/resource_label_events/:resource_label_event_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:issue_iid/resource_label_events/:resource_label_event_id</code></pre>
*
* @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<LabelEvent> getOptionalMergeRequestLabelEvent(Object projectIdOrPath,
Integer mergeRequestIid, Integer resourceLabelEventId) throws GitLabApiException {
try {
return (Optional.ofNullable(getMergeRequestLabelEvent(projectIdOrPath, mergeRequestIid, resourceLabelEventId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
}
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<ResourceType> 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));
}
}
...@@ -69,6 +69,7 @@ import org.gitlab4j.api.models.IssuesStatistics; ...@@ -69,6 +69,7 @@ import org.gitlab4j.api.models.IssuesStatistics;
import org.gitlab4j.api.models.Job; import org.gitlab4j.api.models.Job;
import org.gitlab4j.api.models.Key; import org.gitlab4j.api.models.Key;
import org.gitlab4j.api.models.Label; import org.gitlab4j.api.models.Label;
import org.gitlab4j.api.models.LabelEvent;
import org.gitlab4j.api.models.Member; import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.Milestone; import org.gitlab4j.api.models.Milestone;
...@@ -289,6 +290,12 @@ public class TestGitLabApiBeans { ...@@ -289,6 +290,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(issueLink, "issue-link.json")); assertTrue(compareJson(issueLink, "issue-link.json"));
} }
@Test
public void testLabelEvents() throws Exception {
List<LabelEvent> events = unmarshalResourceList(LabelEvent.class, "label-events.json");
assertTrue(compareJson(events, "label-events.json"));
}
@Test @Test
public void testLinkedIssues() throws Exception { public void testLinkedIssues() throws Exception {
List<Issue> linkedIssues = unmarshalResourceList(Issue.class, "linked-issues.json"); List<Issue> linkedIssues = unmarshalResourceList(Issue.class, "linked-issues.json");
......
[
{
"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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment