1313import org .gitlab4j .api .models .Comment ;
1414import org .gitlab4j .api .models .Commit ;
1515import org .gitlab4j .api .models .CommitAction ;
16+ import org .gitlab4j .api .models .CommitAction .Action ;
1617import org .gitlab4j .api .models .CommitPayload ;
1718import org .gitlab4j .api .models .CommitRef ;
1819import org .gitlab4j .api .models .CommitRef .RefType ;
2324
2425/**
2526 * This class implements the client side API for the GitLab commits calls.
27+ * See <a href="https://docs.gitlab.com/ce/api/commits.html">Commits API at GitLab</a> for more information.
2628 */
2729public class CommitsApi extends AbstractApi {
2830
@@ -566,6 +568,23 @@ public Comment addComment(Object projectIdOrPath, String sha, String note) throw
566568 public Commit createCommit (Object projectIdOrPath , String branch , String commitMessage , String startBranch ,
567569 String authorEmail , String authorName , List <CommitAction > actions ) throws GitLabApiException {
568570
571+ // Validate the actions
572+ if (actions == null || actions .isEmpty ()) {
573+ throw new GitLabApiException ("actions cannot be null or empty." );
574+ }
575+
576+ for (CommitAction action : actions ) {
577+
578+ // File content is required for create and update
579+ Action actionType = action .getAction ();
580+ if (actionType == Action .CREATE || actionType == Action .UPDATE ) {
581+ String content = action .getContent ();
582+ if (content == null ) {
583+ throw new GitLabApiException ("Content cannot be null for create or update actions." );
584+ }
585+ }
586+ }
587+
569588 CommitPayload payload = new CommitPayload ();
570589 payload .setBranch (branch );
571590 payload .setCommitMessage (commitMessage );
@@ -574,7 +593,8 @@ public Commit createCommit(Object projectIdOrPath, String branch, String commitM
574593 payload .setAuthorName (authorName );
575594 payload .setActions (actions );
576595
577- Response response = post (Response .Status .CREATED , payload , "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "commits" );
596+ Response response = post (Response .Status .CREATED , payload ,
597+ "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "commits" );
578598 return (response .readEntity (Commit .class ));
579599 }
580600}
0 commit comments