11package org .gitlab4j .api ;
22
3- import org .gitlab4j .api .models .Issue ;
4- import org .gitlab4j .api .models .MergeRequest ;
5- import org .gitlab4j .api .models .Milestone ;
3+ import java .util .Date ;
4+ import java .util .List ;
65
76import javax .ws .rs .core .Form ;
87import javax .ws .rs .core .GenericType ;
98import javax .ws .rs .core .Response ;
10- import java .util .Date ;
11- import java .util .List ;
9+
10+ import org .gitlab4j .api .models .Issue ;
11+ import org .gitlab4j .api .models .MergeRequest ;
12+ import org .gitlab4j .api .models .Milestone ;
1213
1314/**
14- * This class implements the client side API for the GitLab groups calls.
15+ * This class implements the client side API for the GitLab milestones calls.
1516 */
16- public class MileStonesApi extends AbstractApi {
17+ public class MilestonesApi extends AbstractApi {
1718
18- public MileStonesApi (GitLabApi gitLabApi ) {
19+ public MilestonesApi (GitLabApi gitLabApi ) {
1920 super (gitLabApi );
2021 }
2122
23+ /**
24+ * Get a list of project milestones.
25+ *
26+ * @param projectId the project ID to get the milestones for
27+ * @return the milestones associated with the specified project
28+ * @throws GitLabApiException if any exception occurs
29+ */
2230 public List <Milestone > getMilestones (Integer projectId ) throws GitLabApiException {
31+
2332 if (projectId == null ) {
2433 throw new RuntimeException ("projectId cannot be null" );
2534 }
35+
2636 Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "milestones" );
27- return (response .readEntity (new GenericType <List <Milestone >>() {
28- }));
37+ return (response .readEntity (new GenericType <List <Milestone >>() {}));
2938 }
3039
40+ /**
41+ * Get a list of project milestones.
42+ *
43+ * @param projectId the project ID to get the milestones for
44+ * @param page the page number to get
45+ * @param perPage how many milestones per page
46+ * @return the milestones associated with the specified project
47+ * @throws GitLabApiException if any exception occurs
48+ */
3149 public List <Milestone > getMilestones (Integer projectId , int page , int perPage ) throws GitLabApiException {
50+
3251 if (projectId == null ) {
3352 throw new RuntimeException ("projectId cannot be null" );
3453 }
54+
3555 Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ), "projects" , projectId , "milestones" );
36- return (response .readEntity (new GenericType <List <Milestone >>() {
37- }));
56+ return (response .readEntity (new GenericType <List <Milestone >>() {}));
3857 }
3958
59+ /**
60+ * Get a list of project milestones that have the specified state.
61+ *
62+ * @param projectId the project ID to get the milestones for
63+ * @param state the milestone state
64+ * @return the milestones associated with the specified project and state
65+ * @throws GitLabApiException if any exception occurs
66+ */
4067 public List <Milestone > getMilestones (Integer projectId , MilestoneState state ) throws GitLabApiException {
68+
4169 if (projectId == null ) {
4270 throw new RuntimeException ("projectId cannot be null" );
4371 }
72+
4473 Form formData = new GitLabApiForm ().withParam ("state" , state ).withParam (PER_PAGE_PARAM , getDefaultPerPage ());
4574 Response response = get (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" );
4675 return (response .readEntity (new GenericType <List <Milestone >>() {
4776 }));
4877 }
4978
79+ /**
80+ * Get a list of project milestones that have match the search string.
81+ *
82+ * @param projectId the project ID to get the milestones for
83+ * @param search the search string
84+ * @return the milestones associated with the specified project
85+ * @throws GitLabApiException if any exception occurs
86+ */
5087 public List <Milestone > getMilestones (Integer projectId , String search ) throws GitLabApiException {
88+
5189 if (projectId == null ) {
5290 throw new RuntimeException ("projectId cannot be null" );
5391 }
92+
5493 Form formData = new GitLabApiForm ().withParam ("search" , search ).withParam (PER_PAGE_PARAM , getDefaultPerPage ());
5594 Response response = get (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" );
56- return (response .readEntity (new GenericType <List <Milestone >>() {
57- }));
95+ return (response .readEntity (new GenericType <List <Milestone >>() {}));
5896 }
5997
98+ /**
99+ * Get a list of project milestones that have the specified state and match the search string.
100+ *
101+ * @param projectId the project ID to get the milestones for
102+ * @param state the milestone state
103+ * @param search the search string
104+ * @return the milestones associated with the specified project
105+ * @throws GitLabApiException if any exception occurs
106+ */
60107 public List <Milestone > getMilestones (Integer projectId , MilestoneState state , String search ) throws GitLabApiException {
108+
61109 if (projectId == null ) {
62110 throw new RuntimeException ("projectId cannot be null" );
63111 }
64- Form formData = new GitLabApiForm ().withParam ("state" , state ).withParam ("search" , search ).withParam (PER_PAGE_PARAM , getDefaultPerPage ());
112+
113+ Form formData = new GitLabApiForm ()
114+ .withParam ("state" , state )
115+ .withParam ("search" , search )
116+ .withParam (PER_PAGE_PARAM , getDefaultPerPage ());
65117 Response response = get (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" );
66- return (response .readEntity (new GenericType <List <Milestone >>() {
67- }));
118+ return (response .readEntity (new GenericType <List <Milestone >>() {}));
68119 }
69120
121+ /**
122+ * Get the specified milestone.
123+ *
124+ * @param projectId the project ID to get the milestone for
125+ * @param milestoneId the ID of the milestone tp get
126+ * @return a Milestone instance for the specified IDs
127+ * @throws GitLabApiException if any exception occurs
128+ */
70129 public Milestone getMilestone (Integer projectId , int milestoneId ) throws GitLabApiException {
130+
71131 if (projectId == null ) {
72132 throw new RuntimeException ("projectId cannot be null" );
73133 }
134+
74135 Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "milestones" , milestoneId );
75136 return (response .readEntity (Milestone .class ));
76137 }
77138
139+ /**
140+ * Get the list of issues associated with the specified milestone.
141+ *
142+ * @param projectId the project ID to get the milestone issues for
143+ * @param milestoneId the milestone ID to get the issues for
144+ * @return a List of Issue for the milestone
145+ * @throws GitLabApiException if any exception occurs
146+ */
78147 public List <Issue > getIssues (Integer projectId , Integer milestoneId ) throws GitLabApiException {
148+
79149 if (projectId == null ) {
80150 throw new RuntimeException ("projectId cannot be null" );
81151 }
152+
82153 Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "milestones" , milestoneId , "issues" );
83- return (response .readEntity (new GenericType <List <Issue >>() {
84- }));
154+ return (response .readEntity (new GenericType <List <Issue >>() {}));
85155 }
86156
157+ /**
158+ * Get the list of merge requests associated with the specified milestone.
159+ *
160+ * @param projectId the project ID to get the milestone merge requests for
161+ * @param milestoneId the milestone ID to get the merge requests for
162+ * @return a list of merge requests associated with the specified milestone
163+ * @throws GitLabApiException if any exception occurs
164+ */
87165 public List <MergeRequest > getMergeRequest (Integer projectId , Integer milestoneId ) throws GitLabApiException {
166+
88167 if (projectId == null ) {
89168 throw new RuntimeException ("projectId cannot be null" );
90169 }
170+
91171 Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "milestones" , milestoneId , "merge_requests" );
92- return (response .readEntity (new GenericType <List <MergeRequest >>() {
93- }));
172+ return (response .readEntity (new GenericType <List <MergeRequest >>() {}));
94173 }
95174
175+ /**
176+ * Create a milestone.
177+ *
178+ * @param projectId the project ID to create a milestone for
179+ * @param title the title for the milestone
180+ * @param description the description for the milestone
181+ * @param dueDate the due date for the milestone
182+ * @param startDate the start date for the milestone
183+ * @return the created Milestone instance
184+ * @throws GitLabApiException if any exception occurs
185+ */
96186 public Milestone createMilestone (Integer projectId , String title , String description , Date dueDate , Date startDate ) throws GitLabApiException {
187+
97188 if (projectId == null ) {
98189 throw new RuntimeException ("projectId cannot be null" );
99190 }
191+
100192 GitLabApiForm formData = new GitLabApiForm ()
101193 .withParam ("title" , title , true )
102194 .withParam ("description" , description )
@@ -106,37 +198,76 @@ public Milestone createMilestone(Integer projectId, String title, String descrip
106198 return (response .readEntity (Milestone .class ));
107199 }
108200
201+ /**
202+ * Close a milestone.
203+ *
204+ * @param projectId the project ID of the milestone
205+ * @param milestoneId the milestone ID to close
206+ * @return the closed Milestone instance
207+ * @throws GitLabApiException if any exception occurs
208+ */
109209 public Milestone closeMilestone (Integer projectId , Integer milestoneId ) throws GitLabApiException {
210+
110211 if (projectId == null ) {
111212 throw new RuntimeException ("projectId cannot be null" );
112213 }
214+
113215 if (milestoneId == null ) {
114216 throw new RuntimeException ("milestoneId cannot be null" );
115217 }
218+
116219 GitLabApiForm formData = new GitLabApiForm ().withParam ("state_event" , MilestoneState .CLOSE );
117220 Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" , milestoneId );
118221 return (response .readEntity (Milestone .class ));
119222 }
120223
224+ /**
225+ * Activate a milestone.
226+ *
227+ * @param projectId the project ID of the milestone
228+ * @param milestoneId the milestone ID to activate
229+ * @return the activated Milestone instance
230+ * @throws GitLabApiException if any exception occurs
231+ */
121232 public Milestone activateMilestone (Integer projectId , Integer milestoneId ) throws GitLabApiException {
233+
122234 if (projectId == null ) {
123235 throw new RuntimeException ("projectId cannot be null" );
124236 }
237+
125238 if (milestoneId == null ) {
126239 throw new RuntimeException ("milestoneId cannot be null" );
127240 }
241+
128242 GitLabApiForm formData = new GitLabApiForm ().withParam ("state_event" , MilestoneState .ACTIVATE );
129243 Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" , milestoneId );
130244 return (response .readEntity (Milestone .class ));
131245 }
132246
133- public Milestone updateMilestone (Integer projectId , Integer milestoneId , String title , String description , Date dueDate , Date startDate , MilestoneState milestoneState ) throws GitLabApiException {
247+ /**
248+ * Update the specified milestone.
249+ *
250+ * @param projectId the project ID of the milestone
251+ * @param milestoneId the milestone ID to update
252+ * @param title the updated title for the milestone
253+ * @param description the updated description for the milestone
254+ * @param dueDate the updated due date for the milestone
255+ * @param startDate the updated start date for the milestone
256+ * @param milestoneState the updated milestone state
257+ * @return the updated Milestone instance
258+ * @throws GitLabApiException if any exception occurs
259+ */
260+ public Milestone updateMilestone (Integer projectId , Integer milestoneId , String title , String description ,
261+ Date dueDate , Date startDate , MilestoneState milestoneState ) throws GitLabApiException {
262+
134263 if (projectId == null ) {
135264 throw new RuntimeException ("projectId cannot be null" );
136265 }
266+
137267 if (milestoneId == null ) {
138268 throw new RuntimeException ("milestoneId cannot be null" );
139269 }
270+
140271 GitLabApiForm formData = new GitLabApiForm ()
141272 .withParam ("title" , title , true )
142273 .withParam ("description" , description )
0 commit comments