Skip to content
代码片段 群组 项目
未验证 提交 41ba465a 编辑于 作者: Peter Leitzen's avatar Peter Leitzen
浏览文件

Danger: Fix CiJobsDependencyValidation when YAML cannot be retrieved

In case of an API error, merged YAML should be an empty Hash and not
empty Array. This API error can occur on forks because we cannot lint CI
config on forks.
上级 b74e80de
No related branches found
No related tags found
无相关合并请求
...@@ -112,12 +112,47 @@ ...@@ -112,12 +112,47 @@
it_behaves_like 'empty message' it_behaves_like 'empty message'
end end
context 'when retrieving target branch jobs fails' do
before do
allow(ci_jobs_dependency_validation).to receive_message_chain(:gitlab, :api, :get)
.with("/projects/1/ci/lint", query: query).and_raise('404 Not Found')
end
it 'prints the failure but does not break' do
expect { expect(ci_jobs_dependency_validation.output_message).to eq('') }.tap do |expectation|
expectation
.to output(<<~MSG).to_stdout
Initializing 1 jobs from master ci config...
404 Not Found
Initializing 0 jobs from feature_branch ci config...
MSG
end
end
end
context 'when source branch jobs is empty' do context 'when source branch jobs is empty' do
let(:master_merged_yaml) { YAML.dump({}) } let(:master_merged_yaml) { YAML.dump({}) }
it_behaves_like 'empty message' it_behaves_like 'empty message'
end end
context 'when retrieving source branch jobs fails' do
before do
allow(ci_jobs_dependency_validation).to receive_message_chain(:gitlab, :api, :get)
.with("/projects/1/ci/lint", query: {}).and_raise('404 Not Found')
end
it 'prints the failure but does not break' do
expect { expect(ci_jobs_dependency_validation.output_message).to eq('') }.tap do |expectation|
expectation
.to output(<<~MSG).to_stdout
404 Not Found
Initializing 0 jobs from master ci config...
MSG
end
end
end
context 'when jobs do not have dependencies' do context 'when jobs do not have dependencies' do
it_behaves_like 'empty message', :default_stdout_output, 1, 4 it_behaves_like 'empty message', :default_stdout_output, 1, 4
end end
...@@ -331,7 +366,7 @@ ...@@ -331,7 +366,7 @@
end end
it 'returns jobs yaml' do it 'returns jobs yaml' do
expect(ci_jobs_dependency_validation.send(:fetch_jobs_yaml, '1', 'master')).to eq([]) expect(ci_jobs_dependency_validation.send(:fetch_jobs_yaml, '1', 'master')).to eq({})
end end
end end
...@@ -343,7 +378,7 @@ ...@@ -343,7 +378,7 @@
end end
it 'returns jobs yaml' do it 'returns jobs yaml' do
expect(ci_jobs_dependency_validation.send(:fetch_jobs_yaml, '1', 'master')).to eq([]) expect(ci_jobs_dependency_validation.send(:fetch_jobs_yaml, '1', 'master')).to eq({})
end end
end end
...@@ -357,7 +392,7 @@ ...@@ -357,7 +392,7 @@
end end
it 'returns jobs yaml' do it 'returns jobs yaml' do
expect(ci_jobs_dependency_validation.send(:fetch_jobs_yaml, '1', 'master')).to eq([]) expect(ci_jobs_dependency_validation.send(:fetch_jobs_yaml, '1', 'master')).to eq({})
end end
end end
end end
......
...@@ -71,7 +71,7 @@ def fetch_jobs_yaml(project_id, ref) ...@@ -71,7 +71,7 @@ def fetch_jobs_yaml(project_id, ref)
YAML.load(api_response['merged_yaml'], aliases: true) YAML.load(api_response['merged_yaml'], aliases: true)
rescue StandardError => e rescue StandardError => e
puts e.message puts e.message
[] {}
end end
def build_jobs_from_yaml(jobs_yaml, ref) def build_jobs_from_yaml(jobs_yaml, ref)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册