summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-07-05 20:04:53 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-07-05 20:04:53 +0800
commit9f7e5e45df9b7d99b97e40d1c08250925a408875 (patch)
tree2071af9ef6a07d25f3307634a2d3ae190e5eee81
parent60b8156a25ae308200a3cacf463eba6ab472afcf (diff)
downloadgitlab-ce-9f7e5e45df9b7d99b97e40d1c08250925a408875.tar.gz
Add back Pipeline#ci_yaml_file_path due to all the troubles
-rw-r--r--app/models/ci/pipeline.rb14
-rw-r--r--app/models/project.rb8
-rw-r--r--app/models/repository.rb4
-rw-r--r--app/services/ci/create_pipeline_service.rb2
-rw-r--r--spec/models/ci/build_spec.rb2
-rw-r--r--spec/models/ci/pipeline_spec.rb22
-rw-r--r--spec/models/project_spec.rb24
7 files changed, 37 insertions, 39 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index dd6fbfbd01b..759fdb4bf4c 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -326,14 +326,22 @@ module Ci
end
end
+ def ci_yaml_file_path
+ if project.ci_config_file.blank?
+ '.gitlab-ci.yml'
+ else
+ project.ci_config_file
+ end
+ end
+
def ci_yaml_file
return @ci_yaml_file if defined?(@ci_yaml_file)
@ci_yaml_file = begin
- project.repository.gitlab_ci_yml_for(sha)
+ project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path)
rescue Rugged::ReferenceError, GRPC::NotFound, GRPC::Internal
self.yaml_errors =
- "Failed to load CI/CD config file at #{project.ci_config_file_for_pipeline}"
+ "Failed to load CI/CD config file at #{ci_yaml_file_path}"
nil
end
end
@@ -384,7 +392,7 @@ module Ci
def predefined_variables
[
{ key: 'CI_PIPELINE_ID', value: id.to_s, public: true },
- { key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true }
+ { key: 'CI_CONFIG_PATH', value: ci_yaml_file_path, public: true }
]
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 5298348b74d..edc95980729 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -526,14 +526,6 @@ 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/+}, '')&.delete("\0"))
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 0b06807e292..10b429c707e 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)
- blob_data_at(sha, project.ci_config_file_for_pipeline)
+ def gitlab_ci_yml_for(sha, path = '.gitlab-ci.yml')
+ blob_data_at(sha, path)
end
private
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index b95c26560ae..4f35255fb53 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -33,7 +33,7 @@ module Ci
unless pipeline.config_processor
unless pipeline.ci_yaml_file
- return error("Missing #{project.ci_config_file_for_pipeline} file")
+ return error("Missing #{pipeline.ci_yaml_file_path} file")
end
return error(pipeline.yaml_errors, save: save_on_errors)
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 1553d6d3a9a..e5fd549f0d7 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1179,7 +1179,7 @@ describe Ci::Build, :models do
{ key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true },
{ key: 'CI_PROJECT_URL', value: project.web_url, public: true },
{ key: 'CI_PIPELINE_ID', value: pipeline.id.to_s, public: true },
- { key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true },
+ { key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, public: true },
{ key: 'CI_REGISTRY_USER', value: 'gitlab-ci-token', public: true },
{ key: 'CI_REGISTRY_PASSWORD', value: build.token, public: false },
{ key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false }
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index e36e9082036..a24b1e6c818 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -748,6 +748,28 @@ describe Ci::Pipeline, models: true do
end
end
+ describe '#ci_yaml_file_path' do
+ subject { pipeline.ci_yaml_file_path }
+
+ it 'returns the path from project' do
+ allow(pipeline.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(pipeline.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(pipeline.project).to receive(:ci_config_file) { '' }
+
+ is_expected.to eq('.gitlab-ci.yml')
+ end
+ end
+
describe '#ci_yaml_file' do
it 'reports error if the file is not found' do
allow(pipeline.project).to receive(:ci_config_file) { 'custom' }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 4ef768123bd..a682fa82bf0 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1493,30 +1493,6 @@ 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) }