Unverified Commit f93aeec4 authored by Jérémie Bresson's avatar Jérémie Bresson Committed by GitHub
Browse files

Fix Epic Issue link association (#969)

* Fix Epic Issue link association

Fixes #729

* Change return type
parent 7606448a
...@@ -11,6 +11,7 @@ import javax.ws.rs.core.Response; ...@@ -11,6 +11,7 @@ import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.Epic; import org.gitlab4j.api.models.Epic;
import org.gitlab4j.api.models.EpicIssue; import org.gitlab4j.api.models.EpicIssue;
import org.gitlab4j.api.models.EpicIssueLink;
/** /**
* This class implements the client side API for the GitLab Epics and Epic Issues API calls. * This class implements the client side API for the GitLab Epics and Epic Issues API calls.
...@@ -347,10 +348,10 @@ public class EpicsApi extends AbstractApi { ...@@ -347,10 +348,10 @@ public class EpicsApi extends AbstractApi {
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the IID of the epic to get issues for * @param epicIid the IID of the epic to get issues for
* @return a list of all epic issues belonging to the specified epic * @return a list of all issues belonging to the specified epic
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Epic> getEpicIssues(Object groupIdOrPath, Long epicIid) throws GitLabApiException { public List<EpicIssue> getEpicIssues(Object groupIdOrPath, Long epicIid) throws GitLabApiException {
return (getEpicIssues(groupIdOrPath, epicIid, getDefaultPerPage()).all()); return (getEpicIssues(groupIdOrPath, epicIid, getDefaultPerPage()).all());
} }
...@@ -364,12 +365,12 @@ public class EpicsApi extends AbstractApi { ...@@ -364,12 +365,12 @@ public class EpicsApi extends AbstractApi {
* @param epicIid the IID of the epic to get issues for * @param epicIid the IID of the epic to get issues for
* @param page the page to get * @param page the page to get
* @param perPage the number of issues per page * @param perPage the number of issues per page
* @return a list of all epic issues belonging to the specified epic in the specified range * @return a list of all issues belonging to the specified epic in the specified range
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Epic> getEpicIssues(Object groupIdOrPath, Long epicIid, int page, int perPage) throws GitLabApiException { public List<EpicIssue> getEpicIssues(Object groupIdOrPath, Long epicIid, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues"); Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues");
return (response.readEntity(new GenericType<List<Epic>>() { })); return (response.readEntity(new GenericType<List<EpicIssue>>() { }));
} }
/** /**
...@@ -380,11 +381,11 @@ public class EpicsApi extends AbstractApi { ...@@ -380,11 +381,11 @@ public class EpicsApi extends AbstractApi {
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the IID of the epic to get issues for * @param epicIid the IID of the epic to get issues for
* @param itemsPerPage the number of issues per page * @param itemsPerPage the number of issues per page
* @return the Pager of all epic issues belonging to the specified epic * @return the Pager of all issues belonging to the specified epic
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Pager<Epic> getEpicIssues(Object groupIdOrPath, Long epicIid, int itemsPerPage) throws GitLabApiException { public Pager<EpicIssue> getEpicIssues(Object groupIdOrPath, Long epicIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<Epic>(this, Epic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues")); return (new Pager<EpicIssue>(this, EpicIssue.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues"));
} }
/** /**
...@@ -394,10 +395,10 @@ public class EpicsApi extends AbstractApi { ...@@ -394,10 +395,10 @@ public class EpicsApi extends AbstractApi {
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the IID of the epic to get issues for * @param epicIid the IID of the epic to get issues for
* @return a Stream of all epic issues belonging to the specified epic * @return a Stream of all issues belonging to the specified epic
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Stream<Epic> getEpicIssuesStream(Object groupIdOrPath, Long epicIid) throws GitLabApiException { public Stream<EpicIssue> getEpicIssuesStream(Object groupIdOrPath, Long epicIid) throws GitLabApiException {
return (getEpicIssues(groupIdOrPath, epicIid, getDefaultPerPage()).stream()); return (getEpicIssues(groupIdOrPath, epicIid, getDefaultPerPage()).stream());
} }
...@@ -409,52 +410,52 @@ public class EpicsApi extends AbstractApi { ...@@ -409,52 +410,52 @@ public class EpicsApi extends AbstractApi {
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the Epic IID to assign the issue to * @param epicIid the Epic IID to assign the issue to
* @param issueIid the issue IID of the issue to assign to the epic * @param issueId the issue ID of the issue to assign to the epic
* @return an EpicIssue instance containing info on the newly assigned epic issue * @return an EpicIssue instance containing info on the newly assigned epic issue
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public EpicIssue assignIssue(Object groupIdOrPath, Long epicIid, Long issueIid) throws GitLabApiException { public EpicIssue assignIssue(Object groupIdOrPath, Long epicIid, Long issueId) throws GitLabApiException {
Response response = post(Response.Status.CREATED, (Form)null, Response response = post(Response.Status.CREATED, (Form)null,
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", issueIid); "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", issueId);
return (response.readEntity(EpicIssue.class)); return (response.readEntity(EpicIssue.class));
} }
/** /**
* Remove an epic - issue association. * Remove an epic - issue association.
* *
* <pre><code>GitLab Endpoint: DELETE /groups/:id/epics/:epic_iid/issues/:issue_id</code></pre> * <pre><code>GitLab Endpoint: DELETE /groups/:id/epics/:epic_iid/issues/:epic_issue_id</code></pre>
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the Epic IID to remove the issue from * @param epicIid the Epic IID to remove the issue from
* @param issueIid the issue IID of the issue to remove from the epic * @param epicIssueId the ID of the "issue - epic" association of the issue to remove from the epic
* @return an EpicIssue instance containing info on the removed issue * @return an EpicIssueLink instance containing info on the removed issue
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public EpicIssue removeIssue(Object groupIdOrPath, Long epicIid, Long issueIid) throws GitLabApiException { public EpicIssueLink removeIssue(Object groupIdOrPath, Long epicIid, Long epicIssueId) throws GitLabApiException {
Response response = delete(Response.Status.OK, null, Response response = delete(Response.Status.OK, null,
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", issueIid); "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", epicIssueId);
return (response.readEntity(EpicIssue.class)); return (response.readEntity(EpicIssueLink.class));
} }
/** /**
* Updates an epic - issue association. * Updates an epic - issue association.
* *
* <pre><code>GitLab Endpoint: PUT /groups/:id/epics/:epic_iid/issues/:issue_id</code></pre> * <pre><code>GitLab Endpoint: PUT /groups/:id/epics/:epic_iid/issues/:epic_issue_id</code></pre>
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the Epic IID that the issue is assigned to * @param epicIid the Epic IID that the issue is assigned to
* @param issueIid the issue IID to update * @param epicIssueId the ID of the "issue - epic" association
* @param moveBeforeId the ID of the issue - epic association that should be placed before the link in the question (optional) * @param moveBeforeId the ID of the "issue - epic" association that should be placed before the link in the question (optional)
* @param moveAfterId the ID of the issue - epic association that should be placed after the link in the question (optional) * @param moveAfterId the ID of the "issue - epic" association that should be placed after the link in the question (optional)
* @return an EpicIssue instance containing info on the newly assigned epic issue * @return a list of all issues belonging to the specified epic
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public EpicIssue updateIssue(Object groupIdOrPath, Long epicIid, Long issueIid, Long moveBeforeId, Long moveAfterId) throws GitLabApiException { public List<EpicIssue> updateIssue(Object groupIdOrPath, Long epicIid, Long epicIssueId, Long moveBeforeId, Long moveAfterId) throws GitLabApiException {
GitLabApiForm form = new GitLabApiForm() GitLabApiForm form = new GitLabApiForm()
.withParam("move_before_id", moveBeforeId) .withParam("move_before_id", moveBeforeId)
.withParam("move_after_id", moveAfterId); .withParam("move_after_id", moveAfterId);
Response response = post(Response.Status.OK, form, Response response = put(Response.Status.OK, form,
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", issueIid); "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", epicIssueId);
return (response.readEntity(EpicIssue.class)); return response.readEntity(new GenericType<List<EpicIssue>>() {});
} }
} }
package org.gitlab4j.api.models;
import org.gitlab4j.api.utils.JacksonJson;
public class EpicIssueLink {
private Long id;
private Integer relativePosition;
private Epic epic;
private Issue issue;
public Long getId() {
return id;
}
public void setId(Long epicIssueId) {
this.id = epicIssueId;
}
public Integer getRelativePosition() {
return relativePosition;
}
public void setRelativePosition(Integer relativePosition) {
this.relativePosition = relativePosition;
}
public Epic getEpic() {
return epic;
}
public void setEpic(Epic epic) {
this.epic = epic;
}
public Issue getIssue() {
return issue;
}
public void setIssue(Issue issue) {
this.issue = issue;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
...@@ -60,6 +60,7 @@ import org.gitlab4j.api.models.Email; ...@@ -60,6 +60,7 @@ import org.gitlab4j.api.models.Email;
import org.gitlab4j.api.models.Environment; import org.gitlab4j.api.models.Environment;
import org.gitlab4j.api.models.Epic; import org.gitlab4j.api.models.Epic;
import org.gitlab4j.api.models.EpicIssue; import org.gitlab4j.api.models.EpicIssue;
import org.gitlab4j.api.models.EpicIssueLink;
import org.gitlab4j.api.models.Event; import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.ExportStatus; import org.gitlab4j.api.models.ExportStatus;
import org.gitlab4j.api.models.ExternalStatusCheck; import org.gitlab4j.api.models.ExternalStatusCheck;
...@@ -254,6 +255,12 @@ public class TestGitLabApiBeans { ...@@ -254,6 +255,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(epicIssue, "epic-issue.json")); assertTrue(compareJson(epicIssue, "epic-issue.json"));
} }
@Test
public void testEpicIssueLink() throws Exception {
EpicIssueLink epicIssueLink = unmarshalResource(EpicIssueLink.class, "epic-issue-link.json");
assertTrue(compareJson(epicIssueLink, "epic-issue-link.json"));
}
@Test @Test
public void testEvent() throws Exception { public void testEvent() throws Exception {
Event event = unmarshalResource(Event.class, "event.json"); Event event = unmarshalResource(Event.class, "event.json");
......
{
"id": 237,
"relative_position": -1026,
"epic": {
"id": 25,
"iid": 1,
"color": "#1068bf",
"group_id": 139,
"title": "Test group Epic",
"description": "",
"author": {
"id": 1,
"username": "pipin",
"name": "Pip",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon",
"web_url": "https://gitlab.example.com/pipin"
},
"state": "opened",
"web_url": "https://gitlab.example.com/groups/my/test-group/-/epics/1",
"references": {
"short": "&1",
"relative": "&1",
"full": "my/test-group&1"
},
"reference": "my/test-group&1",
"created_at": "2022-08-23T13:50:08.507Z",
"updated_at": "2023-04-27T13:36:34.636Z",
"labels": [],
"upvotes": 0,
"downvotes": 0,
"_links": {
"self": "https://gitlab.example.com/api/v4/groups/139/epics/1",
"epic_issues": "https://gitlab.example.com/api/v4/groups/139/epics/1/issues",
"group": "https://gitlab.example.com/api/v4/groups/139" }
},
"issue": {
"id": 1106,
"iid": 9,
"project_id": 58,
"title": "a title",
"description": "a description",
"state": "opened",
"created_at": "2022-09-12T07:30:09.431Z",
"updated_at": "2023-04-27T13:36:34.703Z",
"labels": [],
"assignees": [],
"author": {
"id": 1,
"username": "pipin",
"name": "Pip",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon",
"web_url": "https://gitlab.example.com/pipin"
},
"user_notes_count": 0,
"merge_requests_count": 1,
"upvotes": 0,
"downvotes": 0,
"web_url": "https://gitlab.example.com/my/test-group/a-project/-/issues/9",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0
},
"task_completion_status": {
"count": 0,
"completed_count": 0
}
}
}
\ 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