summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-07-04 03:08:30 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-07-04 03:08:30 +0800
commit63bf2457e40ffd465d9a5aeee9b26b1c82432f9d (patch)
treec9733e297dbf0500ffb1de8b511eb52fa9c66c45
parentd7c32c5870ff7122122d0fc75ed8a04a0818251e (diff)
downloadgitlab-ce-63bf2457e40ffd465d9a5aeee9b26b1c82432f9d.tar.gz
Follow feedback on the merge request
-rw-r--r--app/models/ci/pipeline.rb16
-rw-r--r--app/models/project.rb8
-rw-r--r--app/models/repository.rb4
-rw-r--r--spec/models/ci/pipeline_spec.rb25
-rw-r--r--spec/models/project_spec.rb24
-rw-r--r--spec/support/cycle_analytics_helpers.rb4
6 files changed, 41 insertions, 40 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 6905ab9ea23..a38c63e9e91 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 1513402132b..381e9067ad1 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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/+}, ''))
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 10b429c707e..0b06807e292 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 8d4d87def5e..e36e9082036 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -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
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 349f9c3d7eb..f06f7d6b54b 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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) }
diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/cycle_analytics_helpers.rb
index c0a5491a430..916544babcf 100644
--- a/spec/support/cycle_analytics_helpers.rb
+++ b/spec/support/cycle_analytics_helpers.rb
@@ -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)