diff --git a/lib/gitlab/cli_helpers.rb b/lib/gitlab/cli_helpers.rb index 138cb9fe6..fcfd28735 100644 --- a/lib/gitlab/cli_helpers.rb +++ b/lib/gitlab/cli_helpers.rb @@ -231,9 +231,16 @@ def symbolize_keys(hash) hash end + # Check if arg is a color in 6-digit hex notation with leading '#' sign + def hex_color?(arg) + pattern = /\A#\h{6}\Z/ + + pattern.match(arg) + end + # YAML::load on a single argument def yaml_load(arg) - YAML.safe_load(arg) + hex_color?(arg) ? arg : YAML.safe_load(arg) rescue Psych::SyntaxError raise "Error: Argument is not valid YAML syntax: #{arg}" end diff --git a/spec/gitlab/cli_spec.rb b/spec/gitlab/cli_spec.rb index 07bf79633..3b1b76800 100644 --- a/spec/gitlab/cli_spec.rb +++ b/spec/gitlab/cli_spec.rb @@ -62,6 +62,18 @@ expect(@output).to include('Jack Smith') end end + + context 'when command is create_label' do + before do + stub_post('/projects/Project/labels', 'label') + args = ['Project', 'Backlog', '#DD10AA'] + @output = capture_output { described_class.run('create_label', args) } + end + + it 'shows executed command' do + expect(@output).to include('Gitlab.create_label Project, Backlog, #DD10AA') + end + end end describe '.start' do