1
1
package org .gitlab4j .api ;
2
2
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 ;
6
5
7
6
import javax .ws .rs .core .Form ;
8
7
import javax .ws .rs .core .GenericType ;
9
8
import 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 ;
12
13
13
14
/**
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.
15
16
*/
16
- public class MileStonesApi extends AbstractApi {
17
+ public class MilestonesApi extends AbstractApi {
17
18
18
- public MileStonesApi (GitLabApi gitLabApi ) {
19
+ public MilestonesApi (GitLabApi gitLabApi ) {
19
20
super (gitLabApi );
20
21
}
21
22
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
+ */
22
30
public List <Milestone > getMilestones (Integer projectId ) throws GitLabApiException {
31
+
23
32
if (projectId == null ) {
24
33
throw new RuntimeException ("projectId cannot be null" );
25
34
}
35
+
26
36
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 >>() {}));
29
38
}
30
39
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
+ */
31
49
public List <Milestone > getMilestones (Integer projectId , int page , int perPage ) throws GitLabApiException {
50
+
32
51
if (projectId == null ) {
33
52
throw new RuntimeException ("projectId cannot be null" );
34
53
}
54
+
35
55
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 >>() {}));
38
57
}
39
58
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
+ */
40
67
public List <Milestone > getMilestones (Integer projectId , MilestoneState state ) throws GitLabApiException {
68
+
41
69
if (projectId == null ) {
42
70
throw new RuntimeException ("projectId cannot be null" );
43
71
}
72
+
44
73
Form formData = new GitLabApiForm ().withParam ("state" , state ).withParam (PER_PAGE_PARAM , getDefaultPerPage ());
45
74
Response response = get (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" );
46
75
return (response .readEntity (new GenericType <List <Milestone >>() {
47
76
}));
48
77
}
49
78
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
+ */
50
87
public List <Milestone > getMilestones (Integer projectId , String search ) throws GitLabApiException {
88
+
51
89
if (projectId == null ) {
52
90
throw new RuntimeException ("projectId cannot be null" );
53
91
}
92
+
54
93
Form formData = new GitLabApiForm ().withParam ("search" , search ).withParam (PER_PAGE_PARAM , getDefaultPerPage ());
55
94
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 >>() {}));
58
96
}
59
97
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
+ */
60
107
public List <Milestone > getMilestones (Integer projectId , MilestoneState state , String search ) throws GitLabApiException {
108
+
61
109
if (projectId == null ) {
62
110
throw new RuntimeException ("projectId cannot be null" );
63
111
}
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 ());
65
117
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 >>() {}));
68
119
}
69
120
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
+ */
70
129
public Milestone getMilestone (Integer projectId , int milestoneId ) throws GitLabApiException {
130
+
71
131
if (projectId == null ) {
72
132
throw new RuntimeException ("projectId cannot be null" );
73
133
}
134
+
74
135
Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "milestones" , milestoneId );
75
136
return (response .readEntity (Milestone .class ));
76
137
}
77
138
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
+ */
78
147
public List <Issue > getIssues (Integer projectId , Integer milestoneId ) throws GitLabApiException {
148
+
79
149
if (projectId == null ) {
80
150
throw new RuntimeException ("projectId cannot be null" );
81
151
}
152
+
82
153
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 >>() {}));
85
155
}
86
156
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
+ */
87
165
public List <MergeRequest > getMergeRequest (Integer projectId , Integer milestoneId ) throws GitLabApiException {
166
+
88
167
if (projectId == null ) {
89
168
throw new RuntimeException ("projectId cannot be null" );
90
169
}
170
+
91
171
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 >>() {}));
94
173
}
95
174
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
+ */
96
186
public Milestone createMilestone (Integer projectId , String title , String description , Date dueDate , Date startDate ) throws GitLabApiException {
187
+
97
188
if (projectId == null ) {
98
189
throw new RuntimeException ("projectId cannot be null" );
99
190
}
191
+
100
192
GitLabApiForm formData = new GitLabApiForm ()
101
193
.withParam ("title" , title , true )
102
194
.withParam ("description" , description )
@@ -106,37 +198,76 @@ public Milestone createMilestone(Integer projectId, String title, String descrip
106
198
return (response .readEntity (Milestone .class ));
107
199
}
108
200
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
+ */
109
209
public Milestone closeMilestone (Integer projectId , Integer milestoneId ) throws GitLabApiException {
210
+
110
211
if (projectId == null ) {
111
212
throw new RuntimeException ("projectId cannot be null" );
112
213
}
214
+
113
215
if (milestoneId == null ) {
114
216
throw new RuntimeException ("milestoneId cannot be null" );
115
217
}
218
+
116
219
GitLabApiForm formData = new GitLabApiForm ().withParam ("state_event" , MilestoneState .CLOSE );
117
220
Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" , milestoneId );
118
221
return (response .readEntity (Milestone .class ));
119
222
}
120
223
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
+ */
121
232
public Milestone activateMilestone (Integer projectId , Integer milestoneId ) throws GitLabApiException {
233
+
122
234
if (projectId == null ) {
123
235
throw new RuntimeException ("projectId cannot be null" );
124
236
}
237
+
125
238
if (milestoneId == null ) {
126
239
throw new RuntimeException ("milestoneId cannot be null" );
127
240
}
241
+
128
242
GitLabApiForm formData = new GitLabApiForm ().withParam ("state_event" , MilestoneState .ACTIVATE );
129
243
Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId , "milestones" , milestoneId );
130
244
return (response .readEntity (Milestone .class ));
131
245
}
132
246
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
+
134
263
if (projectId == null ) {
135
264
throw new RuntimeException ("projectId cannot be null" );
136
265
}
266
+
137
267
if (milestoneId == null ) {
138
268
throw new RuntimeException ("milestoneId cannot be null" );
139
269
}
270
+
140
271
GitLabApiForm formData = new GitLabApiForm ()
141
272
.withParam ("title" , title , true )
142
273
.withParam ("description" , description )
0 commit comments