From 2200c19189684cdf96ce6dfe63795dc4e4455e07 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 29 May 2014 00:18:29 +0400 Subject: [PATCH] #394: Forbid to publish builds not from valid branch --- app/models/build_list.rb | 19 ++++++++++++++++++- app/models/repository.rb | 7 ++++++- .../platforms/repositories/_form.html.haml | 5 +++++ config/locales/models/repository.en.yml | 1 + config/locales/models/repository.ru.yml | 1 + ...publish_builds_not_from_to_repositories.rb | 5 +++++ db/schema.rb | 13 +++++++------ 7 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20140528170054_add_forbid_to_publish_builds_not_from_to_repositories.rb diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 59096b1a1..37a386f3c 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -392,7 +392,14 @@ class BuildList < ActiveRecord::Base end def can_publish? - [SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && extra_build_lists_published? && save_to_repository.projects.exists?(id: project_id) + super && + valid_branch_for_publish? && + extra_build_lists_published? && + save_to_repository.projects.exists?(id: project_id) + end + + def can_publish_into_testing? + super && valid_branch_for_publish? end def extra_build_lists_published? @@ -597,6 +604,16 @@ class BuildList < ActiveRecord::Base protected + def valid_branch_for_publish? + return true if save_to_platform.personal? || + ( project_version == save_to_platform.name ) || + ( save_to_platform.main? && !save_to_repository.forbid_to_publish_builds_not_from? ) + + p.repo.git.native(:branch, {}, '--contains', commit_hash). + gsub(/\*/, '').split(/\n/).map(&:strip).include?(save_to_platform.name) + end + + def create_container AbfWorker::BuildListsPublishTaskManager.create_container_for self end diff --git a/app/models/repository.rb b/app/models/repository.rb index e42ce367c..a3a3c923a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -29,7 +29,12 @@ class Repository < ActiveRecord::Base before_destroy :detele_directory - attr_accessible :name, :description, :publish_without_qa, :synchronizing_publications + attr_accessible :name, + :description, + :publish_without_qa, + :synchronizing_publications, + :forbid_to_publish_builds_not_from + attr_readonly :name, :platform_id attr_accessor :projects_list diff --git a/app/views/platforms/repositories/_form.html.haml b/app/views/platforms/repositories/_form.html.haml index 695cf2e1c..ffda366d0 100644 --- a/app/views/platforms/repositories/_form.html.haml +++ b/app/views/platforms/repositories/_form.html.haml @@ -11,6 +11,11 @@ .leftlist= f.label :synchronizing_publications .rightlist= f.check_box :synchronizing_publications +- if @platform.main? + .both + .leftlist= f.label :forbid_to_publish_builds_not_from, t('activerecord.attributes.repository.forbid_to_publish_builds_not_from', name: @platform.name) + .rightlist= f.check_box :forbid_to_publish_builds_not_from + .both .hr diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 98a444abd..e60ccace7 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -71,3 +71,4 @@ en: updated_at: Updated owner: Owner synchronizing_publications: Publish only on success all build_lists for each arch (checking by commit hash) + forbid_to_publish_builds_not_from: "Forbid to publish builds not from '%{name}' branch" diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 38e61a860..38749797d 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -71,3 +71,4 @@ ru: updated_at: Обновлен owner: Владелец synchronizing_publications: Публиковать сборочные листы только при успешной сборке под каждую архитектуру (проверка по хэшу коммита) + forbid_to_publish_builds_not_from: "Запрет на публикацию сборок не из '%{name}' ветки" diff --git a/db/migrate/20140528170054_add_forbid_to_publish_builds_not_from_to_repositories.rb b/db/migrate/20140528170054_add_forbid_to_publish_builds_not_from_to_repositories.rb new file mode 100644 index 000000000..eca66d38b --- /dev/null +++ b/db/migrate/20140528170054_add_forbid_to_publish_builds_not_from_to_repositories.rb @@ -0,0 +1,5 @@ +class AddForbidToPublishBuildsNotFromToRepositories < ActiveRecord::Migration + def change + add_column :repositories, :forbid_to_publish_builds_not_from, :boolean, null: false, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index edd024789..62be1cdb9 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: 20140523192643) do +ActiveRecord::Schema.define(version: 20140528170054) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -522,13 +522,14 @@ ActiveRecord::Schema.define(version: 20140523192643) do end create_table "repositories", force: true do |t| - t.string "description", null: false - t.integer "platform_id", null: false + t.string "description", null: false + t.integer "platform_id", null: false t.datetime "created_at" t.datetime "updated_at" - t.string "name", null: false - t.boolean "publish_without_qa", default: true - t.boolean "synchronizing_publications", default: false, null: false + t.string "name", null: false + t.boolean "publish_without_qa", default: true + t.boolean "synchronizing_publications", default: false, null: false + t.boolean "forbid_to_publish_builds_not_from", default: true, null: false t.index ["platform_id"], :name => "index_repositories_on_platform_id" end