From 100e256464a1356221d7e307c0c972a617fcff6a Mon Sep 17 00:00:00 2001 From: Dat Tang Date: Tue, 10 Sep 2024 10:19:57 +0200 Subject: [PATCH] Add get_pipelines_by_pipeline_schedule method GitLab pipeline now support getting all pipelines triggered by a pipeline schedule in a project (https://docs.gitlab.com/ee/api/pipeline_schedules.html#get-all-pipelines-triggered-by-a-pipeline-schedule). --- lib/gitlab/client/pipeline_schedules.rb | 12 ++++++++++++ .../fixtures/pipeline_schedule_get_pipelines.json | 1 + spec/gitlab/client/pipeline_schedules_spec.rb | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 spec/fixtures/pipeline_schedule_get_pipelines.json diff --git a/lib/gitlab/client/pipeline_schedules.rb b/lib/gitlab/client/pipeline_schedules.rb index e7cd78eea..060d01207 100644 --- a/lib/gitlab/client/pipeline_schedules.rb +++ b/lib/gitlab/client/pipeline_schedules.rb @@ -30,6 +30,18 @@ def pipeline_schedule(project, id) get("/projects/#{url_encode project}/pipeline_schedules/#{id}") end + # Get all pipelines triggered by a pipeline schedule + # + # @example + # Gitlab.get_pipelines_by_pipeline_schedule(5, 3) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of the pipeline schedule. + # @return [Array] + def get_pipelines_by_pipeline_schedule(project, id) + get("/projects/#{url_encode project}/pipeline_schedules/#{id}/pipelines") + end + # Create a pipeline schedule. # # @example diff --git a/spec/fixtures/pipeline_schedule_get_pipelines.json b/spec/fixtures/pipeline_schedule_get_pipelines.json new file mode 100644 index 000000000..882b1109a --- /dev/null +++ b/spec/fixtures/pipeline_schedule_get_pipelines.json @@ -0,0 +1 @@ +[{"id":15,"iid":2,"project_id":100,"sha":"a91957a858320c0e17f3a0eca7cfacbff50ea29a","ref":"new-pipeline","status":"pending","source":"schedule","created_at":"2016-08-16T10:23:19.007Z","updated_at":"2016-08-16T10:23:19.216Z","web_url":"http://localhost:3000/root"}] \ No newline at end of file diff --git a/spec/gitlab/client/pipeline_schedules_spec.rb b/spec/gitlab/client/pipeline_schedules_spec.rb index d2ddd8b5c..b5c04ec7e 100644 --- a/spec/gitlab/client/pipeline_schedules_spec.rb +++ b/spec/gitlab/client/pipeline_schedules_spec.rb @@ -33,6 +33,21 @@ end end + describe '.get_pipelines_by_pipeline_schedule' do + before do + stub_get('/projects/3/pipeline_schedules/5/pipelines', 'pipeline_schedule_get_pipelines') + @pipeline_schedule_get_pipelines = Gitlab.get_pipelines_by_pipeline_schedule(3, 5) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/pipeline_schedules/5/pipelines')).to have_been_made + end + + it "returns a response of project's pipeline schedules" do + expect(@pipeline_schedule_get_pipelines).to be_a Gitlab::PaginatedResponse + end + end + describe '.create_pipeline_schedule' do before do stub_post('/projects/3/pipeline_schedules', 'pipeline_schedule_create')