35
35
import org .gitlab4j .api .models .Duration ;
36
36
import org .gitlab4j .api .models .Issue ;
37
37
import org .gitlab4j .api .models .IssueFilter ;
38
+ import org .gitlab4j .api .models .IssueLink ;
38
39
import org .gitlab4j .api .models .MergeRequest ;
39
40
import org .gitlab4j .api .models .TimeStats ;
40
41
import org .gitlab4j .api .utils .DurationUtils ;
41
42
42
43
/**
43
44
* This class provides an entry point to all the GitLab API Issue calls.
45
+ * @see <a href="https://docs.gitlab.com/ce/api/issues.html">Issues API at GitLab</a>
46
+ * @see <a href="https://docs.gitlab.com/ce/api/issue_links.html">Issue Links API at GitLab</a>
44
47
*/
45
48
public class IssuesApi extends AbstractApi implements Constants {
46
49
@@ -81,7 +84,7 @@ public List<Issue> getIssues(int page, int perPage) throws GitLabApiException {
81
84
* <pre><code>GitLab Endpoint: GET /issues</code></pre>
82
85
*r
83
86
* @param itemsPerPage the number of issues per page
84
- * @return the list of issues in the specified range
87
+ * @return the Pager of issues in the specified range
85
88
* @throws GitLabApiException if any exception occurs
86
89
*/
87
90
public Pager <Issue > getIssues (int itemsPerPage ) throws GitLabApiException {
@@ -101,7 +104,7 @@ public Stream<Issue> getIssuesStream() throws GitLabApiException {
101
104
}
102
105
103
106
/**
104
- * Get a list of project's issues. Only returns the first page
107
+ * Get a list of project's issues.
105
108
*
106
109
* <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre>
107
110
*
@@ -136,7 +139,7 @@ public List<Issue> getIssues(Object projectIdOrPath, int page, int perPage) thro
136
139
*
137
140
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
138
141
* @param itemsPerPage the number of issues per page
139
- * @return the list of issues in the specified range
142
+ * @return the Pager of issues in the specified range
140
143
* @throws GitLabApiException if any exception occurs
141
144
*/
142
145
public Pager <Issue > getIssues (Object projectIdOrPath , int itemsPerPage ) throws GitLabApiException {
@@ -196,7 +199,7 @@ public List<Issue> getIssues(Object projectIdOrPath, IssueFilter filter, int pag
196
199
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
197
200
* @param filter {@link IssueFilter} a IssueFilter instance with the filter settings.
198
201
* @param itemsPerPage the number of Project instances that will be fetched per page.
199
- * @return the list of issues in the specified range.
202
+ * @return the Pager of issues in the specified range.
200
203
* @throws GitLabApiException if any exception occurs
201
204
*/
202
205
public Pager <Issue > getIssues (Object projectIdOrPath , IssueFilter filter , int itemsPerPage ) throws GitLabApiException {
@@ -258,7 +261,7 @@ public List<Issue> getIssues(IssueFilter filter, int page, int perPage) throws G
258
261
*
259
262
* @param filter {@link IssueFilter} a IssueFilter instance with the filter settings.
260
263
* @param itemsPerPage the number of Project instances that will be fetched per page.
261
- * @return the list of issues in the specified range.
264
+ * @return the Pager of issues in the specified range.
262
265
* @throws GitLabApiException if any exception occurs
263
266
*/
264
267
public Pager <Issue > getIssues (IssueFilter filter , int itemsPerPage ) throws GitLabApiException {
@@ -273,7 +276,7 @@ public Pager<Issue> getIssues(IssueFilter filter, int itemsPerPage) throws GitLa
273
276
* <pre><code>GitLab Endpoint: GET /issues</code></pre>
274
277
*
275
278
* @param filter {@link IssueFilter} a IssueFilter instance with the filter settings
276
- * @return the list of issues in the specified range.
279
+ * @return the Stream of issues in the specified range.
277
280
* @throws GitLabApiException if any exception occurs
278
281
*/
279
282
public Stream <Issue > getIssuesStream (IssueFilter filter ) throws GitLabApiException {
@@ -698,4 +701,102 @@ public Pager<MergeRequest> getClosedByMergeRequests(Object projectIdOrPath, Inte
698
701
public Stream <MergeRequest > getClosedByMergeRequestsStream (Object projectIdOrPath , Integer issueIid ) throws GitLabApiException {
699
702
return (getClosedByMergeRequests (projectIdOrPath , issueIid , getDefaultPerPage ()).stream ());
700
703
}
704
+
705
+ /**
706
+ * Get a list of related issues of a given issue, sorted by the relationship creation datetime (ascending).
707
+ * Issues will be filtered according to the user authorizations.
708
+ *
709
+ * <p>NOTE: Only available in GitLab Starter, GitLab Bronze, and higher tiers.</p>
710
+ *
711
+ * <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/links</code></pre>
712
+ *
713
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
714
+ * @param issueIid the internal ID of a project's issue
715
+ * @return a list of related issues of a given issue, sorted by the relationship creation datetime (ascending)
716
+ * @throws GitLabApiException if any exception occurs
717
+ */
718
+ public List <Issue > getIssueLinks (Object projectIdOrPath , Integer issueIid ) throws GitLabApiException {
719
+ return (getIssueLinks (projectIdOrPath , issueIid , getDefaultPerPage ()).all ());
720
+ }
721
+
722
+ /**
723
+ * Get a Pager of related issues of a given issue, sorted by the relationship creation datetime (ascending).
724
+ * Issues will be filtered according to the user authorizations.
725
+ *
726
+ * <p>NOTE: Only available in GitLab Starter, GitLab Bronze, and higher tiers.</p>
727
+ *
728
+ * <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/links</code></pre>
729
+ *
730
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
731
+ * @param issueIid the internal ID of a project's issue
732
+ * @param itemsPerPage the number of issues per page
733
+ * @return a Pager of related issues of a given issue, sorted by the relationship creation datetime (ascending)
734
+ * @throws GitLabApiException if any exception occurs
735
+ */
736
+ public Pager <Issue > getIssueLinks (Object projectIdOrPath , Integer issueIid , int itemsPerPage ) throws GitLabApiException {
737
+ return (new Pager <Issue >(this , Issue .class , itemsPerPage , null ,
738
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "issues" , issueIid , "links" ));
739
+ }
740
+
741
+ /**
742
+ * Get a Stream of related issues of a given issue, sorted by the relationship creation datetime (ascending).
743
+ * Issues will be filtered according to the user authorizations.
744
+ *
745
+ * <p>NOTE: Only available in GitLab Starter, GitLab Bronze, and higher tiers.</p>
746
+ *
747
+ * <pre><code>GitLab Endpoint: GET /projects/:id/issues/:issue_iid/links</code></pre>
748
+ *
749
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
750
+ * @param issueIid the internal ID of a project's issue
751
+ * @return a Stream of related issues of a given issue, sorted by the relationship creation datetime (ascending)
752
+ * @throws GitLabApiException if any exception occurs
753
+ */
754
+ public Stream <Issue > getIssueLinksStream (Object projectIdOrPath , Integer issueIid ) throws GitLabApiException {
755
+ return (getIssueLinks (projectIdOrPath , issueIid , getDefaultPerPage ()).stream ());
756
+ }
757
+
758
+ /**
759
+ * Creates a two-way relation between two issues. User must be allowed to update both issues in order to succeed.
760
+ *
761
+ * <p>NOTE: Only available in GitLab Starter, GitLab Bronze, and higher tiers.</p>
762
+ *
763
+ * <pre><code>GitLab Endpoint: POST /projects/:id/issues/:issue_iid/links</code></pre>
764
+ *
765
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
766
+ * @param issueIid the internal ID of a project's issue
767
+ * @param targetProjectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance of the target project
768
+ * @param targetIssueIid the internal ID of a target project’s issue
769
+ * @return an instance of IssueLink holding the link relationship
770
+ * @throws GitLabApiException if any exception occurs
771
+ */
772
+ public IssueLink createIssueLink (Object projectIdOrPath , Integer issueIid ,
773
+ Object targetProjectIdOrPath , Integer targetIssueIid ) throws GitLabApiException {
774
+
775
+ GitLabApiForm formData = new GitLabApiForm ()
776
+ .withParam ("target_project_id" , getProjectIdOrPath (targetProjectIdOrPath ), true )
777
+ .withParam ("target_issue_iid" , targetIssueIid , true );
778
+
779
+ Response response = post (Response .Status .OK , formData .asMap (),
780
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "issues" , issueIid , "links" );
781
+ return (response .readEntity (IssueLink .class ));
782
+ }
783
+
784
+ /**
785
+ * Deletes an issue link, thus removes the two-way relationship.
786
+ *
787
+ * <p>NOTE: Only available in GitLab Starter, GitLab Bronze, and higher tiers.</p>
788
+ *
789
+ * <pre><code>GitLab Endpoint: POST /projects/:id/issues/:issue_iid/links/:issue_link_id</code></pre>
790
+ *
791
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
792
+ * @param issueIid the internal ID of a project's issue, required
793
+ * @param issueLinkId the ID of an issue relationship, required
794
+ * @return an instance of IssueLink holding the deleted link relationship
795
+ * @throws GitLabApiException if any exception occurs
796
+ */
797
+ public IssueLink deleteIssueLink (Object projectIdOrPath , Integer issueIid , Integer issueLinkId ) throws GitLabApiException {
798
+ Response response = delete (Response .Status .OK , null ,
799
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "issues" , issueIid , "links" , issueLinkId );
800
+ return (response .readEntity (IssueLink .class ));
801
+ }
701
802
}
0 commit comments