[refs #442] Mass build refactor and fixes

This commit is contained in:
konstantin.grabar 2012-05-25 19:56:26 +04:00
parent 45ff187875
commit a79d946b6b
11 changed files with 71 additions and 56 deletions

View File

@ -953,3 +953,7 @@ form.mass_build input[type="checkbox"] {
width: 10px;
height: 11px;
}
.bottom_20 {
margin-bottom: 20px;
}

View File

@ -7,14 +7,18 @@ class Platforms::PlatformsController < Platforms::BaseController
autocomplete :user, :uname
def build_all
mass_build = MassBuild.create!(:platform => @platform, :user => current_user)
mass_build.delay.build_all(
:user => current_user,
:repositories => params[:repositories],
:arches => params[:arches],
:auto_publish => params[:auto_publish]
)
redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success"))
mass_build = MassBuild.new(:platform => @platform, :user => current_user)
if mass_build.build_all(
:repositories => params[:repositories],
:arches => params[:arches],
:auto_publish => params[:auto_publish]
)
redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success"))
else
@mass_builds = MassBuild.paginate(:page => params[:page], :per_page => 20)
flash[:warning] = mass_build.errors.full_messages.join('. ')
flash[:error] = t("flash.platform.build_all_error")
end
end
def mass_builds

View File

@ -8,8 +8,8 @@ module ApplicationHelper
'right slim'
when controller_name == 'build_lists' && ['new', 'create'].include?(action_name)
nil
#when controller_name == 'platforms' && action_name == 'build_all'
# nil
when controller_name == 'platforms' && ['build_all', 'mass_builds'].include?(action_name)
nil
when controller_name == 'platforms' && action_name == 'show'
'right bigpadding'
when controller_name == 'platforms' && action_name == 'clone'

View File

@ -5,11 +5,19 @@ class MassBuild < ActiveRecord::Base
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
attr_accessor :repositories_ids
validates :platform_id, :auto_publish, :arch_names, :name, :user_id, :repositories_ids, :presence => true
def build_all(opts={})
auto_publish = opts[:auto_publish] || false
set_data opts[:repositories], opts[:arches], auto_publish
platform.build_all opts.merge({:mass_build_id => self.id})
if set_data(opts[:repositories], opts[:arches], auto_publish)
platform.delay.build_all opts.merge({:mass_build_id => self.id, :user => self.user})
true
else
false
end
end
private
@ -19,6 +27,7 @@ class MassBuild < ActiveRecord::Base
self.name = "#{Date.today.strftime("%d.%b")}-#{platform.name}(#{rep_names})"
self.arch_names = Arch.where(:id => arches).map(&:name).join(", ")
self.auto_publish = auto_publish
self.repositories_ids = repositories_ids
self.save
end
end

View File

@ -1,46 +1,26 @@
- content_for(:sidebar) do
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
.bordered.nopadding
.table
%h3= t("activerecord.attributes.build_list.build_for_platform")
- @platform.repositories.each do |rep|
.lefter
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}"
= label_tag "repositories_#{rep.id}", rep.name
.both
.both
.table
%h3= t("activerecord.attributes.build_list.arch")
- Arch.recent.each do |arch|
.lefter
= 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
.both
.table
%h3= t("activerecord.attributes.build_list.preferences")
.lefter
= check_box_tag :auto_publish, true, params[:auto_publish].present? ? params[:auto_publish].present? : true, :id => 'auto_publish'
= label_tag t('activerecord.attributes.mass_build.auto_publish')
.both
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
%section.left
%h3= t("layout.mass_builds.repositories")
- @platform.repositories.each do |rep|
.both
%br
= f.submit t("layout.projects.build_button")
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}"
= label_tag "repositories_#{rep.id}", rep.name
%br
= f.submit t("layout.projects.build_button")
%section.right
%h3= t("activerecord.attributes.build_list.arch")
- Arch.recent.each do |arch|
.lefter
= 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
%h3= t("activerecord.attributes.build_list.preferences")
.both.bottom_20
= check_box_tag :auto_publish, true, params[:auto_publish].present? ? params[:auto_publish].present? : true, :id => 'auto_publish'
= label_tag :auto_publish
%br
%br
.bordered.nopadding
.table
- ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state|
.lefter
= t("layout.build_lists.statuses.#{state.demodulize.downcase}")
.righter
= BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count
.both
%br
= link_to t("layout.activity_feed.all_my_builds"), build_lists_path
%h3.fix= t("layout.platforms.mass_build")
%br
%br
%table.tablesorter.unbordered
%thead
@ -54,7 +34,7 @@
%tr
%td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id})
%td= mass_build.arch_names
%td= mass_build.user.name
%td= mass_build.user.uname
%td= mass_build.auto_publish
%td= mass_build.created_at
= will_paginate @mass_builds

View File

@ -1,6 +1,6 @@
%tr{:id => "row#{build_list_counter}", :class => "#{build_list_status_color(build_list.status)}"}
%td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), build_list
%td= build_list.mass_build_id ? build_list.mass_build.name : ""
%td= build_list.mass_build_id ? link_to(build_list.mass_build.name, mass_builds_platform_path(build_list.save_to_platform)) : ""
%td= build_list.human_status
%td= link_to build_list.project.name, build_list.project
%td= link_to build_list.project_version, "#"

View File

@ -1,4 +1,7 @@
en:
layout:
mass_builds:
repositories: Repositories
activerecord:
models:
mass_build: Mass Build
@ -10,3 +13,4 @@ en:
arch_names: Architectures
user: User
auto_publish: Auto Publish
repositories_ids: Repositories

View File

@ -1,4 +1,7 @@
ru:
layout:
mass_builds:
repositories: Репозитории
activerecord:
models:
mass_build: Массовая Сборка
@ -10,3 +13,4 @@ ru:
arch_names: Архитектуры
user: Пользователь
auto_publish: Авто Публикация
repositories_ids: Репозитории

View File

@ -58,6 +58,7 @@ en:
unfreeze_error: Platform unfreezing error, try again
destroyed: Platform deleted
build_all_success: All project build in progress
build_all_error: Mass build failed
clone_success: Cloned successfully
members:
already_added: "%{name} is already a member of platform"

View File

@ -58,6 +58,7 @@ ru:
unfreeze_error: Не удалось разморозить платформу, попробуйте еще раз
destroyed: Платформа успешно удалена
build_all_success: Все проекты успешно отправлены на сборку
build_all_error: Сборка не удалась!
clone_success: Клонирование успешно
members:
already_added: "%{name} уже является участником платформы"

View File

@ -0,0 +1,8 @@
class SetMassBuildUserIdToFirstIfNil < ActiveRecord::Migration
def up
MassBuild.update_all(:user_id => nil, :user_id => 1)
end
def down
end
end