From b0d9fd6bc784e51dd18a0888f25099be3773645d Mon Sep 17 00:00:00 2001 From: Albert Salim Date: Wed, 18 Nov 2020 16:35:16 +0800 Subject: [PATCH] Add pipeline bridges API https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-bridges --- lib/gitlab/client/jobs.rb | 15 +++++++++++++++ spec/fixtures/pipeline_bridges.json | 1 + spec/gitlab/client/jobs_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 spec/fixtures/pipeline_bridges.json diff --git a/lib/gitlab/client/jobs.rb b/lib/gitlab/client/jobs.rb index 4c61336d3..a961cc8a2 100644 --- a/lib/gitlab/client/jobs.rb +++ b/lib/gitlab/client/jobs.rb @@ -36,6 +36,21 @@ def pipeline_jobs(project_id, pipeline_id, options = {}) get("/projects/#{url_encode project_id}/pipelines/#{pipeline_id}/jobs", query: options) end + # Gets a list of Bridge Jobs from a pipeline + # + # @example + # Gitlab.pipeline_bridges(1, 2) + # Gitlab.pipeline_bridges("project", 2) + # + # @param [Integer, String] The ID or name of a project. + # @param [Integer] the id of the pipeline + # @param [Hash] options A customizable set of options. + # @option options [Array] :scope The scope of bridge jobs to show, one or array of: created, pending, running, failed, success, canceled, skipped, manual; showing all bridge jobs if none provided. + # @return [Array] + def pipeline_bridges(project_id, pipeline_id, options = {}) + get("/projects/#{url_encode project_id}/pipelines/#{pipeline_id}/bridges", query: options) + end + # Gets a single job # # @example diff --git a/spec/fixtures/pipeline_bridges.json b/spec/fixtures/pipeline_bridges.json new file mode 100644 index 000000000..7696413e6 --- /dev/null +++ b/spec/fixtures/pipeline_bridges.json @@ -0,0 +1 @@ +[{"commit":{"author_email":"admin@example.com","author_name":"Administrator","created_at":"2015-12-24T16:51:14.000+01:00","id":"0ff3ae198f8601a285adcf5c0fff204ee6fba5fd","message":"Test the CI integration.","short_id":"0ff3ae19","title":"Test the CI integration."},"coverage":null,"allow_failure":false,"created_at":"2015-12-24T15:51:21.802Z","started_at":"2015-12-24T17:54:27.722Z","finished_at":"2015-12-24T17:58:27.895Z","duration":240,"id":7,"name":"teaspoon","pipeline":{"id":6,"ref":"master","sha":"0ff3ae198f8601a285adcf5c0fff204ee6fba5fd","status":"pending","created_at":"2015-12-24T15:50:16.123Z","updated_at":"2015-12-24T18:00:44.432Z","web_url":"https://example.com/foo/bar/pipelines/6"},"ref":"master","stage":"test","status":"pending","tag":false,"web_url":"https://example.com/foo/bar/-/jobs/7","user":{"id":1,"name":"Administrator","username":"root","state":"active","avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon","web_url":"http://gitlab.dev/root","created_at":"2015-12-21T13:14:24.077Z","bio":null,"location":null,"public_email":"","skype":"","linkedin":"","twitter":"","website_url":"","organization":""},"downstream_pipeline":{"id":5,"sha":"f62a4b2fb89754372a346f24659212eb8da13601","ref":"master","status":"pending","created_at":"2015-12-24T17:54:27.722Z","updated_at":"2015-12-24T17:58:27.896Z","web_url":"https://example.com/diaspora/diaspora-client/pipelines/5"}}] diff --git a/spec/gitlab/client/jobs_spec.rb b/spec/gitlab/client/jobs_spec.rb index 25f8f81a4..29a9e1ce6 100644 --- a/spec/gitlab/client/jobs_spec.rb +++ b/spec/gitlab/client/jobs_spec.rb @@ -47,6 +47,28 @@ end end + describe '.pipeline_bridges' do + before do + stub_get('/projects/1/pipelines/1/bridges', 'pipeline_bridges') + @jobs = Gitlab.pipeline_bridges(1, 1) + end + + it 'gets the correct resource' do + expect(a_get('/projects/1/pipelines/1/bridges')).to have_been_made + end + end + + describe '.pipeline_bridges - with scope' do + before do + stub_get('/projects/1/pipelines/1/bridges?scope[]=running&scope[]=created', 'pipeline_bridges') + @jobs = Gitlab.pipeline_bridges(1, 1, scope: %w[running created]) + end + + it 'gets the correct resource' do + expect(a_get('/projects/1/pipelines/1/bridges?scope[]=running&scope[]=created')).to have_been_made + end + end + describe '.job' do before do stub_get('/projects/1/jobs/1', 'job')