Skip to content

Commit

Permalink
Add methods to manage related epics
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed May 9, 2023
1 parent 68416b5 commit b9b2a52
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 1 deletion.
88 changes: 87 additions & 1 deletion src/main/java/org/gitlab4j/api/EpicsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.gitlab4j.api.models.Epic;
import org.gitlab4j.api.models.EpicIssue;
import org.gitlab4j.api.models.EpicIssueLink;
import org.gitlab4j.api.models.LinkType;
import org.gitlab4j.api.models.RelatedEpic;
import org.gitlab4j.api.models.RelatedEpicLink;

/**
* This class implements the client side API for the GitLab Epics and Epic Issues API calls.
Expand Down Expand Up @@ -461,7 +464,6 @@ public List<EpicIssue> updateIssue(Object groupIdOrPath, Long epicIid, Long epic
return response.readEntity(new GenericType<List<EpicIssue>>() {});
}


/**
* Gets all child epics of an epic and the authenticated user has access to.
*
Expand Down Expand Up @@ -581,4 +583,88 @@ public ChildEpic unassignChildEpic(Object groupIdOrPath, Long epicIid, Long chil
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "epics", childEpicId);
return (response.readEntity(ChildEpic.class));
}

/**
* Gets all linked epics of an epic filtered according to the user authorizations.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/related_epics</code></pre>
*
* @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 child epics for
* @return a list of all related epics of the specified epic
* @throws GitLabApiException if any exception occurs
*/
public List<RelatedEpic> getRelatedEpics(Object groupIdOrPath, Long epicIid) throws GitLabApiException {
return (getRelatedEpics(groupIdOrPath, epicIid, getDefaultPerPage()).all());
}

/**
* Get a Pager of all linked epics of an epic filtered according to the user authorizations.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/related_epics</code></pre>
*
* @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 child epics for
* @param itemsPerPage the number of child epics per page
* @return the Pager of all related epics of the specified epic
* @throws GitLabApiException if any exception occurs
*/
public Pager<RelatedEpic> getRelatedEpics(Object groupIdOrPath, Long epicIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<RelatedEpic>(this, RelatedEpic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "related_epics"));
}

/**
* Gets all linked epics of an epic filtered according to the user authorizations to as a Stream.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/related_epics</code></pre>
*
* @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 child epics for
* @return a Stream of all related epics of the specified epic
* @throws GitLabApiException if any exception occurs
*/
public Stream<RelatedEpic> getRelatedEpicsStream(Object groupIdOrPath, Long epicIid) throws GitLabApiException {
return (getRelatedEpics(groupIdOrPath, epicIid, getDefaultPerPage()).stream());
}

/**
* Create a two-way relation between two epics. The user must have at least the Guest role for both groups.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/epics/:epic_iid/related_epics</code></pre>
*
* @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 child epic to
* @param targetGroupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path of the target group’s epic
* @param targetEpicIid the Epic IID of the target group’s epic.
* @param linkType the type of the relation (optional), defaults to {@link LinkType#RELATES_TO}.
* @return an RelatedEpic instance containing info on the newly assigned child epic
* @throws GitLabApiException if any exception occurs
*/
public RelatedEpicLink createRelatedEpicLink(Object groupIdOrPath, Long epicIid, Object targetGroupIdOrPath, Long targetEpicIid, LinkType linkType) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("target_group_id", getGroupIdOrPath(targetGroupIdOrPath), true)
.withParam("target_epic_iid", targetEpicIid, true)
.withParam("link_type", linkType);
Response response = post(Response.Status.CREATED, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "related_epics");
return (response.readEntity(RelatedEpicLink.class));
}

/**
* Delete a two-way relation between two epics. The user must have at least the Guest role for both groups.
*
* <pre><code>GitLab Endpoint: DELETE /groups/:id/epics/:epic_iid/related_epics/:related_epic_link_id</code></pre>
*
* @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 child epic from
* @param relatedEpicLinkId the ID a related epic link.
* @return an RelatedEpicLink instance containing info on the removed related epic
* @throws GitLabApiException if any exception occurs
*/
public RelatedEpicLink deleteRelatedEpicLink(Object groupIdOrPath, Long epicIid, Long relatedEpicLinkId) throws GitLabApiException {
Response response = delete(Response.Status.OK, null,
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "related_epics", relatedEpicLinkId);
return (response.readEntity(RelatedEpicLink.class));
}

}
10 changes: 10 additions & 0 deletions src/main/java/org/gitlab4j/api/models/EpicInLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gitlab4j.api.models;

import org.gitlab4j.api.utils.JacksonJson;

public class EpicInLink extends AbstractEpic<EpicInLink> {

public String toString() {
return (JacksonJson.toJsonString(this));
}
}
76 changes: 76 additions & 0 deletions src/main/java/org/gitlab4j/api/models/RelatedEpic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.gitlab4j.api.models;

import java.util.Date;

import org.gitlab4j.api.utils.JacksonJson;

public class RelatedEpic extends AbstractEpic<RelatedEpic> {

private Boolean startDateIsFixed;
private Boolean dueDateIsFixed;
private Date dueDateFromInheritedSource;
private Long relatedEpicLinkId;
private LinkType linkType;
private Date linkCreatedAt;
private Date linkUpdatedAt;

public Boolean getStartDateIsFixed() {
return startDateIsFixed;
}

public void setStartDateIsFixed(Boolean startDateIsFixed) {
this.startDateIsFixed = startDateIsFixed;
}

public Boolean getDueDateIsFixed() {
return dueDateIsFixed;
}

public void setDueDateIsFixed(Boolean dueDateIsFixed) {
this.dueDateIsFixed = dueDateIsFixed;
}

public Date getDueDateFromInheritedSource() {
return dueDateFromInheritedSource;
}

public void setDueDateFromInheritedSource(Date dueDateFromInheritedSource) {
this.dueDateFromInheritedSource = dueDateFromInheritedSource;
}

public Long getRelatedEpicLinkId() {
return relatedEpicLinkId;
}

public void setRelatedEpicLinkId(Long relatedEpicLinkId) {
this.relatedEpicLinkId = relatedEpicLinkId;
}

public LinkType getLinkType() {
return linkType;
}

public void setLinkType(LinkType linkType) {
this.linkType = linkType;
}

public Date getLinkCreatedAt() {
return linkCreatedAt;
}

public void setLinkCreatedAt(Date linkCreatedAt) {
this.linkCreatedAt = linkCreatedAt;
}

public Date getLinkUpdatedAt() {
return linkUpdatedAt;
}

public void setLinkUpdatedAt(Date linkUpdatedAt) {
this.linkUpdatedAt = linkUpdatedAt;
}

public String toString() {
return (JacksonJson.toJsonString(this));
}
}
67 changes: 67 additions & 0 deletions src/main/java/org/gitlab4j/api/models/RelatedEpicLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.gitlab4j.api.models;

import java.util.Date;

import org.gitlab4j.api.utils.JacksonJson;

public class RelatedEpicLink {

private Long id;
private EpicInLink sourceEpic;
private EpicInLink targetEpic;
private LinkType linkType;
private Date createdAt;
private Date updatedAt;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public EpicInLink getSourceEpic() {
return sourceEpic;
}

public void setSourceEpic(EpicInLink sourceEpic) {
this.sourceEpic = sourceEpic;
}

public EpicInLink getTargetEpic() {
return targetEpic;
}

public void setTargetEpic(EpicInLink targetEpic) {
this.targetEpic = targetEpic;
}

public LinkType getLinkType() {
return linkType;
}

public void setLinkType(LinkType linkType) {
this.linkType = linkType;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public Date getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}

public String toString() {
return (JacksonJson.toJsonString(this));
}
}
14 changes: 14 additions & 0 deletions src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
import org.gitlab4j.api.models.ProtectedTag;
import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.RegistryRepository;
import org.gitlab4j.api.models.RelatedEpic;
import org.gitlab4j.api.models.RelatedEpicLink;
import org.gitlab4j.api.models.Release;
import org.gitlab4j.api.models.RemoteMirror;
import org.gitlab4j.api.models.RepositoryFile;
Expand Down Expand Up @@ -551,6 +553,18 @@ public void testRegistryRepositories() throws Exception {
assertTrue(compareJson(repos, "registry-repositories.json"));
}

@Test
public void testRelatedEpicLink() throws Exception {
RelatedEpicLink relatedEpics = unmarshalResource(RelatedEpicLink.class, "related-epic-link.json");
assertTrue(compareJson(relatedEpics, "related-epic-link.json"));
}

@Test
public void testRelatedEpics() throws Exception {
List<RelatedEpic> relatedEpics = unmarshalResourceList(RelatedEpic.class, "related-epics.json");
assertTrue(compareJson(relatedEpics, "related-epics.json"));
}

@Test
public void testReleases() throws Exception {
List<Release> releases = unmarshalResourceList(Release.class, "releases.json");
Expand Down
72 changes: 72 additions & 0 deletions src/test/resources/org/gitlab4j/api/related-epic-link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"id": 1,
"created_at": "2022-01-31T15:10:44.988Z",
"updated_at": "2022-01-31T15:10:44.988Z",
"link_type": "relates_to",
"source_epic": {
"id": 21,
"iid": 1,
"color": "#1068bf",
"group_id": 26,
"title": "Aspernatur recusandae distinctio omnis et qui est iste.",
"description": "some description",
"author": {
"id": 15,
"username": "trina",
"name": "Theresia Robel",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/085e28df717e16484cbf6ceca75e9a93?s=80&d=identicon",
"web_url": "http://gitlab.example.com/trina"
},
"state": "opened",
"web_url": "http://gitlab.example.com/groups/flightjs/-/epics/1",
"references": {
"short": "&1",
"relative": "&1",
"full": "flightjs&1"
},
"created_at": "2022-01-31T15:10:44.988Z",
"updated_at": "2022-03-16T09:32:35.712Z",
"labels": [],
"upvotes": 0,
"downvotes": 0,
"_links": {
"self": "http://gitlab.example.com/api/v4/groups/26/epics/1",
"epic_issues": "http://gitlab.example.com/api/v4/groups/26/epics/1/issues",
"group": "http://gitlab.example.com/api/v4/groups/26"
}
},
"target_epic": {
"id": 25,
"iid": 5,
"color": "#1068bf",
"group_id": 26,
"title": "Aut assumenda id nihil distinctio fugiat vel numquam est.",
"description": "some description",
"author": {
"id": 3,
"username": "valerie",
"name": "Erika Wolf",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/9ef7666abb101418a4716a8ed4dded80?s=80&d=identicon",
"web_url": "http://gitlab.example.com/valerie"
},
"state": "opened",
"web_url": "http://gitlab.example.com/groups/flightjs/-/epics/5",
"references": {
"short": "&5",
"relative": "&5",
"full": "flightjs&5"
},
"created_at": "2022-01-31T15:10:45.080Z",
"updated_at": "2022-03-16T09:32:35.842Z",
"labels": [],
"upvotes": 0,
"downvotes": 0,
"_links": {
"self": "http://gitlab.example.com/api/v4/groups/26/epics/5",
"epic_issues": "http://gitlab.example.com/api/v4/groups/26/epics/5/issues",
"group": "http://gitlab.example.com/api/v4/groups/26"
}
}
}
Loading

0 comments on commit b9b2a52

Please sign in to comment.