Commit 857e86a6 authored by Jonathon Reinhart's avatar Jonathon Reinhart

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
parent cdd9e12b
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment