Skip to content

Commit 4041ae7

Browse files
committed
Add support for link type between issues
Fixes #847
1 parent 2d2fe24 commit 4041ae7

File tree

6 files changed

+98
-3
lines changed

6 files changed

+98
-3
lines changed

src/main/java/org/gitlab4j/api/IssuesApi.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.gitlab4j.api.models.IssueLink;
1717
import org.gitlab4j.api.models.IssuesStatistics;
1818
import org.gitlab4j.api.models.IssuesStatisticsFilter;
19+
import org.gitlab4j.api.models.LinkType;
1920
import org.gitlab4j.api.models.MergeRequest;
2021
import org.gitlab4j.api.models.Participant;
2122
import org.gitlab4j.api.models.TimeStats;
@@ -889,10 +890,31 @@ public Stream<Issue> getIssueLinksStream(Object projectIdOrPath, Long issueIid)
889890
*/
890891
public IssueLink createIssueLink(Object projectIdOrPath, Long issueIid,
891892
Object targetProjectIdOrPath, Long targetIssueIid) throws GitLabApiException {
893+
return createIssueLink(projectIdOrPath, issueIid, targetProjectIdOrPath, targetIssueIid, null);
894+
}
895+
896+
/**
897+
* Creates a two-way relation between two issues. User must be allowed to update both issues in order to succeed.
898+
*
899+
* <p>NOTE: Only available in GitLab Starter, GitLab Bronze, and higher tiers.</p>
900+
*
901+
* <pre><code>GitLab Endpoint: POST /projects/:id/issues/:issue_iid/links</code></pre>
902+
*
903+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
904+
* @param issueIid the internal ID of a project's issue
905+
* @param targetProjectIdOrPath the project in the form of an Long(ID), String(path), or Project instance of the target project
906+
* @param targetIssueIid the internal ID of a target project’s issue
907+
* @param linkType the type of the relation (optional), defaults to {@link LinkType#RELATES_TO}.
908+
* @return an instance of IssueLink holding the link relationship
909+
* @throws GitLabApiException if any exception occurs
910+
*/
911+
public IssueLink createIssueLink(Object projectIdOrPath, Long issueIid,
912+
Object targetProjectIdOrPath, Long targetIssueIid, LinkType linkType) throws GitLabApiException {
892913

893914
GitLabApiForm formData = new GitLabApiForm()
894915
.withParam("target_project_id", getProjectIdOrPath(targetProjectIdOrPath), true)
895-
.withParam("target_issue_iid", targetIssueIid, true);
916+
.withParam("target_issue_iid", targetIssueIid, true)
917+
.withParam("link_type", linkType, false);
896918

897919
Response response = post(Response.Status.OK, formData.asMap(),
898920
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "links");

src/main/java/org/gitlab4j/api/models/Issue.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public String toString() {
8282
private String taskStatus;
8383
private TaskCompletionStatus taskCompletionStatus;
8484

85+
private LinkType linkType;
86+
private Date linkCreatedAt;
87+
private Date linkUpdatedAt;
88+
8589
public Assignee getAssignee() {
8690
return assignee;
8791
}
@@ -351,6 +355,30 @@ public void setTaskCompletionStatus(TaskCompletionStatus taskCompletionStatus) {
351355
this.taskCompletionStatus = taskCompletionStatus;
352356
}
353357

358+
public LinkType getLinkType() {
359+
return linkType;
360+
}
361+
362+
public void setLinkType(LinkType linkType) {
363+
this.linkType = linkType;
364+
}
365+
366+
public Date getLinkCreatedAt() {
367+
return linkCreatedAt;
368+
}
369+
370+
public void setLinkCreatedAt(Date linkCreatedAt) {
371+
this.linkCreatedAt = linkCreatedAt;
372+
}
373+
374+
public Date getLinkUpdatedAt() {
375+
return linkUpdatedAt;
376+
}
377+
378+
public void setLinkUpdatedAt(Date linkUpdatedAt) {
379+
this.linkUpdatedAt = linkUpdatedAt;
380+
}
381+
354382
@Override
355383
public String toString() {
356384
return (JacksonJson.toJsonString(this));

src/main/java/org/gitlab4j/api/models/IssueLink.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class IssueLink {
66

77
private Issue sourceIssue;
88
private Issue targetIssue;
9+
private LinkType linkType;
910

1011
public Issue getSourceIssue() {
1112
return sourceIssue;
@@ -23,6 +24,14 @@ public void setTargetIssue(Issue targetIssue) {
2324
this.targetIssue = targetIssue;
2425
}
2526

27+
public LinkType getLinkType() {
28+
return linkType;
29+
}
30+
31+
public void setLinkType(LinkType linkType) {
32+
this.linkType = linkType;
33+
}
34+
2635
@Override
2736
public String toString() {
2837
return (JacksonJson.toJsonString(this));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonValue;
7+
8+
/**
9+
* Enum to model the type of link between issues or epics
10+
*/
11+
public enum LinkType {
12+
RELATES_TO,
13+
BLOCKS,
14+
IS_BLOCKED_BY;
15+
16+
private static JacksonJsonEnumHelper<LinkType> enumHelper = new JacksonJsonEnumHelper<>(LinkType.class);
17+
18+
@JsonCreator
19+
public static LinkType forValue(String value) {
20+
return enumHelper.forValue(value);
21+
}
22+
23+
@JsonValue
24+
public String toValue() {
25+
return (enumHelper.toString(this));
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return (enumHelper.toString(this));
31+
}
32+
}

src/test/resources/org/gitlab4j/api/issue-link.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"user_notes_count": 0,
4747
"web_url": "http://example.com/example/example/issues/14",
4848
"confidential": false
49-
}
49+
},
50+
"link_type": "is_blocked_by"
5051
}

src/test/resources/org/gitlab4j/api/linked-issues.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"subscribed" : true,
2323
"user_notes_count": 0,
2424
"web_url": "http://example.com/example/example/issues/14",
25-
"confidential": false
25+
"confidential": false,
26+
"link_type": "relates_to",
27+
"link_created_at": "2016-01-07T12:44:33.959Z",
28+
"link_updated_at": "2016-01-07T12:44:33.959Z"
2629
}
2730
]

0 commit comments

Comments
 (0)