Follow feedback on the merge request
This commit is contained in:
parent
d7c32c5870
commit
63bf2457e4
|
@ -330,10 +330,10 @@ module Ci
|
|||
return @ci_yaml_file if defined?(@ci_yaml_file)
|
||||
|
||||
@ci_yaml_file = begin
|
||||
project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path)
|
||||
rescue
|
||||
project.repository.gitlab_ci_yml_for(sha)
|
||||
rescue Rugged::ReferenceError, GRPC::NotFound
|
||||
self.yaml_errors =
|
||||
"Failed to load CI/CD config file at #{ci_yaml_file_path}"
|
||||
"Failed to load CI/CD config file at #{project.ci_config_file_for_pipeline}"
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
@ -342,14 +342,6 @@ module Ci
|
|||
yaml_errors.present?
|
||||
end
|
||||
|
||||
def ci_yaml_file_path
|
||||
if project.ci_config_file.blank?
|
||||
'.gitlab-ci.yml'
|
||||
else
|
||||
project.ci_config_file
|
||||
end
|
||||
end
|
||||
|
||||
def environments
|
||||
builds.where.not(environment: nil).success.pluck(:environment).uniq
|
||||
end
|
||||
|
@ -392,7 +384,7 @@ module Ci
|
|||
def predefined_variables
|
||||
[
|
||||
{ key: 'CI_PIPELINE_ID', value: id.to_s, public: true },
|
||||
{ key: 'CI_CONFIG_PATH', value: ci_yaml_file_path, public: true }
|
||||
{ key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true }
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -526,6 +526,14 @@ class Project < ActiveRecord::Base
|
|||
import_data&.destroy
|
||||
end
|
||||
|
||||
def ci_config_file_for_pipeline
|
||||
if ci_config_file.blank?
|
||||
'.gitlab-ci.yml'
|
||||
else
|
||||
ci_config_file
|
||||
end
|
||||
end
|
||||
|
||||
def ci_config_file=(value)
|
||||
# Strip all leading slashes so that //foo -> foo
|
||||
super(value&.sub(%r{\A/+}, ''))
|
||||
|
|
|
@ -1078,8 +1078,8 @@ class Repository
|
|||
blob_data_at(sha, '.gitlab/route-map.yml')
|
||||
end
|
||||
|
||||
def gitlab_ci_yml_for(sha, path = '.gitlab-ci.yml')
|
||||
blob_data_at(sha, path)
|
||||
def gitlab_ci_yml_for(sha)
|
||||
blob_data_at(sha, project.ci_config_file_for_pipeline)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -748,30 +748,9 @@ describe Ci::Pipeline, models: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#ci_yaml_file_path' do
|
||||
let(:project) { create(:empty_project) }
|
||||
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
|
||||
|
||||
it 'returns the path from project' do
|
||||
allow(project).to receive(:ci_config_file) { 'custom/path' }
|
||||
|
||||
expect(pipeline.ci_yaml_file_path).to eq('custom/path')
|
||||
end
|
||||
|
||||
it 'returns default when custom path is nil' do
|
||||
allow(project).to receive(:ci_config_file) { nil }
|
||||
|
||||
expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml')
|
||||
end
|
||||
|
||||
it 'returns default when custom path is empty' do
|
||||
allow(project).to receive(:ci_config_file) { '' }
|
||||
|
||||
expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml')
|
||||
end
|
||||
|
||||
describe '#ci_yaml_file' do
|
||||
it 'reports error if the file is not found' do
|
||||
allow(project).to receive(:ci_config_file) { 'custom' }
|
||||
allow(pipeline.project).to receive(:ci_config_file) { 'custom' }
|
||||
|
||||
pipeline.ci_yaml_file
|
||||
|
||||
|
|
|
@ -1493,6 +1493,30 @@ describe Project, models: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#ci_config_file_for_pipeline' do
|
||||
let(:project) { create(:empty_project) }
|
||||
|
||||
subject { project.ci_config_file_for_pipeline }
|
||||
|
||||
it 'returns the path from project' do
|
||||
allow(project).to receive(:ci_config_file) { 'custom/path' }
|
||||
|
||||
is_expected.to eq('custom/path')
|
||||
end
|
||||
|
||||
it 'returns default when custom path is nil' do
|
||||
allow(project).to receive(:ci_config_file) { nil }
|
||||
|
||||
is_expected.to eq('.gitlab-ci.yml')
|
||||
end
|
||||
|
||||
it 'returns default when custom path is empty' do
|
||||
allow(project).to receive(:ci_config_file) { '' }
|
||||
|
||||
is_expected.to eq('.gitlab-ci.yml')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ci_config_file=' do
|
||||
let(:project) { create(:empty_project) }
|
||||
|
||||
|
|
|
@ -74,9 +74,7 @@ module CycleAnalyticsHelpers
|
|||
|
||||
def dummy_pipeline
|
||||
@dummy_pipeline ||=
|
||||
Ci::Pipeline.new(
|
||||
sha: project.repository.commit('master').sha,
|
||||
project: project)
|
||||
project.pipelines.build(sha: project.repository.commit('master').sha)
|
||||
end
|
||||
|
||||
def new_dummy_job(environment)
|
||||
|
|
Loading…
Reference in New Issue