1
1
package org .gitlab4j .api ;
2
2
3
+ import java .io .UnsupportedEncodingException ;
4
+ import java .net .URLEncoder ;
5
+ import java .util .Date ;
6
+ import java .util .List ;
7
+ import java .util .Optional ;
8
+
9
+ import javax .ws .rs .core .Form ;
10
+ import javax .ws .rs .core .GenericType ;
11
+ import javax .ws .rs .core .MultivaluedMap ;
12
+ import javax .ws .rs .core .Response ;
13
+
3
14
import org .gitlab4j .api .models .Comment ;
4
15
import org .gitlab4j .api .models .Commit ;
5
16
import org .gitlab4j .api .models .CommitAction ;
6
17
import org .gitlab4j .api .models .CommitPayload ;
7
18
import org .gitlab4j .api .models .CommitRef ;
8
19
import org .gitlab4j .api .models .CommitRef .RefType ;
20
+ import org .gitlab4j .api .models .CommitStatus ;
21
+ import org .gitlab4j .api .models .CommitStatusFilter ;
9
22
import org .gitlab4j .api .models .Diff ;
10
23
import org .gitlab4j .api .utils .ISO8601 ;
11
24
12
- import javax .ws .rs .core .Form ;
13
- import javax .ws .rs .core .GenericType ;
14
- import javax .ws .rs .core .Response ;
15
- import java .io .UnsupportedEncodingException ;
16
- import java .net .URLEncoder ;
17
- import java .util .Date ;
18
- import java .util .List ;
19
- import java .util .Optional ;
20
-
21
25
/**
22
26
* This class implements the client side API for the GitLab commits calls.
23
27
*/
@@ -287,6 +291,80 @@ public List<CommitRef> getCommitRefs(int projectId, String sha, CommitRef.RefTyp
287
291
return (response .readEntity (new GenericType <List <CommitRef >>(){}));
288
292
}
289
293
294
+ /**
295
+ * Get a list of repository commit statuses that meet the provided filter.
296
+ *
297
+ * GET /projects/:id/repository/commits/:sha/statuses
298
+ *
299
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
300
+ * @param sha the commit SHA
301
+ * @param filter the commit statuses file, contains ref, stage, name, all
302
+ * @return a List containing the commit statuses for the specified project and sha that meet the provided filter
303
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
304
+ */
305
+ public List <CommitStatus > getCommitStatuses (Object projectIdOrPath , String sha , CommitStatusFilter filter ) throws GitLabApiException {
306
+ return (getCommitStatuses (projectIdOrPath , sha , filter , 1 , getDefaultPerPage ()));
307
+ }
308
+
309
+ /**
310
+ * Get a list of repository commit statuses that meet the provided filter.
311
+ *
312
+ * GET /projects/:id/repository/commits/:sha/statuses
313
+ *
314
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
315
+ * @param sha the commit SHA
316
+ * @param filter the commit statuses file, contains ref, stage, name, all
317
+ * @param page the page to get
318
+ * @param perPage the number of commits statuses per page
319
+ * @return a List containing the commit statuses for the specified project and sha that meet the provided filter
320
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
321
+ */
322
+ public List <CommitStatus > getCommitStatuses (Object projectIdOrPath , String sha ,
323
+ CommitStatusFilter filter , int page , int perPage ) throws GitLabApiException {
324
+
325
+ if (projectIdOrPath == null ) {
326
+ throw new RuntimeException ("projectIdOrPath cannot be null" );
327
+ }
328
+
329
+ if (sha == null || sha .trim ().isEmpty ()) {
330
+ throw new RuntimeException ("sha cannot be null" );
331
+ }
332
+
333
+ MultivaluedMap <String , String > queryParams = (filter != null ?
334
+ filter .getQueryParams (page , perPage ).asMap () : getPageQueryParams (page , perPage ));
335
+ Response response = get (Response .Status .OK , queryParams ,
336
+ "projects" , this .getProjectIdOrPath (projectIdOrPath ), "repository" , "commits" , sha , "statuses" );
337
+ return (response .readEntity (new GenericType <List <CommitStatus >>() {}));
338
+ }
339
+
340
+ /**
341
+ * Get a Pager of repository commit statuses that meet the provided filter.
342
+ *
343
+ * GET /projects/:id/repository/commits/:sha/statuses
344
+ *
345
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
346
+ * @param sha the commit SHA
347
+ * @param filter the commit statuses file, contains ref, stage, name, all
348
+ * @param itemsPerPage the number of CommitStatus instances that will be fetched per page
349
+ * @return a Pager containing the commit statuses for the specified project and sha that meet the provided filter
350
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
351
+ */
352
+ public Pager <CommitStatus > getCommitStatuses (Object projectIdOrPath , String sha ,
353
+ CommitStatusFilter filter , int itemsPerPage ) throws GitLabApiException {
354
+
355
+ if (projectIdOrPath == null ) {
356
+ throw new RuntimeException ("projectIdOrPath cannot be null" );
357
+ }
358
+
359
+ if (sha == null || sha .trim ().isEmpty ()) {
360
+ throw new RuntimeException ("sha cannot be null" );
361
+ }
362
+
363
+ MultivaluedMap <String , String > queryParams = (filter != null ? filter .getQueryParams ().asMap () : null );
364
+ return (new Pager <CommitStatus >(this , CommitStatus .class , itemsPerPage , queryParams ,
365
+ "projects" , this .getProjectIdOrPath (projectIdOrPath ), "repository" , "commits" , sha , "statuses" ));
366
+ }
367
+
290
368
/**
291
369
* Get the list of diffs of a commit in a project.
292
370
*
@@ -399,37 +477,7 @@ public Comment addComment(int projectId, String sha, String note) throws GitLabA
399
477
*
400
478
* POST /projects/:id/repository/commits
401
479
*
402
- * @param projectId the ID of the project
403
- * @param branch tame of the branch to commit into. To create a new branch, also provide startBranch
404
- * @param commitMessage the commit message
405
- * @param startBranch the name of the branch to start the new commit from
406
- * @param authorEmail the commit author's email address
407
- * @param authorName the commit author's name
408
- * @param actions the array of CommitAction to commit as a batch
409
- * @return the create Commit instance
410
- * @throws GitLabApiException if any exception occurs during execution
411
- */
412
- public Commit createCommit (int projectId , String branch , String commitMessage , String startBranch ,
413
- String authorEmail , String authorName , List <CommitAction > actions ) throws GitLabApiException {
414
-
415
- CommitPayload payload = new CommitPayload ();
416
- payload .setBranch (branch );
417
- payload .setCommitMessage (commitMessage );
418
- payload .setStartBranch (startBranch );
419
- payload .setAuthorEmail (authorEmail );
420
- payload .setAuthorName (authorName );
421
- payload .setActions (actions );
422
-
423
- Response response = post (Response .Status .CREATED , payload , "projects" , projectId , "repository" , "commits" );
424
- return (response .readEntity (Commit .class ));
425
- }
426
-
427
- /**
428
- * Create a commit with multiple files and actions.
429
- *
430
- * POST /projects/:id/repository/commits
431
- *
432
- * @param project the path of the project
480
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
433
481
* @param branch tame of the branch to commit into. To create a new branch, also provide startBranch
434
482
* @param commitMessage the commit message
435
483
* @param startBranch the name of the branch to start the new commit from
@@ -439,7 +487,7 @@ public Commit createCommit(int projectId, String branch, String commitMessage, S
439
487
* @return the create Commit instance
440
488
* @throws GitLabApiException if any exception occurs during execution
441
489
*/
442
- public Commit createCommit (String project , String branch , String commitMessage , String startBranch ,
490
+ public Commit createCommit (Object projectIdOrPath , String branch , String commitMessage , String startBranch ,
443
491
String authorEmail , String authorName , List <CommitAction > actions ) throws GitLabApiException {
444
492
445
493
CommitPayload payload = new CommitPayload ();
@@ -450,7 +498,7 @@ public Commit createCommit(String project, String branch, String commitMessage,
450
498
payload .setAuthorName (authorName );
451
499
payload .setActions (actions );
452
500
453
- Response response = post (Response .Status .CREATED , payload , "projects" , urlEncode ( project ), "repository" , "commits" );
501
+ Response response = post (Response .Status .CREATED , payload , "projects" , getProjectIdOrPath ( projectIdOrPath ), "repository" , "commits" );
454
502
return (response .readEntity (Commit .class ));
455
503
}
456
504
}
0 commit comments