Commit 63bf2457 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Follow feedback on the merge request

parent d7c32c58
...@@ -330,10 +330,10 @@ module Ci ...@@ -330,10 +330,10 @@ module Ci
return @ci_yaml_file if defined?(@ci_yaml_file) return @ci_yaml_file if defined?(@ci_yaml_file)
@ci_yaml_file = begin @ci_yaml_file = begin
project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path) project.repository.gitlab_ci_yml_for(sha)
rescue rescue Rugged::ReferenceError, GRPC::NotFound
self.yaml_errors = 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 nil
end end
end end
...@@ -342,14 +342,6 @@ module Ci ...@@ -342,14 +342,6 @@ module Ci
yaml_errors.present? yaml_errors.present?
end end
def ci_yaml_file_path
if project.ci_config_file.blank?
'.gitlab-ci.yml'
else
project.ci_config_file
end
end
def environments def environments
builds.where.not(environment: nil).success.pluck(:environment).uniq builds.where.not(environment: nil).success.pluck(:environment).uniq
end end
...@@ -392,7 +384,7 @@ module Ci ...@@ -392,7 +384,7 @@ module Ci
def predefined_variables def predefined_variables
[ [
{ key: 'CI_PIPELINE_ID', value: id.to_s, public: true }, { 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 end
......
...@@ -526,6 +526,14 @@ class Project < ActiveRecord::Base ...@@ -526,6 +526,14 @@ class Project < ActiveRecord::Base
import_data&.destroy import_data&.destroy
end 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) def ci_config_file=(value)
# Strip all leading slashes so that //foo -> foo # Strip all leading slashes so that //foo -> foo
super(value&.sub(%r{\A/+}, '')) super(value&.sub(%r{\A/+}, ''))
......
...@@ -1078,8 +1078,8 @@ class Repository ...@@ -1078,8 +1078,8 @@ class Repository
blob_data_at(sha, '.gitlab/route-map.yml') blob_data_at(sha, '.gitlab/route-map.yml')
end end
def gitlab_ci_yml_for(sha, path = '.gitlab-ci.yml') def gitlab_ci_yml_for(sha)
blob_data_at(sha, path) blob_data_at(sha, project.ci_config_file_for_pipeline)
end end
private private
......
...@@ -748,30 +748,9 @@ describe Ci::Pipeline, models: true do ...@@ -748,30 +748,9 @@ describe Ci::Pipeline, models: true do
end end
end end
describe '#ci_yaml_file_path' do describe '#ci_yaml_file' 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
it 'reports error if the file is not found' 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 pipeline.ci_yaml_file
......
...@@ -1493,6 +1493,30 @@ describe Project, models: true do ...@@ -1493,6 +1493,30 @@ describe Project, models: true do
end end
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 describe '#ci_config_file=' do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
......
...@@ -74,9 +74,7 @@ module CycleAnalyticsHelpers ...@@ -74,9 +74,7 @@ module CycleAnalyticsHelpers
def dummy_pipeline def dummy_pipeline
@dummy_pipeline ||= @dummy_pipeline ||=
Ci::Pipeline.new( project.pipelines.build(sha: project.repository.commit('master').sha)
sha: project.repository.commit('master').sha,
project: project)
end end
def new_dummy_job(environment) def new_dummy_job(environment)
......
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