diff --git a/app/assets/javascripts/pipelines/components/pipeline_url.vue b/app/assets/javascripts/pipelines/components/pipeline_url.vue index 2ca5ac2912f544a3600dba358513db1f5097b074..3cab411d3213785709178e6606749402a3d5bed8 100644 --- a/app/assets/javascripts/pipelines/components/pipeline_url.vue +++ b/app/assets/javascripts/pipelines/components/pipeline_url.vue @@ -57,6 +57,13 @@ export default { :title="pipeline.yaml_errors"> yaml invalid + + Auto DevOps + diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 53ff42c04f44cf9fa965224f07d9a310bb1a6f77..5587b19fd69ce40d52a2b68d8f595be5434a6811 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -50,6 +50,11 @@ module Ci external: 6 } + enum config_source: { + repository: nil, + auto_devops: 1 + } + state_machine :status, initial: :created do event :enqueue do transition created: :pending @@ -338,10 +343,14 @@ module Ci def ci_yaml_file return @ci_yaml_file if defined?(@ci_yaml_file) - @ci_yaml_file = (ci_yaml_from_repo || implied_ci_yaml_file).tap do |config| - unless config - self.yaml_errors = "Failed to load CI/CD config file for #{sha}" - end + @ci_yaml_file = ci_yaml_from_repo + @ci_yaml_file ||= implied_ci_yaml_file&.tap { self.auto_devops! } + + if @ci_yaml_file + @ci_yaml_file + else + self.yaml_errors = "Failed to load CI/CD config file for #{sha}" + nil end end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index c4f000b0ca3f4900395ea8ccba6b14355a338b09..767f33e11e189bd487fb65b4414ccb4142522350 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -16,6 +16,7 @@ class PipelineEntity < Grape::Entity expose :flags do expose :latest?, as: :latest expose :stuck?, as: :stuck + expose :auto_devops?, as: :auto_devops expose :has_yaml_errors?, as: :yaml_errors expose :can_retry?, as: :retryable expose :can_cancel?, as: :cancelable diff --git a/app/views/projects/pipelines/index.html.haml b/app/views/projects/pipelines/index.html.haml index c1729850cf4ec01f71404289b2228df12b9c64b9..93c3e016cba0aba179e88a03827e11e0d8087c93 100644 --- a/app/views/projects/pipelines/index.html.haml +++ b/app/views/projects/pipelines/index.html.haml @@ -13,7 +13,7 @@ "finished-path" => project_pipelines_path(@project, scope: :finished), "branches-path" => project_pipelines_path(@project, scope: :branches), "tags-path" => project_pipelines_path(@project, scope: :tags), - "has-ci" => @repository.gitlab_ci_yml, + "has-ci" => @repository.gitlab_ci_yml || @project.auto_devops_enabled?, "ci-lint-path" => ci_lint_path } } = page_specific_javascript_bundle_tag('common_vue') diff --git a/db/migrate/20170831092813_add_config_source_to_pipelines.rb b/db/migrate/20170831092813_add_config_source_to_pipelines.rb new file mode 100644 index 0000000000000000000000000000000000000000..ff51e968abd86787a63a0137dc086ff4e2b85213 --- /dev/null +++ b/db/migrate/20170831092813_add_config_source_to_pipelines.rb @@ -0,0 +1,7 @@ +class AddConfigSourceToPipelines < ActiveRecord::Migration + DOWNTIME = false + + def change + add_column(:ci_pipelines, :config_source, :integer, allow_null: true) + end +end diff --git a/db/schema.rb b/db/schema.rb index 1bc2a5eddc52c48575eedfc473e9fc25e7e49739..0f4b0c0c3b3a90b6d716206d4224fa550db68ac1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170828093725) do +ActiveRecord::Schema.define(version: 20170824162758) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -125,11 +125,10 @@ ActiveRecord::Schema.define(version: 20170828093725) do t.boolean "prometheus_metrics_enabled", default: false, null: false t.boolean "help_page_hide_commercial_content", default: false t.string "help_page_support_url" - t.boolean "password_authentication_enabled" t.integer "performance_bar_allowed_group_id" - t.boolean "hashed_storage_enabled", default: false, null: false + t.boolean "password_authentication_enabled" t.boolean "project_export_enabled", default: true, null: false - t.boolean "auto_devops_enabled", default: false, null: false + t.boolean "hashed_storage_enabled", default: false, null: false end create_table "audit_events", force: :cascade do |t| @@ -1117,16 +1116,6 @@ ActiveRecord::Schema.define(version: 20170828093725) do add_index "project_authorizations", ["project_id"], name: "index_project_authorizations_on_project_id", using: :btree 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.boolean "enabled", default: true - t.string "domain" - 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 - create_table "project_features", force: :cascade do |t| t.integer "project_id" t.integer "merge_requests_access_level" @@ -1210,7 +1199,6 @@ ActiveRecord::Schema.define(version: 20170828093725) 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" @@ -1218,8 +1206,9 @@ ActiveRecord::Schema.define(version: 20170828093725) do t.integer "auto_cancel_pending_pipelines", default: 1, null: false t.string "import_jid" t.integer "cached_markdown_version" - t.text "delete_error" t.datetime "last_repository_updated_at" + t.string "ci_config_path" + t.text "delete_error" t.integer "storage_version", limit: 2 end @@ -1733,7 +1722,6 @@ ActiveRecord::Schema.define(version: 20170828093725) do add_foreign_key "personal_access_tokens", "users" add_foreign_key "project_authorizations", "projects", on_delete: :cascade add_foreign_key "project_authorizations", "users", on_delete: :cascade - add_foreign_key "project_auto_devops", "projects", name: "fk_45436b12b2", on_delete: :cascade add_foreign_key "project_features", "projects", name: "fk_18513d9b92", on_delete: :cascade add_foreign_key "project_group_links", "projects", name: "fk_daa8cee94c", on_delete: :cascade add_foreign_key "project_import_data", "projects", name: "fk_ffb9ee3a10", on_delete: :cascade diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index a7e0da04f55a8510861ce74c772137c3e7bd9087..80cf872a5fd62346af13cf4fe47cb5d8a47f986f 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -794,14 +794,27 @@ describe Ci::Pipeline, :mailer do 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 + expect(pipeline.repository?).to be(true) end - it 'returns the implied configuration when its not found' do - allow_any_instance_of(ApplicationSetting) - .to receive(:auto_devops_enabled?) { true } - allow(pipeline.project).to receive(:ci_config_path) { 'custom' } + context 'when the implied configuration will be used' do + before do + allow_any_instance_of(ApplicationSetting) + .to receive(:auto_devops_enabled?) { true } + end - expect(pipeline.ci_yaml_file).to eq(implied_yml) + it 'returns the implied configuration when its not found' do + allow(pipeline.project).to receive(:ci_config_path) { 'custom' } + + expect(pipeline.ci_yaml_file).to eq(implied_yml) + end + + it 'sets the config source' do + allow(pipeline.project).to receive(:ci_config_path) { 'custom' } + + expect(pipeline.ci_yaml_file).to eq(implied_yml) + expect(pipeline.auto_devops?).to be(true) + end end end diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index 881f2b6bfd8bcb51c70ff906c50e27e27532d7be..f8df461bc814c3320bc9a3c323983f4ad796dd0a 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -36,7 +36,7 @@ describe PipelineEntity do it 'contains flags' do expect(subject).to include :flags expect(subject[:flags]) - .to include :latest, :stuck, + .to include :latest, :stuck, :auto_devops, :yaml_errors, :retryable, :cancelable end end