Commit 003bfac2 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Incorporate another round of feedback

parent 63e308f6
...@@ -351,9 +351,9 @@ module Ci ...@@ -351,9 +351,9 @@ module Ci
@ci_yaml_file = @ci_yaml_file =
case config_source case config_source
when :repository_source, :unknown_source when "repository_source", "unknown_source"
ci_yaml_from_repo ci_yaml_from_repo
when :auto_devops_source when "auto_devops_source"
implied_ci_yaml_file implied_ci_yaml_file
end end
......
...@@ -469,7 +469,7 @@ class Project < ActiveRecord::Base ...@@ -469,7 +469,7 @@ class Project < ActiveRecord::Base
end end
def auto_devops_enabled? def auto_devops_enabled?
if auto_devops && !auto_devops.enabled.nil? if auto_devops && auto_devops.enabled.present?
auto_devops.enabled? auto_devops.enabled?
else else
current_application_settings.auto_devops_enabled? current_application_settings.auto_devops_enabled?
......
class ProjectAutoDevops < ActiveRecord::Base class ProjectAutoDevops < ActiveRecord::Base
belongs_to :project belongs_to :project
validates :domain, presence: true validates :domain, presence: true, if: :enabled?
end end
...@@ -9,7 +9,7 @@ class CreateProjectAutoDevOps < ActiveRecord::Migration ...@@ -9,7 +9,7 @@ class CreateProjectAutoDevOps < ActiveRecord::Migration
create_table :project_auto_devops do |t| create_table :project_auto_devops do |t|
t.belongs_to :project, null: false, index: { unique: true } t.belongs_to :project, null: false, index: { unique: true }
t.boolean :enabled, default: nil, null: true t.boolean :enabled, default: nil, null: true
t.string :domain, null: false t.string :domain
end end
add_timestamps_with_timezone(:project_auto_devops, null: false) add_timestamps_with_timezone(:project_auto_devops, null: false)
......
...@@ -1125,7 +1125,7 @@ ActiveRecord::Schema.define(version: 20170831092813) do ...@@ -1125,7 +1125,7 @@ ActiveRecord::Schema.define(version: 20170831092813) do
create_table "project_auto_devops", force: :cascade do |t| create_table "project_auto_devops", force: :cascade do |t|
t.integer "project_id", null: false t.integer "project_id", null: false
t.boolean "enabled" t.boolean "enabled"
t.string "domain", null: false t.string "domain"
t.datetime_with_timezone "created_at", null: false t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false t.datetime_with_timezone "updated_at", null: false
end end
......
...@@ -783,60 +783,82 @@ describe Ci::Pipeline, :mailer do ...@@ -783,60 +783,82 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '#ci_yaml_file' do describe '#detect_ci_yaml_file' do
let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content } context 'when the repo has a config file' do
it 'returns that configuration' do
context 'when AutoDevops is enabled' do
it 'returns the configuration if found' do
allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for) allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
.and_return('config') .and_return('config')
expect(pipeline.ci_yaml_file).to be_a(String) expect(pipeline.detect_ci_yaml_file).to be_a(String)
expect(pipeline.ci_yaml_file).not_to eq(implied_yml) expect(pipeline.repository_source?).to be(true)
expect(pipeline.yaml_errors).to be_nil
expect(pipeline.repository?).to be(true)
end end
end
context 'when the repo does not have a config file' do
let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
context 'when the implied configuration will be used' do context 'auto devops enabled' do
before do before do
allow_any_instance_of(ApplicationSetting) allow_any_instance_of(ApplicationSetting)
.to receive(:auto_devops_enabled?) { true } .to receive(:auto_devops_enabled?) { true }
end end
it 'returns the implied configuration when its not found' do it 'returns the implied ci file' do
allow(pipeline.project).to receive(:ci_config_path) { 'custom' } allow(pipeline.project).to receive(:ci_config_path) { 'custom' }
expect(pipeline.ci_yaml_file).to eq(implied_yml) expect(pipeline.detect_ci_yaml_file).to eq(implied_yml)
expect(pipeline.auto_devops_source?).to be(true)
end end
end
end
end
it 'sets the config source' do describe '#ci_yaml_file' do
allow(pipeline.project).to receive(:ci_config_path) { 'custom' } let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
expect(pipeline.ci_yaml_file).to eq(implied_yml) before { pipeline.detect_ci_yaml_file }
expect(pipeline.auto_devops?).to be(true)
end context 'the source is unknown' do
before { pipeline.unknown_source! }
it 'returns the configuration if found' do
allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
.and_return('config')
expect(pipeline.ci_yaml_file).to be_a(String)
expect(pipeline.ci_yaml_file).not_to eq(implied_yml)
expect(pipeline.yaml_errors).to be_nil
end
it 'sets yaml errors if not found' do
expect(pipeline.ci_yaml_file).to be_nil
expect(pipeline.yaml_errors)
.to start_with('Failed to load CI/CD config file')
end end
end end
context 'when AudoDevOps is disabled' do context 'the source is the repository' do
context 'when an invalid path is given' do before { pipeline.repository_source! }
it 'sets the yaml errors' do
allow(pipeline.project).to receive(:ci_config_path) { 'custom' }
expect(pipeline.ci_yaml_file).to be_nil it 'returns the configuration if found' do
expect(pipeline.yaml_errors) allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
.to start_with('Failed to load CI/CD config file') .and_return('config')
end
expect(pipeline.ci_yaml_file).to be_a(String)
expect(pipeline.ci_yaml_file).not_to eq(implied_yml)
expect(pipeline.yaml_errors).to be_nil
end end
end
context 'when the config file can be found' do context 'when the source is auto_devops_source' do
it 'has no yaml_errors' do before { pipeline.auto_devops_source! }
allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
.and_return('config')
expect(pipeline.ci_yaml_file).to eq('config') it 'finds the implied config' do
expect(pipeline.yaml_errors).to be_nil allow_any_instance_of(ApplicationSetting)
end .to receive(:auto_devops_enabled?) { true }
expect(pipeline.ci_yaml_file).to eq(implied_yml)
expect(pipeline.yaml_errors).to be_nil
end end
end end
end end
......
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