2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Projects::BuildListsController < Projects::BaseController
|
2011-12-22 00:53:55 +00:00
|
|
|
CALLBACK_ACTIONS = [:publish_build, :status_build, :pre_build, :post_build, :circle_build, :new_bbdt]
|
2012-03-01 17:33:46 +00:00
|
|
|
NESTED_ACTIONS = [:search, :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
|
2012-08-17 09:23:49 +01:00
|
|
|
skip_before_filter :authenticate_user!, :only => [:show, :index, :search, :log] if APP_CONFIG['anonymous_access']
|
2012-04-19 20:45:50 +01:00
|
|
|
|
2012-08-17 09:23:49 +01:00
|
|
|
before_filter :find_build_list, :only => [:show, :publish, :cancel, :update, :log]
|
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
|
|
|
|
2012-03-01 17:33:46 +00:00
|
|
|
def search
|
|
|
|
new_params = {:filter => {}}
|
|
|
|
params[:filter].each do |k,v|
|
|
|
|
new_params[:filter][k] = v unless v.empty?
|
|
|
|
end
|
|
|
|
redirect_to @project ? project_build_lists_path(@project, new_params) : build_lists_path(new_params)
|
|
|
|
end
|
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def index
|
2012-03-01 17:33:46 +00:00
|
|
|
@action_url = @project ? search_project_build_lists_path(@project) : search_build_lists_path
|
|
|
|
@filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
|
2012-08-10 15:09:44 +01:00
|
|
|
|
2012-11-14 17:56:00 +00:00
|
|
|
page = params[:page].to_i == 0 ? nil : params[:page]
|
|
|
|
@bls = @filter.find.recent.paginate :page => page
|
2012-08-10 15:09:44 +01:00
|
|
|
@build_lists = BuildList.where(:id => @bls.pluck("#{BuildList.table_name}.id")).recent
|
|
|
|
@build_lists = @build_lists.includes [:save_to_platform, :save_to_repository, :arch, :user, :project => [:owner]]
|
2011-12-02 01:30:25 +00:00
|
|
|
|
2012-03-01 17:33:46 +00:00
|
|
|
@build_server_status = begin
|
|
|
|
BuildServer.get_status
|
|
|
|
rescue Exception # Timeout::Error
|
|
|
|
{}
|
2011-12-02 01:30:25 +00:00
|
|
|
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
|
2012-05-02 10:18:07 +01:00
|
|
|
# @build_list = BuildList.new # @build_list already created by CanCan
|
2011-12-21 14:01:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
notices, errors = [], []
|
2012-07-27 17:01:26 +01:00
|
|
|
|
2012-09-13 17:08:41 +01:00
|
|
|
@repository = Repository.find params[:build_list][:save_to_repository_id]
|
|
|
|
@platform = @repository.platform
|
2012-08-06 11:59:07 +01:00
|
|
|
|
2012-09-13 17:08:41 +01:00
|
|
|
params[:build_list][:save_to_platform_id] = @platform.id
|
2012-09-06 16:39:26 +01:00
|
|
|
params[:build_list][:auto_publish] = false unless @repository.publish_without_qa?
|
2012-07-27 17:01:26 +01:00
|
|
|
|
2012-09-13 17:08:41 +01:00
|
|
|
|
|
|
|
build_for_platforms = Repository.select(:platform_id).
|
2012-09-13 17:18:09 +01:00
|
|
|
where(:id => params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id)
|
2012-09-13 17:08:41 +01:00
|
|
|
|
2012-12-24 12:35:29 +00:00
|
|
|
new_core = @platform.personal? && params[:build_list][:new_core] == '1'
|
2012-08-06 12:03:10 +01:00
|
|
|
Arch.where(:id => params[:arches]).each do |arch|
|
2012-09-13 17:08:41 +01:00
|
|
|
Platform.main.where(:id => build_for_platforms).each do |build_for_platform|
|
2012-08-06 12:03:10 +01:00
|
|
|
@build_list = @project.build_lists.build(params[:build_list])
|
|
|
|
@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
|
2012-11-29 17:56:03 +00:00
|
|
|
@build_list.new_core = new_core
|
2012-11-29 15:12:24 +00:00
|
|
|
|
2012-08-06 12:03:10 +01:00
|
|
|
flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :build_for_platform => build_for_platform.name}
|
|
|
|
if @build_list.save
|
|
|
|
notices << t("flash.build_list.saved", flash_options)
|
|
|
|
else
|
|
|
|
errors << t("flash.build_list.save_error", flash_options)
|
2011-12-21 14:01:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-06 12:03:10 +01:00
|
|
|
errors << t("flash.build_list.no_arch_or_platform_selected") if errors.blank? and notices.blank?
|
2011-12-21 14:01:50 +00:00
|
|
|
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
|
2012-03-23 11:58:20 +00:00
|
|
|
redirect_to project_build_lists_path(@project)
|
2011-12-21 14:01:50 +00:00
|
|
|
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
|
|
|
|
|
2012-05-04 18:12:51 +01:00
|
|
|
def update
|
2012-05-10 16:15:50 +01:00
|
|
|
if params[:publish].present? and can?(:publish, @build_list)
|
|
|
|
publish
|
2012-05-17 22:19:57 +01:00
|
|
|
elsif params[:reject_publish].present? and can?(:reject_publish, @build_list)
|
2012-05-10 16:15:50 +01:00
|
|
|
reject_publish
|
|
|
|
else
|
|
|
|
# King Arthur, we are under attack!
|
|
|
|
redirect_to :forbidden and return
|
2012-04-17 19:18:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def cancel
|
2012-12-06 17:34:09 +00:00
|
|
|
if @build_list.cancel
|
|
|
|
notice = @build_list.new_core? ?
|
|
|
|
t('layout.build_lists.will_be_canceled') :
|
|
|
|
t('layout.build_lists.cancel_success')
|
2011-12-22 00:53:55 +00:00
|
|
|
else
|
2012-12-06 17:34:09 +00:00
|
|
|
notice = t('layout.build_lists.cancel_fail')
|
2011-12-22 00:53:55 +00:00
|
|
|
end
|
2012-12-06 14:41:24 +00:00
|
|
|
redirect_to :back, :notice => notice
|
2011-12-22 00:53:55 +00:00
|
|
|
end
|
|
|
|
|
2012-08-17 09:23:49 +01:00
|
|
|
def log
|
2012-11-26 18:16:34 +00:00
|
|
|
render :json => {
|
2012-11-29 17:56:03 +00:00
|
|
|
:log => @build_list.log(params[:load_lines]),
|
2012-11-26 18:16:34 +00:00
|
|
|
:building => @build_list.build_started?
|
|
|
|
}
|
2012-08-17 09:23:49 +01:00
|
|
|
end
|
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def publish_build
|
2012-01-13 16:45:13 +00:00
|
|
|
if params[:status].to_i == 0 # ok
|
2012-06-13 18:24:50 +01:00
|
|
|
@build_list.published
|
2012-01-13 16:45:13 +00:00
|
|
|
else
|
2012-06-15 09:47:40 +01:00
|
|
|
@build_list.fail_publish
|
2012-01-13 16:45:13 +00:00
|
|
|
end
|
2011-12-22 00:53:55 +00:00
|
|
|
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.save
|
|
|
|
|
2012-05-17 22:19:57 +01:00
|
|
|
@build_list.set_packages(ActiveSupport::JSON.decode(params[:pkg_info]), params[:package_name]) if params[:status].to_i == BuildServer::SUCCESS and params[:pkg_info].present?
|
2012-05-14 20:08:31 +01:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def pre_build
|
2012-06-13 19:33:23 +01:00
|
|
|
@build_list.start_build
|
2011-12-22 00:53:55 +00:00
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_build
|
2012-06-15 17:05:55 +01:00
|
|
|
params[:status].to_i == BuildServer::SUCCESS ? @build_list.build_success : @build_list.build_error
|
2011-12-22 00:53:55 +00:00
|
|
|
@build_list.container_path = params[:container_path]
|
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
2012-01-25 22:28:11 +00:00
|
|
|
|
2012-06-16 23:51:02 +01:00
|
|
|
@build_list.publish if @build_list.auto_publish # && @build_list.can_publish? # later with resque
|
2011-12-22 00:53:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def circle_build
|
|
|
|
@build_list.is_circle = true
|
|
|
|
@build_list.container_path = params[:container_path]
|
|
|
|
@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]
|
|
|
|
@build_list.save
|
|
|
|
|
|
|
|
render :nothing => true, :status => 200
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
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
|
2012-05-04 18:12:51 +01:00
|
|
|
|
|
|
|
def publish
|
|
|
|
@build_list.update_type = params[:build_list][:update_type] if params[:build_list][:update_type].present?
|
2012-06-04 20:49:20 +01:00
|
|
|
|
|
|
|
if params[:attach_advisory].present? and params[:attach_advisory] != 'no' and !@build_list.advisory
|
2012-07-06 00:05:47 +01:00
|
|
|
|
|
|
|
unless @build_list.update_type.in? BuildList::RELEASE_UPDATE_TYPES
|
|
|
|
redirect_to :back, :notice => t('lyout.build_lists.publish_fail') and return
|
|
|
|
end
|
|
|
|
|
2012-06-04 20:49:20 +01:00
|
|
|
if params[:attach_advisory] == 'new'
|
|
|
|
# create new advisory
|
2012-10-19 08:32:12 +01:00
|
|
|
unless @build_list.associate_and_create_advisory(params[:build_list][:advisory])
|
2012-06-04 20:49:20 +01:00
|
|
|
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# attach existing advisory
|
2012-10-19 08:32:12 +01:00
|
|
|
a = Advisory.where(:advisory_id => params[:attach_advisory]).first
|
|
|
|
unless (a && a.attach_build_list(@build_list))
|
2012-06-04 20:49:20 +01:00
|
|
|
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
|
|
|
|
end
|
|
|
|
end
|
2012-07-06 00:05:47 +01:00
|
|
|
|
2012-05-04 18:12:51 +01:00
|
|
|
end
|
2012-07-06 00:05:47 +01:00
|
|
|
|
2012-06-16 19:27:46 +01:00
|
|
|
if @build_list.save and @build_list.now_publish
|
2012-05-04 18:12:51 +01:00
|
|
|
redirect_to :back, :notice => t('layout.build_lists.publish_success')
|
|
|
|
else
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.publish_fail')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reject_publish
|
|
|
|
if @build_list.reject_publish
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.reject_publish_success')
|
|
|
|
else
|
|
|
|
redirect_to :back, :notice => t('layout.build_lists.reject_publish_fail')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-22 13:08:58 +01:00
|
|
|
end
|