From 94f1edc3e3430dcd027df1311a133561f2837601 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Sat, 31 May 2014 00:08:45 +0400 Subject: [PATCH] #394: add ability to set forbid_to_publish_builds_not_from --- app/models/build_list.rb | 7 ++++--- app/models/repository.rb | 1 + app/views/platforms/repositories/_form.html.haml | 4 ++-- config/locales/models/repository.en.yml | 2 +- config/locales/models/repository.ru.yml | 3 ++- ...to_publish_builds_not_from_in_repositories.rb | 16 ++++++++++++++++ db/schema.rb | 4 ++-- 7 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20140530193652_change_type_of_forbid_to_publish_builds_not_from_in_repositories.rb diff --git a/app/models/build_list.rb b/app/models/build_list.rb index fca15c528..8a5d8be3f 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -606,11 +606,12 @@ class BuildList < ActiveRecord::Base 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? ) + save_to_repository.forbid_to_publish_builds_not_from.blank? || + ( project_version == save_to_repository.forbid_to_publish_builds_not_from ) project.repo.git.native(:branch, {}, '--contains', commit_hash). - gsub(/\*/, '').split(/\n/).map(&:strip).include?(save_to_platform.name) + gsub(/\*/, '').split(/\n/).map(&:strip). + include?(save_to_repository.forbid_to_publish_builds_not_from) end diff --git a/app/models/repository.rb b/app/models/repository.rb index a3a3c923a..f02cc7551 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -23,6 +23,7 @@ class Repository < ActiveRecord::Base validates :description, presence: true validates :name, uniqueness: { scope: :platform_id, case_sensitive: false }, presence: true, format: { with: /\A[a-z0-9_\-]+\z/ } + validates :forbid_to_publish_builds_not_from, length: { maximum: 255 } scope :recent, -> { order(:name) } scope :main, -> { where(name: %w(main base)) } diff --git a/app/views/platforms/repositories/_form.html.haml b/app/views/platforms/repositories/_form.html.haml index ffda366d0..e44b03b5a 100644 --- a/app/views/platforms/repositories/_form.html.haml +++ b/app/views/platforms/repositories/_form.html.haml @@ -13,8 +13,8 @@ - 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 + .leftlist= f.label :forbid_to_publish_builds_not_from + .rightlist= f.text_field :forbid_to_publish_builds_not_from .both diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index e60ccace7..0189ea93b 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -71,4 +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" + forbid_to_publish_builds_not_from: "Forbid to publish builds not from branch" diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 38749797d..591ff50ed 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -71,4 +71,5 @@ ru: updated_at: Обновлен owner: Владелец synchronizing_publications: Публиковать сборочные листы только при успешной сборке под каждую архитектуру (проверка по хэшу коммита) - forbid_to_publish_builds_not_from: "Запрет на публикацию сборок не из '%{name}' ветки" + forbid_to_publish_builds_not_from: "Запрет на публикацию сборок не из ветки" + diff --git a/db/migrate/20140530193652_change_type_of_forbid_to_publish_builds_not_from_in_repositories.rb b/db/migrate/20140530193652_change_type_of_forbid_to_publish_builds_not_from_in_repositories.rb new file mode 100644 index 000000000..8e8b1d8fa --- /dev/null +++ b/db/migrate/20140530193652_change_type_of_forbid_to_publish_builds_not_from_in_repositories.rb @@ -0,0 +1,16 @@ +class ChangeTypeOfForbidToPublishBuildsNotFromInRepositories < ActiveRecord::Migration + def up + remove_column :repositories, :forbid_to_publish_builds_not_from + add_column :repositories, :forbid_to_publish_builds_not_from, :string + execute <<-SQL + UPDATE repositories SET forbid_to_publish_builds_not_from = platforms.name + FROM platforms + WHERE repositories.platform_id = platforms.id + SQL + end + + def down + remove_column :repositories, :forbid_to_publish_builds_not_from + 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 62be1cdb9..a0d15fbad 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: 20140528170054) do +ActiveRecord::Schema.define(version: 20140530193652) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -529,7 +529,7 @@ ActiveRecord::Schema.define(version: 20140528170054) do 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.string "forbid_to_publish_builds_not_from" t.index ["platform_id"], :name => "index_repositories_on_platform_id" end