summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ci/pipeline.rb31
-rw-r--r--app/models/project.rb3
-rw-r--r--app/models/project_auto_devops.rb2
-rw-r--r--app/services/ci/create_pipeline_service.rb7
-rw-r--r--config/initializers/0_inflections.rb2
-rw-r--r--db/migrate/20170828093725_create_project_auto_dev_ops.rb4
-rw-r--r--db/schema.rb7
-rw-r--r--lib/gitlab/import_export/relation_factory.rb2
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml3
-rw-r--r--spec/models/project_auto_devops_spec.rb4
-rw-r--r--spec/models/project_spec.rb1
11 files changed, 44 insertions, 22 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 5587b19fd69..c1327a9f690 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index b2d6598a30b..798f3dfe853 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/models/project_auto_devops.rb b/app/models/project_auto_devops.rb
index fe73c6f0a85..f4f54f05e33 100644
--- a/app/models/project_auto_devops.rb
+++ b/app/models/project_auto_devops.rb
@@ -1,3 +1,5 @@
class ProjectAutoDevops < ActiveRecord::Base
belongs_to :project
+
+ validates :domain, presence: true
end
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index de2cd7e87be..821542dd8d2 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -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
diff --git a/config/initializers/0_inflections.rb b/config/initializers/0_inflections.rb
index da19c765f50..1ad9ddca877 100644
--- a/config/initializers/0_inflections.rb
+++ b/config/initializers/0_inflections.rb
@@ -14,6 +14,6 @@ ActiveSupport::Inflector.inflections do |inflect|
award_emoji
project_statistics
system_note_metadata
- auto_devops
+ project_auto_devops
)
end
diff --git a/db/migrate/20170828093725_create_project_auto_dev_ops.rb b/db/migrate/20170828093725_create_project_auto_dev_ops.rb
index a96ad644a2e..17ee193ccc1 100644
--- a/db/migrate/20170828093725_create_project_auto_dev_ops.rb
+++ b/db/migrate/20170828093725_create_project_auto_dev_ops.rb
@@ -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)
diff --git a/db/schema.rb b/db/schema.rb
index fafbf521e02..f2eb6dacab6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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"
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index e6e7e3573b0..7448b806b72 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -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
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index 6e77c955b05..f2224bc3aa6 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -467,3 +467,6 @@ ProjectAutoDevops:
- id
- enabled
- domain
+- project_id
+- created_at
+- updated_at
diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb
index d534dacf079..08cb7c4c1b1 100644
--- a/spec/models/project_auto_devops_spec.rb
+++ b/spec/models/project_auto_devops_spec.rb
@@ -1,10 +1,12 @@
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) }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index be1ae295f75..d41d7150922 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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) }