Commit 1255205d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add method that returns commands for ci job entry

parent bd807503
...@@ -55,12 +55,7 @@ module Ci ...@@ -55,12 +55,7 @@ module Ci
{ {
stage_idx: @stages.index(job[:stage]), stage_idx: @stages.index(job[:stage]),
stage: job[:stage], stage: job[:stage],
## commands: job[:commands],
# Refactoring note:
# - before script behaves differently than after script
# - after script returns an array of commands
# - before script should be a concatenated command
commands: [job[:before_script], job[:script]].flatten.compact.join("\n"),
tag_list: job[:tags] || [], tag_list: job[:tags] || [],
name: job[:name].to_s, name: job[:name].to_s,
allow_failure: job[:allow_failure] || false, allow_failure: job[:allow_failure] || false,
......
...@@ -80,7 +80,7 @@ module Gitlab ...@@ -80,7 +80,7 @@ module Gitlab
helpers :before_script, :script, :stage, :type, :after_script, helpers :before_script, :script, :stage, :type, :after_script,
:cache, :image, :services, :only, :except, :variables, :cache, :image, :services, :only, :except, :variables,
:artifacts :artifacts, :commands
def compose!(deps = nil) def compose!(deps = nil)
super do super do
...@@ -102,6 +102,10 @@ module Gitlab ...@@ -102,6 +102,10 @@ module Gitlab
@config.merge(to_hash.compact) @config.merge(to_hash.compact)
end end
def commands
(before_script_value.to_a + script_value.to_a).join("\n")
end
private private
def inherit!(deps) def inherit!(deps)
...@@ -121,6 +125,7 @@ module Gitlab ...@@ -121,6 +125,7 @@ module Gitlab
{ name: name, { name: name,
before_script: before_script, before_script: before_script,
script: script, script: script,
commands: commands,
image: image, image: image,
services: services, services: services,
stage: stage, stage: stage,
......
...@@ -141,9 +141,10 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -141,9 +141,10 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#jobs' do describe '#jobs' do
it 'returns jobs configuration' do it 'returns jobs configuration' do
expect(global.jobs).to eq( expect(global.jobs).to eq(
rspec: { script: %w[rspec ls], rspec: { name: :rspec,
name: :rspec, script: %w[rspec ls],
before_script: ['ls', 'pwd'], before_script: ['ls', 'pwd'],
commands: "ls\npwd\nrspec\nls",
image: 'ruby:2.2', image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'], services: ['postgres:9.1', 'mysql:5.5'],
stage: 'test', stage: 'test',
...@@ -151,8 +152,9 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -151,8 +152,9 @@ describe Gitlab::Ci::Config::Node::Global do
variables: { VAR: 'value' }, variables: { VAR: 'value' },
after_script: ['make clean'] }, after_script: ['make clean'] },
spinach: { name: :spinach, spinach: { name: :spinach,
script: %w[spinach],
before_script: [], before_script: [],
script: %w[spinach],
commands: 'spinach',
image: 'ruby:2.2', image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'], services: ['postgres:9.1', 'mysql:5.5'],
stage: 'test', stage: 'test',
......
...@@ -59,27 +59,6 @@ describe Gitlab::Ci::Config::Node::Job do ...@@ -59,27 +59,6 @@ describe Gitlab::Ci::Config::Node::Job do
end end
end end
describe '#value' do
before { entry.compose! }
context 'when entry is correct' do
let(:config) do
{ before_script: %w[ls pwd],
script: 'rspec',
after_script: %w[cleanup] }
end
it 'returns correct value' do
expect(entry.value)
.to eq(name: :rspec,
before_script: %w[ls pwd],
script: %w[rspec],
stage: 'test',
after_script: %w[cleanup])
end
end
end
describe '#relevant?' do describe '#relevant?' do
it 'is a relevant entry' do it 'is a relevant entry' do
expect(entry).to be_relevant expect(entry).to be_relevant
...@@ -122,4 +101,40 @@ describe Gitlab::Ci::Config::Node::Job do ...@@ -122,4 +101,40 @@ describe Gitlab::Ci::Config::Node::Job do
end end
end end
end end
context 'when composed' do
before { entry.compose! }
describe '#value' do
before { entry.compose! }
context 'when entry is correct' do
let(:config) do
{ before_script: %w[ls pwd],
script: 'rspec',
after_script: %w[cleanup] }
end
it 'returns correct value' do
expect(entry.value)
.to eq(name: :rspec,
before_script: %w[ls pwd],
script: %w[rspec],
commands: "ls\npwd\nrspec",
stage: 'test',
after_script: %w[cleanup])
end
end
end
describe '#commands' do
let(:config) do
{ before_script: %w[ls pwd], script: 'rspec' }
end
it 'returns a string of commands concatenated with new line character' do
expect(entry.commands).to eq "ls\npwd\nrspec"
end
end
end
end end
...@@ -61,9 +61,11 @@ describe Gitlab::Ci::Config::Node::Jobs do ...@@ -61,9 +61,11 @@ describe Gitlab::Ci::Config::Node::Jobs do
expect(entry.value).to eq( expect(entry.value).to eq(
rspec: { name: :rspec, rspec: { name: :rspec,
script: %w[rspec], script: %w[rspec],
commands: 'rspec',
stage: 'test' }, stage: 'test' },
spinach: { name: :spinach, spinach: { name: :spinach,
script: %w[spinach], script: %w[spinach],
commands: 'spinach',
stage: 'test' }) stage: 'test' })
end end
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