From 7efe8894ff12f9a6d1ef277fc2c33eadc92c5ace Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 18 Feb 2015 01:33:58 +0300 Subject: [PATCH] Added ability to use specific branch for each platform --- .../build_lists/new_build_list_controller.js.coffee | 4 ++-- app/controllers/platforms/platforms_controller.rb | 2 +- app/helpers/build_lists_helper.rb | 2 +- app/models/platform.rb | 9 +++++++-- app/views/platforms/platforms/_form.html.slim | 2 ++ config/locales/models/platform.en.yml | 11 ++++++++--- config/locales/models/platform.ru.yml | 12 +++++++++--- ...20150217215529_add_default_branch_to_platforms.rb | 11 +++++++++++ db/schema.rb | 3 ++- spec/models/platform_spec.rb | 1 + 10 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20150217215529_add_default_branch_to_platforms.rb diff --git a/app/assets/javascripts/angularjs/build_lists/new_build_list_controller.js.coffee b/app/assets/javascripts/angularjs/build_lists/new_build_list_controller.js.coffee index 28d10f5c5..bf2c88515 100644 --- a/app/assets/javascripts/angularjs/build_lists/new_build_list_controller.js.coffee +++ b/app/assets/javascripts/angularjs/build_lists/new_build_list_controller.js.coffee @@ -12,7 +12,7 @@ NewBuildListController = (dataservice, $http) -> result = _.select(vm.save_to_repositories, (e) -> e.id is vm.save_to_repository_id or !vm.save_to_repository_id and - e.platform_name is vm.project_version_name + e.default_branch is vm.project_version_name ) return vm.save_to_repositories[0] if result.length is 0 result[0] @@ -78,7 +78,7 @@ NewBuildListController = (dataservice, $http) -> vm.build_for_platform_id = vm.save_to_repository.platform_id vm.is_build_for_main_platform = isBuildForMainPlatform() - vm.project_version_name = vm.save_to_repository.platform_name + vm.project_version_name = vm.save_to_repository.default_branch vm.project_version = setProjectVersion() if vm.is_build_for_main_platform changeStatusRepositories() diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 50956cce9..9ff1a2060 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -51,7 +51,7 @@ class Platforms::PlatformsController < Platforms::BaseController @admin_uname = params[:admin_uname] platform_params = params[:platform] || {} - platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released, :automatic_metadata_regeneration) + platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released, :automatic_metadata_regeneration, :default_branch) platform_params[:owner] = User.find(@admin_id) if @admin_id.present? diff --git a/app/helpers/build_lists_helper.rb b/app/helpers/build_lists_helper.rb index a6157decf..9641b06ae 100644 --- a/app/helpers/build_lists_helper.rb +++ b/app/helpers/build_lists_helper.rb @@ -222,7 +222,7 @@ module BuildListsHelper publish_without_qa: r.publish_without_qa?, repo_name: r.name, platform_id: r.platform.id, - platform_name: r.platform.name, + default_branch: r.platform.default_branch, default_arches: ( r.platform.platform_arch_settings.by_default.pluck(:arch_id).presence || Arch.where(name: Arch::DEFAULT).pluck(:id) ) } diff --git a/app/models/platform.rb b/app/models/platform.rb index ebbe43161..8769cc82a 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -65,7 +65,11 @@ class Platform < ActiveRecord::Base uniqueness: { case_sensitive: false }, presence: true, format: { with: /\A#{NAME_PATTERN}\z/ }, - length: { maximum: 100 } + length: { maximum: 100 } + + validates :default_branch, + presence: true, + length: { maximum: 100 } validates :distrib_type, presence: true, @@ -114,7 +118,8 @@ class Platform < ActiveRecord::Base :platform_arch_settings_attributes, :automatic_metadata_regeneration, :admin_id, - :term + :term, + :default_branch attr_accessor :admin_id, :term diff --git a/app/views/platforms/platforms/_form.html.slim b/app/views/platforms/platforms/_form.html.slim index e464851af..ead035381 100644 --- a/app/views/platforms/platforms/_form.html.slim +++ b/app/views/platforms/platforms/_form.html.slim @@ -22,6 +22,8 @@ value: @admin_uname, class: 'typeahead' } += f.input :default_branch + - if %w(edit update).include? controller.action_name - if can? :change_visibility, @platform diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index c6495c00a..af4e7467d 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -98,9 +98,14 @@ en: simple_form: labels: platform: - term: Search - admin_id: Owner + term: Search + admin_id: Owner + default_branch: Default branch + hints: + platform: + default_branch: "This is the name of branch that will be used by default at creation of build for platform." placeholders: platform: - term: Enter the name of file or folder here. + term: Enter the name of file or folder here. + default_branch: Enter the name of branch here. diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index 335d67ed3..7a788877a 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -99,8 +99,14 @@ ru: simple_form: labels: platform: - term: Искать - admin_id: Владелец + term: Искать + admin_id: Владелец + default_branch: Ветка по умолчанию + hints: + platform: + default_branch: "Это имя ветки, которая будет использоваться по умолчанию при создании сборок для платформы." placeholders: platform: - term: Введите имя файла или папки здесь. + term: Введите имя файла или папки здесь. + default_branch: Введите имя ветки здесь. + diff --git a/db/migrate/20150217215529_add_default_branch_to_platforms.rb b/db/migrate/20150217215529_add_default_branch_to_platforms.rb new file mode 100644 index 000000000..0ff30af4a --- /dev/null +++ b/db/migrate/20150217215529_add_default_branch_to_platforms.rb @@ -0,0 +1,11 @@ +class AddDefaultBranchToPlatforms < ActiveRecord::Migration + def up + add_column :platforms, :default_branch, :string + execute "UPDATE platforms SET default_branch = name" + change_column_null :platforms, :default_branch, false + end + + def down + remove_column :platforms, :default_branch + end +end diff --git a/db/schema.rb b/db/schema.rb index 1101a8ce0..586ebd187 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: 20150210192749) do +ActiveRecord::Schema.define(version: 20150217215529) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -416,6 +416,7 @@ ActiveRecord::Schema.define(version: 20150210192749) do t.integer "last_regenerated_status" t.string "last_regenerated_log_sha1" t.string "automatic_metadata_regeneration" + t.string "default_branch", null: false t.index ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false end diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb index 7b176775c..e9b2d1bb4 100644 --- a/spec/models/platform_spec.rb +++ b/spec/models/platform_spec.rb @@ -18,6 +18,7 @@ describe Platform do it { should validate_uniqueness_of(:name).case_insensitive } it { should allow_value('Basic_platform-name-1234').for(:name) } it { should_not allow_value('.!').for(:name) } + it { should validate_presence_of(:default_branch)} it { should validate_presence_of(:description) } it { should validate_presence_of(:distrib_type) } it { should validate_presence_of(:visibility) }