From 5d0d972a0d12b765cb10348ed9707a3a4f5a09a3 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 3 Sep 2012 17:49:11 +0400 Subject: [PATCH] [refs #374] Refactor api build lists create logic --- .../api/v1/build_lists_controller.rb | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index e5765945f..09c1600aa 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -14,34 +14,31 @@ 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 + build_list = project.build_lists.build(params[:build_list]) + build_list.project_version = build_list.commit_hash - 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.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} - if build_list.save - msg = t("flash.build_list.saved", flash_options) - notices << msg - else - msg = t("flash.build_list.save_error", flash_options) - errors << msg - end - json_report[:build_lists] << {"id" => build_list.id, "message" => msg} - end + 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_list.build_for_platform.name} + + if build_list.save + msg = t("flash.build_list.saved", flash_options) + notices << msg + else + msg = t("flash.build_list.save_error", flash_options) + errors << msg 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