|
1 | 1 | package org.gitlab4j.api; |
2 | 2 |
|
3 | 3 | import java.util.List; |
| 4 | +import java.util.Optional; |
4 | 5 | import java.util.stream.Stream; |
5 | 6 |
|
6 | 7 | import javax.ws.rs.core.GenericType; |
7 | 8 | import javax.ws.rs.core.Response; |
8 | 9 |
|
9 | 10 | import org.gitlab4j.api.models.Pipeline; |
| 11 | +import org.gitlab4j.api.models.PipelineSchedule; |
10 | 12 | import org.gitlab4j.api.models.PipelineStatus; |
11 | 13 |
|
12 | 14 | /** |
@@ -271,4 +273,167 @@ public Pipeline cancelPipelineJobs(Object projectIdOrPath, int pipelineId) throw |
271 | 273 | Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "cancel"); |
272 | 274 | return (response.readEntity(Pipeline.class)); |
273 | 275 | } |
| 276 | + |
| 277 | + /** |
| 278 | + * Get a list of the project pipeline_schedules for the specified project. |
| 279 | + * |
| 280 | + * <pre><code>GET /projects/:id/pipeline_schedules</code></pre> |
| 281 | + * |
| 282 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 283 | + * @return a list of pipeline schedules for the specified project |
| 284 | + * @throws GitLabApiException if any exception occurs |
| 285 | + */ |
| 286 | + public List<PipelineSchedule> getPipelineSchedules(Object projectIdOrPath) throws GitLabApiException { |
| 287 | + return (getPipelineSchedules(projectIdOrPath, getDefaultPerPage()).all()); |
| 288 | + } |
| 289 | + /** |
| 290 | + * Get list of project pipeline schedules in the specified page range. |
| 291 | + * |
| 292 | + * <pre><code>GET /projects/:id/pipeline_schedules</code></pre> |
| 293 | + * |
| 294 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 295 | + * @param page the page to get |
| 296 | + * @param perPage the number of ProjectHook instances per page |
| 297 | + * @return a list of project pipeline_schedules for the specified project in the specified page range |
| 298 | + * @throws GitLabApiException if any exception occurs |
| 299 | + */ |
| 300 | + public List<PipelineSchedule> getPipelineSchedules(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { |
| 301 | + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules"); |
| 302 | + return (response.readEntity(new GenericType<List<PipelineSchedule>>() {})); |
| 303 | + } |
| 304 | + /** |
| 305 | + * Get Pager of project pipeline schedule. |
| 306 | + * |
| 307 | + * <pre><code>GET /projects/:id/pipeline_schedule</code></pre> |
| 308 | + * |
| 309 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 310 | + * @param itemsPerPage the number of Project instances that will be fetched per page |
| 311 | + * @return a Pager of project pipeline_schedules for the specified project |
| 312 | + * @throws GitLabApiException if any exception occurs |
| 313 | + */ |
| 314 | + public Pager<PipelineSchedule> getPipelineSchedules(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { |
| 315 | + return (new Pager<PipelineSchedule>(this, PipelineSchedule.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules")); |
| 316 | + } |
| 317 | + |
| 318 | + /** |
| 319 | + * Get a Stream of the project pipeline schedule for the specified project. |
| 320 | + * |
| 321 | + * <pre><code>GET /projects/:id/pipeline_schedule</code></pre> |
| 322 | + * |
| 323 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 324 | + * @return a Stream of project pipeline schedules for the specified project |
| 325 | + * @throws GitLabApiException if any exception occurs |
| 326 | + */ |
| 327 | + public Stream<PipelineSchedule> getPipelineSchedulesStream(Object projectIdOrPath) throws GitLabApiException { |
| 328 | + return (getPipelineSchedules(projectIdOrPath, getDefaultPerPage()).stream()); |
| 329 | + } |
| 330 | + |
| 331 | + |
| 332 | + /** |
| 333 | + * Get a specific pipeline schedule for project. |
| 334 | + * |
| 335 | + * <pre><code>GET /projects/:id/pipeline_schedules/:pipeline_schedule_id</code></pre> |
| 336 | + * |
| 337 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 338 | + * @param pipelineScheduleId the ID of the hook to get |
| 339 | + * @return the project hook for the specified project ID/hook ID pair |
| 340 | + * @throws GitLabApiException if any exception occurs |
| 341 | + */ |
| 342 | + public PipelineSchedule getPipelineSchedule(Object projectIdOrPath, Integer pipelineScheduleId) throws GitLabApiException { |
| 343 | + Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId); |
| 344 | + return (response.readEntity(PipelineSchedule.class)); |
| 345 | + } |
| 346 | + |
| 347 | + /** |
| 348 | + * Get a specific pipeline schedule for project as an Optional instance. |
| 349 | + * |
| 350 | + * <pre><code>GET /projects/:id/pipeline_schedules/:pipeline_schedule_id</code></pre> |
| 351 | + * |
| 352 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 353 | + * @param pipelineScheduleId the ID of the hook to get |
| 354 | + * @return the project hook for the specified project ID/hook ID pair as an Optional instance |
| 355 | + */ |
| 356 | + public Optional<PipelineSchedule> getOptionalPipelineSchedule (Object projectIdOrPath, Integer pipelineScheduleId) { |
| 357 | + try { |
| 358 | + return (Optional.ofNullable(getPipelineSchedule(projectIdOrPath, pipelineScheduleId))); |
| 359 | + } catch (GitLabApiException glae) { |
| 360 | + return (GitLabApi.createOptionalFromException(glae)); |
| 361 | + } |
| 362 | + } |
| 363 | + |
| 364 | + /** |
| 365 | + * create a pipeline schedule for a project. |
| 366 | + * |
| 367 | + * <pre><code>POST /projects/:id/pipeline_schedules</code></pre> |
| 368 | + * |
| 369 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 370 | + * @param pipelineSchedule a PipelineSchedule instance to create |
| 371 | + * @return the added PipelineSchedule instance |
| 372 | + * @throws GitLabApiException if any exception occurs |
| 373 | + */ |
| 374 | + public PipelineSchedule createPipelineSchedule(Object projectIdOrPath, PipelineSchedule pipelineSchedule) |
| 375 | + throws GitLabApiException { |
| 376 | + |
| 377 | + GitLabApiForm formData = new GitLabApiForm() |
| 378 | + .withParam("description", pipelineSchedule.getDescription(), true) |
| 379 | + .withParam("ref", pipelineSchedule.getRef(), true) |
| 380 | + .withParam("cron", pipelineSchedule.getCron(), true) |
| 381 | + .withParam("cron_timezone", pipelineSchedule.getCronTimezone(), false) |
| 382 | + .withParam("active", pipelineSchedule.getActive(), false); |
| 383 | + Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules"); |
| 384 | + return (response.readEntity(PipelineSchedule.class)); |
| 385 | + } |
| 386 | + |
| 387 | + /** |
| 388 | + * Deletes a pipeline schedule from the project. |
| 389 | + * |
| 390 | + * <pre><code>DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id</code></pre> |
| 391 | + * |
| 392 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 393 | + * @param pipelineScheduleId the project schedule ID to delete |
| 394 | + * @throws GitLabApiException if any exception occurs |
| 395 | + */ |
| 396 | + public void deletePipelineSchedule(Object projectIdOrPath, Integer pipelineScheduleId) throws GitLabApiException { |
| 397 | + Response.Status expectedStatus = (isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); |
| 398 | + delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId); |
| 399 | + } |
| 400 | + |
| 401 | + /** |
| 402 | + * Modifies a pipeline schedule for project. |
| 403 | + * |
| 404 | + * <pre><code>PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id</code></pre> |
| 405 | + * |
| 406 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 407 | + * @param pipelineSchedule the pipelineSchedule instance that contains the pipelineSchedule info to modify |
| 408 | + * @return the modified project schedule |
| 409 | + * @throws GitLabApiException if any exception occurs |
| 410 | + */ |
| 411 | + public PipelineSchedule modifyPipelineSchedule(Object projectIdOrPath,PipelineSchedule pipelineSchedule) throws GitLabApiException { |
| 412 | + |
| 413 | + GitLabApiForm formData = new GitLabApiForm() |
| 414 | + .withParam("description", pipelineSchedule.getDescription(), false) |
| 415 | + .withParam("ref", pipelineSchedule.getRef(), false) |
| 416 | + .withParam("cron", pipelineSchedule.getCron(), false) |
| 417 | + .withParam("cron_timezone", pipelineSchedule.getCronTimezone(), false) |
| 418 | + .withParam("active", pipelineSchedule.getActive(), false); |
| 419 | + |
| 420 | + Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineSchedule.getId()); |
| 421 | + return (response.readEntity(PipelineSchedule.class)); |
| 422 | + } |
| 423 | + |
| 424 | + /** |
| 425 | + * Update the owner of the pipeline schedule of a project. |
| 426 | + * |
| 427 | + * <pre><code>POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership</code></pre> |
| 428 | + * |
| 429 | + * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required |
| 430 | + * @param pipelineScheduleId the pipelineSchedule instance id that ownership has to be taken of |
| 431 | + * @return the modified project schedule |
| 432 | + * @throws GitLabApiException if any exception occurs |
| 433 | + */ |
| 434 | + public PipelineSchedule takeOwnershipPipelineSchedule(Object projectIdOrPath, Integer pipelineScheduleId) throws GitLabApiException { |
| 435 | + |
| 436 | + Response response = post(Response.Status.OK, "", "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId, "take_ownership"); |
| 437 | + return (response.readEntity(PipelineSchedule.class)); |
| 438 | + } |
274 | 439 | } |
0 commit comments