|
11 | 11 |
|
12 | 12 | import org.gitlab4j.api.models.Comment;
|
13 | 13 | import org.gitlab4j.api.models.Commit;
|
| 14 | +import org.gitlab4j.api.models.CommitAction; |
| 15 | +import org.gitlab4j.api.models.CommitPayload; |
14 | 16 | import org.gitlab4j.api.models.Diff;
|
15 | 17 | import org.gitlab4j.api.utils.ISO8601;
|
16 | 18 |
|
@@ -283,4 +285,64 @@ public Comment addComment(int projectId, String sha, String note, String path, I
|
283 | 285 | public Comment addComment(int projectId, String sha, String note) throws GitLabApiException {
|
284 | 286 | return (addComment(projectId, sha, note, null, null, null));
|
285 | 287 | }
|
| 288 | + |
| 289 | + /** |
| 290 | + * Create a commit with multiple files and actions. |
| 291 | + * |
| 292 | + * POST /projects/:id/repository/commits |
| 293 | + * |
| 294 | + * @param projectId the ID of the project |
| 295 | + * @param branch tame of the branch to commit into. To create a new branch, also provide startBranch |
| 296 | + * @param commitMessage the commit message |
| 297 | + * @param startBranch the name of the branch to start the new commit from |
| 298 | + * @param authorEmail the commit author's email address |
| 299 | + * @param authorName the commit author's name |
| 300 | + * @param actions the array of CommitAction to commit as a batch |
| 301 | + * @return the create Commit instance |
| 302 | + * @throws GitLabApiException |
| 303 | + */ |
| 304 | + public Commit createCommit(int projectId, String branch, String commitMessage, String startBranch, |
| 305 | + String authorEmail, String authorName, List<CommitAction> actions) throws GitLabApiException { |
| 306 | + |
| 307 | + CommitPayload payload = new CommitPayload(); |
| 308 | + payload.setBranch(branch); |
| 309 | + payload.setCommitMessage(commitMessage); |
| 310 | + payload.setStartBranch(startBranch); |
| 311 | + payload.setAuthorEmail(authorEmail); |
| 312 | + payload.setAuthorName(authorName); |
| 313 | + payload.setActions(actions); |
| 314 | + |
| 315 | + Response response = post(Response.Status.CREATED, payload, "projects", projectId, "repository", "commits"); |
| 316 | + return (response.readEntity(Commit.class)); |
| 317 | + } |
| 318 | + |
| 319 | + /** |
| 320 | + * Create a commit with multiple files and actions. |
| 321 | + * |
| 322 | + * POST /projects/:id/repository/commits |
| 323 | + * |
| 324 | + * @param project the path of the project |
| 325 | + * @param branch tame of the branch to commit into. To create a new branch, also provide startBranch |
| 326 | + * @param commitMessage the commit message |
| 327 | + * @param startBranch the name of the branch to start the new commit from |
| 328 | + * @param authorEmail the commit author's email address |
| 329 | + * @param authorName the commit author's name |
| 330 | + * @param actions the array of CommitAction to commit as a batch |
| 331 | + * @return the create Commit instance |
| 332 | + * @throws GitLabApiException |
| 333 | + */ |
| 334 | + public Commit createCommit(String project, String branch, String commitMessage, String startBranch, |
| 335 | + String authorEmail, String authorName, List<CommitAction> actions) throws GitLabApiException { |
| 336 | + |
| 337 | + CommitPayload payload = new CommitPayload(); |
| 338 | + payload.setBranch(branch); |
| 339 | + payload.setCommitMessage(commitMessage); |
| 340 | + payload.setStartBranch(startBranch); |
| 341 | + payload.setAuthorEmail(authorEmail); |
| 342 | + payload.setAuthorName(authorName); |
| 343 | + payload.setActions(actions); |
| 344 | + |
| 345 | + Response response = post(Response.Status.CREATED, payload, "projects", urlEncode(project), "repository", "commits"); |
| 346 | + return (response.readEntity(Commit.class)); |
| 347 | + } |
286 | 348 | }
|
0 commit comments