2011-04-07 14:20:21 +01:00
|
|
|
class BuildListsController < ApplicationController
|
2011-12-22 00:53:55 +00:00
|
|
|
CALLBACK_ACTIONS = [:publish_build, :status_build, :pre_build, :post_build, :circle_build, :new_bbdt]
|
2011-12-21 21:42:06 +00:00
|
|
|
NESTED_ACTIONS = [:index, :new, :create]
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2011-11-30 00:56:57 +00:00
|
|
|
before_filter :authenticate_user!, :except => CALLBACK_ACTIONS
|
|
|
|
before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS
|
2011-12-21 21:42:06 +00:00
|
|
|
before_filter :find_project, :only => NESTED_ACTIONS
|
|
|
|
before_filter :find_build_list, :only => [:show, :publish, :cancel]
|
2011-12-29 02:37:34 +00:00
|
|
|
before_filter :find_build_list_by_bs, :only => [:publish_build, :status_build, :pre_build, :post_build, :circle_build]
|
2011-11-30 00:56:57 +00:00
|
|
|
|
2011-12-21 21:42:06 +00:00
|
|
|
load_and_authorize_resource :project, :only => NESTED_ACTIONS
|
2011-12-28 02:57:42 +00:00
|
|
|
load_and_authorize_resource :build_list, :through => :project, :only => NESTED_ACTIONS, :shallow => true
|
2011-12-21 21:42:06 +00:00
|
|
|
load_and_authorize_resource :except => CALLBACK_ACTIONS.concat(NESTED_ACTIONS)
|
2011-10-28 18:55:40 +01:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def index
|
2011-12-21 01:30:34 +00:00
|
|
|
filter_params = params[:filter] || {}
|
2011-12-21 21:42:06 +00:00
|
|
|
if @project
|
2011-12-21 01:30:34 +00:00
|
|
|
@action_url = project_build_lists_path(@project)
|
2011-10-22 16:28:41 +01:00
|
|
|
else
|
2011-12-21 01:30:34 +00:00
|
|
|
@action_url = build_lists_path
|
2011-04-07 15:56:28 +01:00
|
|
|
end
|
2011-10-22 16:28:41 +01:00
|
|
|
|
2011-12-21 01:30:34 +00:00
|
|
|
@filter = BuildList::Filter.new(@project, filter_params)
|
2011-12-22 00:53:55 +00:00
|
|
|
@build_lists = @filter.find.accessible_by(current_ability).recent.paginate :page => params[:page]
|
2011-12-02 01:30:25 +00:00
|
|
|
|
|
|
|
@build_server_status = begin
|
|
|
|
BuildServer.get_status
|
|
|
|
rescue Exception # Timeout::Error
|
|
|
|
{}
|
|
|
|
end
|
2011-12-22 00:53:55 +00:00
|
|
|
end
|
2011-10-22 16:28:41 +01:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def new
|
|
|
|
@build_list = BuildList.new
|
2011-12-21 14:01:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
notices, errors = [], []
|
2011-12-23 02:14:28 +00:00
|
|
|
Arch.where(:id => params[:arches]).each do |arch|
|
2011-12-21 14:01:50 +00:00
|
|
|
Platform.main.where(:id => params[:bpls]).each do |bpl|
|
|
|
|
@build_list = @project.build_lists.build(params[:build_list])
|
2011-12-21 19:17:55 +00:00
|
|
|
@build_list.bpl = bpl; @build_list.arch = arch; @build_list.user = current_user
|
2011-12-21 14:01:50 +00:00
|
|
|
flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :bpl => bpl.name, :pl => @build_list.pl}
|
|
|
|
if @build_list.save
|
|
|
|
notices << t("flash.build_list.saved", flash_options)
|
|
|
|
else
|
|
|
|
errors << t("flash.build_list.save_error", flash_options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
errors << t("flash.build_list.no_arch_or_platform_selected") if errors.blank? and notices.blank?
|
|
|
|
if errors.present?
|
|
|
|
@build_list ||= BuildList.new
|
|
|
|
flash[:error] = errors.join('<br>').html_safe
|
|
|
|
render :action => :new
|
|
|
|
else
|
|
|
|
flash[:notice] = notices.join('<br>').html_safe
|
|
|
|
redirect_to @project
|
|
|
|
end
|
|
|
|
end
|
2011-12-21 21:42:06 +00:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def show
|
|
|
|
@item_groups = @build_list.items.group_by_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish
|
|
|
|
if @build_list.publish
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.publish_success')
|
|
|
|
else
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.publish_fail')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
if @build_list.cancel
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.cancel_success')
|
|
|
|
else
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish_build
|
|
|
|
@build_list.status = (params[:status].to_i == 0 ? BuildList::BUILD_PUBLISHED : BuildList::FAILED_PUBLISH)
|
|
|
|
@build_list.notified_at = Time.current
|
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_build
|
|
|
|
@item = @build_list.items.find_by_name!(params[:package_name])
|
|
|
|
@item.status = params[:status]
|
|
|
|
@item.save
|
|
|
|
|
|
|
|
@build_list.container_path = params[:container_path]
|
|
|
|
@build_list.notified_at = Time.current
|
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def pre_build
|
|
|
|
@build_list.status = BuildServer::BUILD_STARTED
|
|
|
|
@build_list.notified_at = Time.current
|
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_build
|
|
|
|
@build_list.status = params[:status]
|
|
|
|
@build_list.container_path = params[:container_path]
|
|
|
|
@build_list.notified_at = Time.current
|
|
|
|
@build_list.save
|
|
|
|
|
2012-01-11 19:43:33 +00:00
|
|
|
@build_list.delay.publish if @build_list.auto_publish # && @build_list.can_publish?
|
2011-12-29 02:37:34 +00:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def circle_build
|
|
|
|
@build_list.is_circle = true
|
|
|
|
@build_list.container_path = params[:container_path]
|
|
|
|
@build_list.notified_at = Time.current
|
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_bbdt
|
|
|
|
@build_list = BuildList.find_by_id!(params[:web_id])
|
|
|
|
@build_list.name = params[:name]
|
|
|
|
@build_list.additional_repos = ActiveSupport::JSON.decode(params[:additional_repos])
|
|
|
|
@build_list.set_items(ActiveSupport::JSON.decode(params[:items]))
|
2011-12-29 02:37:34 +00:00
|
|
|
@build_list.is_circle = (params[:is_circular].to_i != 0)
|
2011-12-22 00:53:55 +00:00
|
|
|
@build_list.bs_id = params[:id]
|
2011-12-29 02:37:34 +00:00
|
|
|
@build_list.notified_at = Time.current
|
2011-12-22 00:53:55 +00:00
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def find_project
|
|
|
|
@project = Project.find_by_id params[:project_id]
|
|
|
|
end
|
2011-10-22 16:28:41 +01:00
|
|
|
|
2011-12-21 21:42:06 +00:00
|
|
|
def find_build_list
|
|
|
|
@build_list = BuildList.find(params[:id])
|
|
|
|
end
|
2011-10-22 16:28:41 +01:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def find_build_list_by_bs
|
|
|
|
@build_list = BuildList.find_by_bs_id!(params[:id])
|
|
|
|
end
|
2011-04-07 15:56:28 +01:00
|
|
|
|
2011-12-21 21:42:06 +00:00
|
|
|
def authenticate_build_service!
|
|
|
|
if request.remote_ip != APP_CONFIG['build_server_ip']
|
|
|
|
render :nothing => true, :status => 403
|
2011-11-26 00:54:40 +00:00
|
|
|
end
|
2011-12-21 21:42:06 +00:00
|
|
|
end
|
2011-04-22 13:08:58 +01:00
|
|
|
end
|