From b034721fc1b23ecd9729cd0978a5d784533c6f00 Mon Sep 17 00:00:00 2001 From: Ronan Potage Date: Fri, 16 Sep 2022 19:05:29 -0700 Subject: [PATCH 1/2] Add Pipeline Variables endpoint `Gitlab.pipeline_variables(12, 3)` https://docs.gitlab.com/ee/api/pipelines.html#get-variables-of-a-pipeline --- lib/gitlab/client/pipelines.rb | 12 ++++++++++++ spec/fixtures/pipeline_variables.json | 11 +++++++++++ spec/gitlab/client/pipelines_spec.rb | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 spec/fixtures/pipeline_variables.json diff --git a/lib/gitlab/client/pipelines.rb b/lib/gitlab/client/pipelines.rb index b4970544d..58f5601fc 100644 --- a/lib/gitlab/client/pipelines.rb +++ b/lib/gitlab/client/pipelines.rb @@ -43,6 +43,18 @@ def pipeline_test_report(project, id) get("/projects/#{url_encode project}/pipelines/#{id}/test_report") end + # Gets a single pipeline's variables. + # + # @example + # Gitlab.pipeline_variables(5, 36) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a pipeline. + # @return [Array] + def pipeline_variables(project, id) + get("/projects/#{url_encode project}/pipelines/#{id}/variables") + end + # Create a pipeline. # # @example diff --git a/spec/fixtures/pipeline_variables.json b/spec/fixtures/pipeline_variables.json new file mode 100644 index 000000000..49494a084 --- /dev/null +++ b/spec/fixtures/pipeline_variables.json @@ -0,0 +1,11 @@ +[ + { + "key": "RUN_NIGHTLY_BUILD", + "variable_type": "env_var", + "value": "true" + }, + { + "key": "foo", + "value": "bar" + } +] diff --git a/spec/gitlab/client/pipelines_spec.rb b/spec/gitlab/client/pipelines_spec.rb index b6955ffc8..9ea87bc6c 100644 --- a/spec/gitlab/client/pipelines_spec.rb +++ b/spec/gitlab/client/pipelines_spec.rb @@ -58,6 +58,25 @@ end end + describe '.pipeline_variables' do + before do + stub_get('/projects/3/pipelines/46/variables', 'pipeline_variables') + @variables = Gitlab.pipeline_variables(3, 46) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/pipelines/46/variables')).to have_been_made + end + + it 'returns a paginated response of pipeline variables' do + expect(@variables).to be_a Gitlab::PaginatedResponse + end + + it "returns pipeline's variables" do + expect(@variables[0]["key"]).to eq('RUN_NIGHTLY_BUILD') + end + end + describe '.create_pipeline' do let(:pipeline_path) { '/projects/3/pipeline?ref=master' } From 7311bc45ca65185b15e5ecfaac06be427496e3c7 Mon Sep 17 00:00:00 2001 From: Ronan Potage Date: Fri, 16 Sep 2022 19:25:07 -0700 Subject: [PATCH 2/2] fix quotes --- spec/gitlab/client/pipelines_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/gitlab/client/pipelines_spec.rb b/spec/gitlab/client/pipelines_spec.rb index 9ea87bc6c..d57246a03 100644 --- a/spec/gitlab/client/pipelines_spec.rb +++ b/spec/gitlab/client/pipelines_spec.rb @@ -73,7 +73,7 @@ end it "returns pipeline's variables" do - expect(@variables[0]["key"]).to eq('RUN_NIGHTLY_BUILD') + expect(@variables[0]['key']).to eq('RUN_NIGHTLY_BUILD') end end