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

Incorporate review

parent a346dbf0
......@@ -51,8 +51,9 @@ module Ci
}
enum config_source: {
repository: nil,
auto_devops: 1
unknown_source: nil,
repository_source: 1,
auto_devops_source: 2
}
state_machine :status, initial: :created do
......@@ -317,6 +318,11 @@ module Ci
builds.latest.failed_but_allowed.any?
end
def detect_ci_yaml_file
ci_yaml_from_repo&.tap { self.repository_source! } ||
implied_ci_yaml_file&.tap { self.auto_devops_source! }
end
def config_processor
return unless ci_yaml_file
return @config_processor if defined?(@config_processor)
......@@ -343,8 +349,13 @@ module Ci
def ci_yaml_file
return @ci_yaml_file if defined?(@ci_yaml_file)
@ci_yaml_file = ci_yaml_from_repo
@ci_yaml_file ||= implied_ci_yaml_file&.tap { self.auto_devops! }
@ci_yaml_file =
case config_source
when :repository_source, :unknown_source
ci_yaml_from_repo
when :auto_devops_source
implied_ci_yaml_file
end
if @ci_yaml_file
@ci_yaml_file
......@@ -437,18 +448,18 @@ module Ci
private
def implied_ci_yaml_file
if project.auto_devops_enabled?
Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content
end
end
def ci_yaml_from_repo
project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path)
rescue GRPC::NotFound, Rugged::ReferenceError, GRPC::Internal
nil
end
def implied_ci_yaml_file
if project.auto_devops_enabled?
Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content
end
end
def pipeline_data
Gitlab::DataBuilder::Pipeline.build(self)
end
......
......@@ -1395,7 +1395,8 @@ class Project < ActiveRecord::Base
{ key: 'CI_PROJECT_PATH', value: full_path, public: true },
{ key: 'CI_PROJECT_PATH_SLUG', value: full_path_slug, public: true },
{ key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path, public: true },
{ key: 'CI_PROJECT_URL', value: web_url, public: true }
{ key: 'CI_PROJECT_URL', value: web_url, public: true },
{ key: 'AUTO_DEVOPS_DOMAIN', value: auto_devops.domain, public: true }
]
end
......
class ProjectAutoDevops < ActiveRecord::Base
belongs_to :project
validates :domain, presence: true
end
......@@ -67,10 +67,11 @@ module Ci
return error('Commit not found')
end
unless pipeline.detect_ci_yaml_file
return error("Missing #{pipeline.ci_yaml_file_path} file")
end
unless pipeline.config_processor
unless pipeline.ci_yaml_file
return error("Missing #{pipeline.ci_yaml_file_path} file")
end
return error(pipeline.yaml_errors, save: save_on_errors)
end
......
......@@ -14,6 +14,6 @@ ActiveSupport::Inflector.inflections do |inflect|
award_emoji
project_statistics
system_note_metadata
auto_devops
project_auto_devops
)
end
......@@ -7,9 +7,9 @@ class CreateProjectAutoDevOps < ActiveRecord::Migration
def up
create_table :project_auto_devops do |t|
t.belongs_to :project, index: true
t.belongs_to :project, null: false, index: { unique: true }
t.boolean :enabled, default: nil, null: true
t.string :domain
t.string :domain, null: false
end
add_timestamps_with_timezone(:project_auto_devops, null: false)
......
......@@ -1123,14 +1123,14 @@ ActiveRecord::Schema.define(version: 20170831092813) do
add_index "project_authorizations", ["user_id", "project_id", "access_level"], name: "index_project_authorizations_on_user_id_project_id_access_level", unique: true, using: :btree
create_table "project_auto_devops", force: :cascade do |t|
t.integer "project_id"
t.integer "project_id", null: false
t.boolean "enabled"
t.string "domain"
t.string "domain", null: false
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
end
add_index "project_auto_devops", ["project_id"], name: "index_project_auto_devops_on_project_id", using: :btree
add_index "project_auto_devops", ["project_id"], name: "index_project_auto_devops_on_project_id", unique: true, using: :btree
create_table "project_features", force: :cascade do |t|
t.integer "project_id"
......@@ -1215,6 +1215,7 @@ ActiveRecord::Schema.define(version: 20170831092813) do
t.string "repository_storage", default: "default", null: false
t.boolean "request_access_enabled", default: false, null: false
t.boolean "has_external_wiki"
t.string "ci_config_path"
t.boolean "lfs_enabled"
t.text "description_html"
t.boolean "only_allow_merge_if_all_discussions_are_resolved"
......
......@@ -14,7 +14,7 @@ module Gitlab
create_access_levels: 'ProtectedTag::CreateAccessLevel',
labels: :project_labels,
priorities: :label_priorities,
auto_devops: 'ProjectAutoDevops',
auto_devops: :project_auto_devops,
label: :project_label }.freeze
USER_REFERENCES = %w[author_id assignee_id updated_by_id user_id created_by_id last_edited_by_id merge_user_id resolved_by_id].freeze
......
......@@ -467,3 +467,6 @@ ProjectAutoDevops:
- id
- enabled
- domain
- project_id
- created_at
- updated_at
require 'spec_helper'
describe ProjectAutoDevops, type: :model do
describe ProjectAutoDevops do
subject { build_stubbed(:project_auto_devops) }
it { is_expected.to belong_to(:project) }
it { is_expected.to validate_presence_of(:domain) }
it { is_expected.to respond_to(:created_at) }
it { is_expected.to respond_to(:updated_at) }
......
......@@ -53,6 +53,7 @@ describe Project do
it { is_expected.to have_one(:import_data).class_name('ProjectImportData') }
it { is_expected.to have_one(:last_event).class_name('Event') }
it { is_expected.to have_one(:forked_from_project).through(:forked_project_link) }
it { is_expected.to have_one(:auto_devops).class_name('ProjectAutoDevops') }
it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:pipelines) }
it { is_expected.to have_many(:builds) }
......
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