Skip to content

Commit

Permalink
Add get_pipelines_by_pipeline_schedule method
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Dat Tang committed Sep 10, 2024
1 parent f3bd928 commit 100e256
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/gitlab/client/pipeline_schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gitlab::ObjectifiedHash>]
def get_pipelines_by_pipeline_schedule(project, id)
get("/projects/#{url_encode project}/pipeline_schedules/#{id}/pipelines")
end

# Create a pipeline schedule.
#
# @example
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/pipeline_schedule_get_pipelines.json
Original file line number Diff line number Diff line change
@@ -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"}]
15 changes: 15 additions & 0 deletions spec/gitlab/client/pipeline_schedules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 100e256

Please sign in to comment.