diff options
author | Jonathon Reinhart <Jonathon.Reinhart@gmail.com> | 2017-08-29 22:39:28 -0400 |
---|---|---|
committer | Jonathon Reinhart <Jonathon.Reinhart@gmail.com> | 2018-12-13 22:34:15 -0500 |
commit | 857e86a6e666b20679d5cb43ce85fe9576fea678 (patch) | |
tree | 6f3076c1ad6c583ea58459b2e31a6adb9df42273 | |
parent | cdd9e12beb06354ff0babfb18907d3f184bac547 (diff) | |
download | gitlab-shell-857e86a6e666b20679d5cb43ce85fe9576fea678.tar.gz |
Add lib/hooks_utils.rb
This module is responsible for converting the GIT_PUSH_OPTION_*
environment variables into an array.
See https://gitlab.com/gitlab-org/gitlab-ce/issues/18667
-rw-r--r-- | lib/hooks_utils.rb | 15 | ||||
-rw-r--r-- | spec/hooks_utils_spec.rb | 22 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/hooks_utils.rb b/lib/hooks_utils.rb new file mode 100644 index 0000000..67c45f3 --- /dev/null +++ b/lib/hooks_utils.rb @@ -0,0 +1,15 @@ +module HooksUtils + extend self + + # Gets an array of Git push options from the environment + def get_push_options + count = ENV['GIT_PUSH_OPTION_COUNT'].to_i + result = [] + + count.times do |i| + result.push(ENV["GIT_PUSH_OPTION_#{i}"]) + end + + result + end +end diff --git a/spec/hooks_utils_spec.rb b/spec/hooks_utils_spec.rb new file mode 100644 index 0000000..5246bbc --- /dev/null +++ b/spec/hooks_utils_spec.rb @@ -0,0 +1,22 @@ +require_relative 'spec_helper' +require_relative '../lib/hooks_utils.rb' + +describe :get_push_options do + context "when GIT_PUSH_OPTION_COUNT is not set" do + HooksUtils.get_push_options.should == [] + end + + context "when one option is given" do + ENV['GIT_PUSH_OPTION_COUNT'] = '1' + ENV['GIT_PUSH_OPTION_0'] = 'aaa' + HooksUtils.get_push_options.should == ['aaa'] + end + + context "when multiple options are given" do + ENV['GIT_PUSH_OPTION_COUNT'] = '3' + ENV['GIT_PUSH_OPTION_0'] = 'aaa' + ENV['GIT_PUSH_OPTION_1'] = 'bbb' + ENV['GIT_PUSH_OPTION_2'] = 'ccc' + HooksUtils.get_push_options.should == ['aaa', 'bbb', 'ccc'] + end +end |