From 35b9213cd7e378a732991a11bc8b5fa9e711c52b Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 31 Aug 2017 13:47:29 +0200 Subject: [PATCH] Add config_source to ci_pipelines Given the user can soon have multiple config sources for CI, we now store what type at the time of the pipeline run we chose. This will give us insight into what triggered the new pipeline so we can display it to the enduser. --- .../pipelines/components/pipeline_url.vue | 7 ++++++ app/models/ci/pipeline.rb | 17 ++++++++++---- app/serializers/pipeline_entity.rb | 1 + app/views/projects/pipelines/index.html.haml | 2 +- ...31092813_add_config_source_to_pipelines.rb | 7 ++++++ db/schema.rb | 22 ++++-------------- spec/models/ci/pipeline_spec.rb | 23 +++++++++++++++---- spec/serializers/pipeline_entity_spec.rb | 2 +- 8 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20170831092813_add_config_source_to_pipelines.rb diff --git a/app/assets/javascripts/pipelines/components/pipeline_url.vue b/app/assets/javascripts/pipelines/components/pipeline_url.vue index 2ca5ac2912f..3cab411d321 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 53ff42c04f4..5587b19fd69 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 c4f000b0ca3..767f33e11e1 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 c1729850cf4..93c3e016cba 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 00000000000..ff51e968abd --- /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 1bc2a5eddc5..0f4b0c0c3b3 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 a7e0da04f55..80cf872a5fd 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 881f2b6bfd8..f8df461bc81 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 -- GitLab