[refs #374] Refactor api build lists create logic

This commit is contained in:
konstantin.grabar 2012-09-03 17:49:11 +04:00
parent 6229daf137
commit 5d0d972a0d
1 changed files with 20 additions and 23 deletions

View File

@ -14,22 +14,21 @@ class Api::V1::BuildListsController < Api::V1::BaseController
def create
notices, errors = [], []
json_report = {:build_lists => []}
json_report = {:build_list => []}
project = Project.find(params[:build_list][:project_id])
platform = Platform.includes(:repositories).find params[:build_list][:save_to_platform_id]
repository = project.repositories.where(:id => platform.repository_ids).first
arch = Arch.find(params[:build_list][:arch_id])
save_to_repository = Repository.find params[:build_list][:save_to_repository_id]
params[:build_list][:save_to_platform_id] = save_to_repository.platform_id
params[:build_list][:save_to_repository_id] = repository.id
params[:build_list][:auto_publish] = false if platform.released
Arch.where(:id => params[:arches]).each do |arch|
Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform|
build_list = project.build_lists.build(params[:build_list])
build_list.project_version = build_list.commit_hash
build_list.build_for_platform = build_for_platform; build_list.arch = arch; build_list.user = current_user
build_list.user = current_user
build_list.include_repos = build_list.include_repos.select {|ir| build_list.build_for_platform.repository_ids.include? ir.to_i}
build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
flash_options = {:project_version => build_list.project_version, :arch => arch.name, :build_for_platform => build_for_platform.name}
flash_options = {:project_version => build_list.project_version, :arch => arch.name, :build_for_platform => build_list.build_for_platform.name}
if build_list.save
msg = t("flash.build_list.saved", flash_options)
notices << msg
@ -37,11 +36,9 @@ class Api::V1::BuildListsController < Api::V1::BaseController
msg = t("flash.build_list.save_error", flash_options)
errors << msg
end
json_report[:build_lists] << {"id" => build_list.id, "message" => msg}
end
end
msg << t("flash.build_list.no_arch_or_platform_selected") if errors.blank? and notices.blank?
json_report[:build_list] = {"id" => build_list.id, "message" => msg}
errors << t("flash.build_list.no_arch_or_platform_selected") if errors.blank? and notices.blank?
render :json => json_report.to_json
end