Commit e1727441 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch '30101-fix-includes' into 'master'

Fix config variables when having includes

See merge request gitlab-org/gitlab!47189
parents 4337dce3 7b6734a0
...@@ -214,7 +214,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -214,7 +214,7 @@ class Projects::PipelinesController < Projects::ApplicationController
def config_variables def config_variables
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: Ci::ListConfigVariablesService.new(@project).execute(params[:sha]) render json: Ci::ListConfigVariablesService.new(@project, current_user).execute(params[:sha])
end end
end end
end end
......
...@@ -6,7 +6,10 @@ module Ci ...@@ -6,7 +6,10 @@ module Ci
config = project.ci_config_for(sha) config = project.ci_config_for(sha)
return {} unless config return {} unless config
result = Gitlab::Ci::YamlProcessor.new(config).execute result = Gitlab::Ci::YamlProcessor.new(config, project: project,
user: current_user,
sha: sha).execute
result.valid? ? result.variables_with_data : {} result.valid? ? result.variables_with_data : {}
end end
end end
......
---
title: Fix config variables when having includes
merge_request: 47189
author:
type: fixed
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Ci::ListConfigVariablesService do RSpec.describe Ci::ListConfigVariablesService do
let_it_be(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:service) { described_class.new(project) } let(:user) { project.creator }
let(:service) { described_class.new(project, user) }
let(:result) { YAML.dump(ci_config) } let(:result) { YAML.dump(ci_config) }
subject { service.execute(sha) } subject { service.execute(sha) }
...@@ -38,6 +39,40 @@ RSpec.describe Ci::ListConfigVariablesService do ...@@ -38,6 +39,40 @@ RSpec.describe Ci::ListConfigVariablesService do
end end
end end
context 'when config has includes' do
let(:sha) { 'master' }
let(:ci_config) do
{
include: [{ local: 'other_file.yml' }],
variables: {
KEY1: { value: 'val 1', description: 'description 1' }
},
test: {
stage: 'test',
script: 'echo'
}
}
end
before do
allow_next_instance_of(Repository) do |repository|
allow(repository).to receive(:blob_data_at).with(sha, 'other_file.yml') do
<<~HEREDOC
variables:
KEY2:
value: 'val 2'
description: 'description 2'
HEREDOC
end
end
end
it 'returns variable list' do
expect(subject['KEY1']).to eq({ value: 'val 1', description: 'description 1' })
expect(subject['KEY2']).to eq({ value: 'val 2', description: 'description 2' })
end
end
context 'when sending an invalid sha' do context 'when sending an invalid sha' do
let(:sha) { 'invalid-sha' } let(:sha) { 'invalid-sha' }
let(:ci_config) { nil } let(:ci_config) { nil }
......
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