diff --git a/app/assets/javascripts/extra/build_list.js b/app/assets/javascripts/extra/build_list.js index dd24f24ea..9e8f3b4a9 100644 --- a/app/assets/javascripts/extra/build_list.js +++ b/app/assets/javascripts/extra/build_list.js @@ -34,11 +34,11 @@ $(document).ready(function() { } setBranchSelected(selected_option); } - var build_list_auto_publish = $('#build_list_auto_publish'); + var build_list_auto_publish_status = $('#build_list_auto_publish_status'); if (selected_option.attr('publish_without_qa') == '1') { - build_list_auto_publish.removeAttr('disabled').attr('checked', 'checked'); + build_list_auto_publish_status.removeAttr('disabled').val('default'); } else { - build_list_auto_publish.removeAttr('checked').attr('disabled', 'disabled'); + build_list_auto_publish_status.val('none').attr('disabled', 'disabled'); auto_create_container.attr('checked', 'checked'); } }); diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index dc6fce832..4394ea3d1 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -16,10 +16,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController bl_params = params[:build_list] || {} save_to_repository = Repository.where(id: bl_params[:save_to_repository_id]).first - if save_to_repository - bl_params[:save_to_platform_id] = save_to_repository.platform_id - bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa? - end + bl_params[:save_to_platform_id] = save_to_repository.platform_id if save_to_repository @build_list = current_user.build_lists.new(bl_params) @build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index c52bcc406..42e443c72 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -56,7 +56,6 @@ class Projects::BuildListsController < Projects::BaseController @platform = @repository.platform params[:build_list][:save_to_platform_id] = @platform.id - params[:build_list][:auto_publish] = false unless @repository.publish_without_qa? build_for_platforms = Repository.select(:platform_id). where(id: params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id) @@ -192,7 +191,7 @@ class Projects::BuildListsController < Projects::BaseController build_list = BuildList.find(params[:build_list_id]) params[:build_list] ||= {} - keys = [:save_to_repository_id, :auto_publish, :include_repos, :extra_params, + keys = [:save_to_repository_id, :auto_publish_status, :include_repos, :extra_params, :project_version, :update_type, :auto_create_container, :extra_repositories, :extra_build_lists, :build_for_platform_id] keys.each { |key| params[:build_list][key] = build_list.send(key) } diff --git a/app/helpers/build_lists_helper.rb b/app/helpers/build_lists_helper.rb index 0890218c6..63cfb9101 100644 --- a/app/helpers/build_lists_helper.rb +++ b/app/helpers/build_lists_helper.rb @@ -38,6 +38,12 @@ module BuildListsHelper end end + def auto_publish_statuses + BuildList::AUTO_PUBLISH_STATUSES.map do |status| + [I18n.t("layout.build_lists.auto_publish_status.#{status}"), status] + end + end + def mass_build_options options_from_collection_for_select( MassBuild.recent.limit(15), diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 3527a4d00..63a145914 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -23,10 +23,16 @@ class BuildList < ActiveRecord::Base EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm] EXTERNAL_NODES = %w[owned everything] + AUTO_PUBLISH_STATUS_NONE = 'none' + AUTO_PUBLISH_STATUS_DEFAULT = 'default' + AUTO_PUBLISH_STATUS_TESTING = 'testing' + AUTO_PUBLISH_STATUSES = [AUTO_PUBLISH_STATUS_NONE, AUTO_PUBLISH_STATUS_DEFAULT, AUTO_PUBLISH_STATUS_TESTING] + validates :project_id, :project_version, :arch, :include_repos, :build_for_platform_id, :save_to_platform_id, :save_to_repository_id, presence: true validates_numericality_of :priority, greater_than_or_equal_to: 0 validates :external_nodes, inclusion: {in: EXTERNAL_NODES}, allow_blank: true + validates :auto_publish_status, inclusion: {in: AUTO_PUBLISH_STATUSES} validates :update_type, inclusion: UPDATE_TYPES, unless: Proc.new { |b| b.advisory.present? } validates :update_type, inclusion: {in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform')}, @@ -50,14 +56,15 @@ class BuildList < ActiveRecord::Base before_validation :prepare_extra_repositories, on: :create before_validation :prepare_extra_build_lists, on: :create before_validation :prepare_extra_params, on: :create - before_validation lambda { self.auto_publish = false if external_nodes.present?; true }, on: :create - before_validation lambda { self.auto_create_container = false if auto_publish?; true }, on: :create + before_validation lambda { self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE if external_nodes.present?; true }, on: :create + before_validation lambda { self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE if auto_publish? && !save_to_repository.publish_without_qa?; true }, on: :create + before_validation lambda { self.auto_create_container = false if auto_publish? || auto_publish_into_testing?; true }, on: :create attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash, :arch_id, :project_id, :save_to_repository_id, :update_type, :save_to_platform_id, :project_version, :auto_create_container, :extra_repositories, :extra_build_lists, :extra_params, :external_nodes, - :include_testing_subrepository + :include_testing_subrepository, :auto_publish_status LIVE_TIME = 4.week # for unpublished MAX_LIVE_TIME = 3.month # for published @@ -167,7 +174,7 @@ class BuildList < ActiveRecord::Base after_transition on: [:published, :fail_publish, :build_error, :tests_failed], do: :notify_users after_transition on: :build_success, do: :notify_users, - unless: lambda { |build_list| build_list.auto_publish? } + unless: lambda { |build_list| build_list.auto_publish? || build_list.auto_publish_into_testing? } event :place_build do transition waiting_for_response: :build_pending @@ -359,6 +366,19 @@ class BuildList < ActiveRecord::Base return false # no new packages end + def auto_publish? + auto_publish_status == AUTO_PUBLISH_STATUS_DEFAULT + end + + def auto_publish_into_testing? + auto_publish_status == AUTO_PUBLISH_STATUS_TESTING + end + + # TODO: remove later + def auto_publish=(value) + self.auto_publish_status = value.present? ? AUTO_PUBLISH_STATUS_DEFAULT : AUTO_PUBLISH_STATUS_NONE + end + def can_auto_publish? auto_publish? && can_publish? && has_new_packages? && can_publish_into_repository? end diff --git a/app/models/project.rb b/app/models/project.rb index d48788372..9fc0eacce 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -185,7 +185,7 @@ class Project < ActiveRecord::Base bl.arch = arch bl.project_version = project_version bl.user = user - bl.auto_publish = mass_build.auto_publish? + bl.auto_publish_status = mass_build.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE bl.include_repos = include_repos bl.extra_repositories = mass_build.extra_repositories bl.extra_build_lists = mass_build.extra_build_lists @@ -324,7 +324,7 @@ class Project < ActiveRecord::Base bl.arch_id = arch_id bl.project_version = p.project_version_for(platform, platform) bl.user = user - bl.auto_publish = p_to_r.auto_publish? + bl.auto_publish_status = p_to_r.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE bl.save_to_repository = repository bl.include_repos = [repository.id, platform.repositories.main.first.try(:id)].uniq.compact end diff --git a/app/views/api/v1/build_lists/show.json.jbuilder b/app/views/api/v1/build_lists/show.json.jbuilder index 2b146ca40..2e7718912 100644 --- a/app/views/api/v1/build_lists/show.json.jbuilder +++ b/app/views/api/v1/build_lists/show.json.jbuilder @@ -2,7 +2,7 @@ json.build_list do json.(@build_list, :id, :container_status, :status, :duration) json.(@build_list, :update_type, :priority, :new_core) json.(@build_list, :advisory, :mass_build) - json.(@build_list, :auto_publish, :package_version, :commit_hash, :last_published_commit_hash, :auto_create_container) + json.(@build_list, :auto_publish_status, :package_version, :commit_hash, :last_published_commit_hash, :auto_create_container) json.build_log_url log_build_list_path(@build_list) if @build_list.container_published? diff --git a/app/views/projects/build_lists/_new_form.html.haml b/app/views/projects/build_lists/_new_form.html.haml index 45579ad3d..2b60680c1 100644 --- a/app/views/projects/build_lists/_new_form.html.haml +++ b/app/views/projects/build_lists/_new_form.html.haml @@ -43,7 +43,11 @@ .both %h3= t("activerecord.attributes.build_list.preferences") - - [:auto_publish, :auto_create_container, :include_testing_subrepository].each do |kind| + - selected = params[:build_list].try(:[], :auto_publish_status) ? {selected: params[:build_list][:auto_publish_status]} : {} + = f.select :auto_publish_status, auto_publish_statuses, selected + = f.label :auto_publish_status + .both + - %i(auto_create_container include_testing_subrepository).each do |kind| .both - checked, field = params[:build_list].try(:[], kind), "build_list[#{kind}]" = hidden_field_tag field, false, id: nil diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index e279a1a60..23173d522 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -57,8 +57,8 @@ {{ update_type_errors }} .both .both - .leftlist= t("activerecord.attributes.build_list.auto_publish") - .rightlist= t("layout.#{@build_list.auto_publish}_") + .leftlist= t("activerecord.attributes.build_list.auto_publish_status") + .rightlist= t("layout.build_lists.auto_publish_status.#{@build_list.auto_publish_status}") .both .leftlist= t("activerecord.attributes.build_list.auto_create_container") .rightlist= t("layout.#{@build_list.auto_create_container?}_") diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 376ef745d..651c6a10d 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -27,7 +27,7 @@ en: save_to_repository: Save to repository build_for_platform: Build for platform update_type: Update type - auto_publish: Automated publishing + auto_publish_status: Automated publishing project_version: Version user: User publisher: Publisher @@ -135,6 +135,11 @@ en: git_error: Git error build_canceled: Build canceled + auto_publish_status: + none: None + default: Default + testing: Into 'testing' + statuses: build_lists: All build_error: Build error diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 308224f62..c20f0b33d 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -27,7 +27,7 @@ ru: save_to_repository: Сохранить в репозиторий build_for_platform: Собрано для платформы update_type: Критичность обновления - auto_publish: Автоматическая публикация + auto_publish_status: Автоматическая публикация project_version: Версия user: Пользователь publisher: Публикатор @@ -134,6 +134,11 @@ ru: git_error: проблема с гит build_canceled: сборка отменена + auto_publish_status: + none: Нет + default: По умолчанию + testing: В 'testing' + statuses: build_lists: Всего build_error: ошибка сборки diff --git a/db/migrate/20140219191644_add_auto_publish_status_to_build_list.rb b/db/migrate/20140219191644_add_auto_publish_status_to_build_list.rb new file mode 100644 index 000000000..1b2412bb2 --- /dev/null +++ b/db/migrate/20140219191644_add_auto_publish_status_to_build_list.rb @@ -0,0 +1,16 @@ +class AddAutoPublishStatusToBuildList < ActiveRecord::Migration + + class BuildList < ActiveRecord::Base + end + + def up + # Make existing build_lists 'none', but default to 'default' in the future. + add_column :build_lists, :auto_publish_status, :string, default: 'none', null: false + BuildList.where(auto_publish: true).update_all(auto_publish_status: :default) + change_column :build_lists, :auto_publish_status, :string, default: 'default', null: false + end + + def down + remove_column :build_lists, :auto_publish_status + end +end diff --git a/db/schema.rb b/db/schema.rb index 7f6db9edc..ff37abb52 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140217192640) do +ActiveRecord::Schema.define(:version => 20140219191644) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -125,7 +125,7 @@ ActiveRecord::Schema.define(:version => 20140217192640) do t.boolean "auto_publish", :default => true t.string "package_version" t.string "commit_hash" - t.integer "priority", :default => 0, :null => false + t.integer "priority", :default => 0, :null => false t.datetime "started_at" t.integer "duration" t.integer "advisory_id" @@ -144,6 +144,7 @@ ActiveRecord::Schema.define(:version => 20140217192640) do t.string "external_nodes" t.integer "builder_id" t.boolean "include_testing_subrepository" + t.string "auto_publish_status", :default => "default", :null => false end add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id" diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index 6615e733e..34b3e7e15 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -21,7 +21,11 @@ module AbfWorker case status when COMPLETED subject.build_success - subject.now_publish if subject.can_auto_publish? + if subject.can_auto_publish? + subject.now_publish + elsif subject.auto_publish_into_testing? + subject.now_publish_into_testing + end when FAILED subject.build_error item.update_attributes({status: BuildList::BUILD_ERROR}) diff --git a/spec/models/build_list_spec.rb b/spec/models/build_list_spec.rb index 84e4ebe12..6e144fb2b 100644 --- a/spec/models/build_list_spec.rb +++ b/spec/models/build_list_spec.rb @@ -19,7 +19,7 @@ describe BuildList do let!(:user) { FactoryGirl.create(:user) } let!(:build_list) { FactoryGirl.create(:build_list, user: user, - auto_publish: false) } + auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_NONE) } let!(:build_list_package) { FactoryGirl.create(:build_list_package, build_list: build_list, project: build_list.project) } @@ -44,7 +44,7 @@ describe BuildList do end it "gets notification by email when auto_publish and status - Build error" do - build_list.update_attributes(auto_publish: true) + build_list.update_attributes(auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT) build_list.build_error should have(1).item end @@ -56,7 +56,7 @@ describe BuildList do end it "gets notification by email when auto_publish and status - Failed publish" do - build_list.update_attributes({auto_publish: true, status: BuildList::BUILD_PUBLISH}, without_protection: true) + build_list.update_attributes({auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT, status: BuildList::BUILD_PUBLISH}, without_protection: true) build_list.fail_publish should have(1).item end @@ -68,13 +68,13 @@ describe BuildList do end it "gets notification by email when auto_publish and status - Build published" do - build_list.update_attributes({auto_publish: true, status: BuildList::BUILD_PUBLISH}, without_protection: true) + build_list.update_attributes({auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT, status: BuildList::BUILD_PUBLISH}, without_protection: true) build_list.published should have(1).item end it "doesn't get notification by email when auto_publish and status - Build complete" do - build_list.update_attributes(auto_publish: true) + build_list.update_attributes(auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT) build_list.build_success should have(:no).items end @@ -141,9 +141,9 @@ describe BuildList do it "doesn't get 2 notification by email when user associated to project and created task" do project = FactoryGirl.create(:project_with_commit, owner: user) bl = FactoryGirl.create(:build_list_with_attaching_project, - user: user, - auto_publish: true, - project: project + user: user, + auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT, + project: project ) FactoryGirl.create(:build_list_package, build_list: bl, project: bl.project) bl.update_attributes({commit_hash: bl.project.repo.commits('master').last.id, @@ -156,8 +156,8 @@ describe BuildList do context '#has_new_packages?' do let!(:build_list) { FactoryGirl.create( :build_list, - status: BuildList::SUCCESS, - auto_publish: true) } + status: BuildList::SUCCESS, + auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT) } let!(:build_list_package) { FactoryGirl.create( :build_list_package, build_list: build_list, version: '3.1.12',