From ff0487427849379159fa1d0d625c7d209030f846 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 3 Jun 2013 19:20:23 +0400 Subject: [PATCH] #156: added MassBuild for personal platforms --- .../platforms/mass_builds_controller.rb | 4 +-- app/models/ability.rb | 9 +++-- app/models/mass_build.rb | 29 ++++++++++------ app/models/platform.rb | 2 +- app/models/project.rb | 30 ++++++++-------- app/views/platforms/base/_sidebar.html.haml | 2 +- .../platforms/mass_builds/_form.html.haml | 10 +++++- config/locales/models/mass_build.en.yml | 1 + config/locales/models/mass_build.ru.yml | 1 + ...4853_add_save_to_platform_to_mass_build.rb | 20 +++++++++++ db/schema.rb | 34 ++++++++++--------- lib/tasks/build.rake | 2 +- 12 files changed, 92 insertions(+), 52 deletions(-) create mode 100644 db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb diff --git a/app/controllers/platforms/mass_builds_controller.rb b/app/controllers/platforms/mass_builds_controller.rb index 27c261e95..96fee671c 100644 --- a/app/controllers/platforms/mass_builds_controller.rb +++ b/app/controllers/platforms/mass_builds_controller.rb @@ -20,7 +20,7 @@ class Platforms::MassBuildsController < Platforms::BaseController if mass_build.save redirect_to(platform_mass_builds_path(@platform), :notice => t("flash.platform.build_all_success")) else - @auto_publish_selected = params[:auto_publish].present? + @auto_publish_selected, @use_save_to_repository = params[:auto_publish].present?, params[:use_save_to_repository].present? @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) flash[:warning] = mass_build.errors.full_messages.join('. ') flash[:error] = t("flash.platform.build_all_error") @@ -39,7 +39,7 @@ class Platforms::MassBuildsController < Platforms::BaseController def index @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) - @auto_publish_selected = true + @auto_publish_selected = @use_save_to_repository = true end def cancel diff --git a/app/models/ability.rb b/app/models/ability.rb index 52c080448..56a4e6173 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -26,7 +26,7 @@ class Ability # Platforms block can [:show, :members, :advisories], Platform, :visibility => 'open' can :platforms_for_build, Platform, :visibility => 'open', :platform_type => 'main' - can(:get_list, MassBuild) {|mass_build| mass_build.platform.main? && can?(:show, mass_build.platform) } + can(:get_list, MassBuild) {|mass_build| can?(:show, mass_build.save_to_platform) } can [:read, :projects_list, :projects], Repository, :platform => {:visibility => 'open'} can :read, Product, :platform => {:visibility => 'open'} @@ -105,8 +105,8 @@ class Ability can([:update, :destroy], Platform) {|platform| owner?(platform) } can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) } - can([:create, :publish], MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && mass_build.platform.main?} - can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build && mass_build.platform.main?} + can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)} + can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)) && !mass_build.stop_build} can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} @@ -166,8 +166,7 @@ class Ability cannot :create_container, BuildList, :new_core => false cannot(:publish, BuildList) {|build_list| !build_list.can_publish? } - cannot([:get_list, :create, :publish], MassBuild) {|mass_build| mass_build.platform.personal?} - cannot(:cancel, MassBuild) {|mass_build| mass_build.platform.personal? || mass_build.stop_build} + cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build} cannot(:regenerate_metadata, Repository) {|repository| !repository.platform.main?} diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 03bcb8fbf..c388e1028 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -1,20 +1,22 @@ class MassBuild < ActiveRecord::Base - belongs_to :platform + belongs_to :build_for_platform, :class_name => 'Platform' + belongs_to :save_to_platform, :class_name => 'Platform' belongs_to :user has_many :build_lists, :dependent => :destroy scope :recent, order("#{table_name}.created_at DESC") - scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } + scope :by_platform, lambda { |platform| where(:save_to_platform_id => platform.id) } scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) attr_accessor :arches attr_accessible :arches, :auto_publish, :projects_list - validates :platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true + validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true validates_inclusion_of :auto_publish, :in => [true, false] after_create :build_all - before_validation :set_data + before_validation :set_data, :on => :create + before_validation :set_build_for_platform, :on => :create COUNT_STATUSES = [ :build_lists, @@ -36,12 +38,12 @@ class MassBuild < ActiveRecord::Base next if name.blank? name.chomp!; name.strip! - if project = Project.joins(:repositories).where('repositories.id in (?)', platform.repository_ids).find_by_name(name) + if project = Project.joins(:repositories).where('repositories.id in (?)', save_to_platform.repository_ids).find_by_name(name) begin return if self.reload.stop_build arches_list.each do |arch| - rep = (project.repositories & platform.repositories).first - project.build_for(platform, rep.id, user, arch, auto_publish, self.id, 0) + rep_id = (project.repository_ids & save_to_platform.repository_ids).first + project.build_for(build_for_platform, save_to_platform, rep_id, user, arch, auto_publish, self, 0) end rescue RuntimeError, Exception end @@ -98,10 +100,15 @@ class MassBuild < ActiveRecord::Base end end - def set_data - if new_record? - self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}" - self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") + def set_build_for_platform + if save_to_platform && save_to_platform.main? + self.build_for_platform = save_to_platform + self.use_save_to_repository = true end end + + def set_data + self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}" + self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") + end end diff --git a/app/models/platform.rb b/app/models/platform.rb index 67ad038ff..6d14ff1e5 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -16,7 +16,7 @@ class Platform < ActiveRecord::Base has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy - has_many :mass_builds + has_many :mass_builds, :foreign_key => :save_to_platform_id validates :description, :presence => true validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} diff --git a/app/models/project.rb b/app/models/project.rb index 943f5d366..acff6ea40 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -146,27 +146,29 @@ class Project < ActiveRecord::Base #path #share by NFS end - def build_for(platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build_id = nil, priority = 0) + def build_for(build_for_platform, save_to_platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build = nil, priority = 0) # Select main and project platform repository(contrib, non-free and etc) # If main does not exist, will connect only project platform repository # If project platform repository is main, only main will be connect - main_rep_id = platform.repositories.find_by_name('main').try(:id) - build_reps_ids = [main_rep_id, repository_id].compact.uniq + main_rep_id = build_for_platform.repositories.find_by_name('main').try(:id) + include_repos = [main_rep_id] << (save_to_platform.main? ? repository_id : nil).compact.uniq + project_version = repo.commits("#{platform.name}").try(:first).try(:id) ? platform.name : 'master' build_list = build_lists.build do |bl| - bl.save_to_platform = platform - bl.build_for_platform = platform - bl.update_type = 'newpackage' - bl.arch = arch - bl.project_version = project_version - bl.user = user - bl.auto_publish = auto_publish - bl.include_repos = build_reps_ids - bl.priority = priority - bl.mass_build_id = mass_build_id - bl.save_to_repository_id = repository_id + bl.save_to_platform = platform + bl.build_for_platform = platform + bl.update_type = 'newpackage' + bl.arch = arch + bl.project_version = project_version + bl.user = user + bl.auto_publish = auto_publish + bl.include_repos = include_repos + bl.extra_repositories = [repository_id] if save_to_platform.personal? && mass_build.use_save_to_repository? + bl.priority = priority + bl.mass_build_id = mass_build.try(:id) + bl.save_to_repository_id = repository_id end build_list.save end diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index 4edefc28a..e8c95b594 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -13,7 +13,7 @@ - if can? :show, @platform %li{:class => (act == :index && contr == :maintainers) ? 'active' : nil} = link_to t("layout.platforms.maintainers"), platform_maintainers_path(@platform) - - if @platform.main? && can?(:show, @platform) + - if can?(:show, @platform) %li{:class => (contr == :mass_builds && [:index, :create].include?(act)) ? 'active' : ''} = link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform) - if can? :read, @platform.products.build diff --git a/app/views/platforms/mass_builds/_form.html.haml b/app/views/platforms/mass_builds/_form.html.haml index 88748ed12..172c9044f 100644 --- a/app/views/platforms/mass_builds/_form.html.haml +++ b/app/views/platforms/mass_builds/_form.html.haml @@ -10,8 +10,16 @@ = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" = label_tag "arches_#{arch.id}", arch.name .both + - if @platform.personal? + %h3= t('activerecord.attributes.build_list.build_for_platform') + - platforms = Platform.main.select{ |p| p.repository_ids.size > 0 } + = select_tag 'build_for_platform', options_from_collection_for_select(platforms, :id, :name), :include_blank => false + .both %h3= t("activerecord.attributes.build_list.preferences") - .both.bottom_20 + .both = check_box_tag :auto_publish, true, @auto_publish_selected, :id => 'auto_publish' = label_tag :auto_publish, t('activerecord.attributes.build_list.auto_publish') + - if @platform.personal? + = check_box_tag :use_save_to_repository, true, @use_save_to_repository, :id => 'auto_publish' + = label_tag :use_save_to_repository, t('activerecord.attributes.mass_build.use_save_to_repository') .both \ No newline at end of file diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index bafb62b01..931704e45 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -21,6 +21,7 @@ en: created_at: Created updated_at: Updated arch_names: Architectures + use_save_to_repository: Use personal repository for assembly user: User auto_publish: Auto Publish repositories: Repositories diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 974e7f09d..9763dee59 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -21,6 +21,7 @@ ru: created_at: Создан updated_at: Обновлен arch_names: Архитектуры + use_save_to_repository: Использовать персональный репозиторий для сборки user: Пользователь auto_publish: Авто Публикация repositories: Репозитории diff --git a/db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb b/db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb new file mode 100644 index 000000000..07948564f --- /dev/null +++ b/db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb @@ -0,0 +1,20 @@ +class AddSaveToPlatformToMassBuild < ActiveRecord::Migration + class MassBuild < ActiveRecord::Base + end + + def up + add_column :mass_builds, :save_to_platform_id, :integer + MassBuild.update_all('save_to_platform_id = platform_id') + change_column :mass_builds, :save_to_platform_id, :integer, :null => false + change_column :mass_builds, :platform_id, :integer, :null => false + rename_column :mass_builds, :platform_id, :build_for_platform_id + add_column :mass_builds, :use_save_to_repository, :boolean + end + + def down + remove_column :mass_builds, :save_to_platform_id + remove_column :mass_builds, :use_save_to_repository + rename_column :mass_builds, :build_for_platform_id, :platform_id + end + +end diff --git a/db/schema.rb b/db/schema.rb index ed3d2c4ea..3b70efa2e 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 => 20130527181351) do +ActiveRecord::Schema.define(:version => 20130603124853) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -271,26 +271,28 @@ ActiveRecord::Schema.define(:version => 20130527181351) do add_index "labels", ["project_id"], :name => "index_labels_on_project_id" create_table "mass_builds", :force => true do |t| - t.integer "platform_id" + t.integer "build_for_platform_id", :null => false t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "arch_names" t.integer "user_id" - t.boolean "auto_publish", :default => false, :null => false - t.integer "build_lists_count", :default => 0, :null => false - t.integer "build_published_count", :default => 0, :null => false - t.integer "build_pending_count", :default => 0, :null => false - t.integer "build_started_count", :default => 0, :null => false - t.integer "build_publish_count", :default => 0, :null => false - t.integer "build_error_count", :default => 0, :null => false - t.boolean "stop_build", :default => false, :null => false + t.boolean "auto_publish", :default => false, :null => false + t.integer "build_lists_count", :default => 0, :null => false + t.integer "build_published_count", :default => 0, :null => false + t.integer "build_pending_count", :default => 0, :null => false + t.integer "build_started_count", :default => 0, :null => false + t.integer "build_publish_count", :default => 0, :null => false + t.integer "build_error_count", :default => 0, :null => false + t.boolean "stop_build", :default => false, :null => false t.text "projects_list" - t.integer "missed_projects_count", :default => 0, :null => false + t.integer "missed_projects_count", :default => 0, :null => false t.text "missed_projects_list" - t.boolean "new_core", :default => true - t.integer "success_count", :default => 0, :null => false - t.integer "build_canceled_count", :default => 0, :null => false + t.boolean "new_core", :default => true + t.integer "success_count", :default => 0, :null => false + t.integer "build_canceled_count", :default => 0, :null => false + t.integer "save_to_platform_id", :null => false + t.boolean "use_save_to_repository" end create_table "platforms", :force => true do |t| diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index c0f414df6..0ef7bb07a 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -13,7 +13,7 @@ namespace :build do open(source).readlines.each do |name| name.chomp!; name.strip! #; name.downcase! if p = Project.joins(:repositories).where('repositories.id IN (?)', platform.repositories).find_by_name(name) - # Old code p.build_for(platform, owner, arch) + # Old code p.build_for(platform, platform, owner, arch) say "== Build #{p.name} ==" else say "== Not found #{name} =="