2012-05-02 10:18:07 +01:00
|
|
|
class Projects::BuildListsController < Projects::BaseController
|
2013-08-27 16:43:30 +01:00
|
|
|
include FileStoreHelper
|
2014-11-05 13:57:20 +00:00
|
|
|
include BuildListsHelper
|
2013-08-21 12:00:22 +01:00
|
|
|
|
2015-04-23 07:39:39 +01:00
|
|
|
NESTED_ACTIONS = [:index, :new, :create, :list]
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
|
|
|
skip_before_action :authenticate_user!, only: [:show, :index, :log] if APP_CONFIG['anonymous_access']
|
2012-04-19 20:45:50 +01:00
|
|
|
|
2015-04-03 23:29:07 +01:00
|
|
|
before_action :load_build_list, except: NESTED_ACTIONS
|
2011-10-28 18:55:40 +01:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :create_from_build_list, only: :new
|
2012-03-01 17:33:46 +00:00
|
|
|
|
2011-12-22 00:53:55 +00:00
|
|
|
def index
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize :build_list
|
2013-08-01 23:24:33 +01:00
|
|
|
params[:filter].each{|k,v| params[:filter].delete(k) if v.blank? } if params[:filter]
|
2012-08-10 15:09:44 +01:00
|
|
|
|
2013-08-02 19:13:41 +01:00
|
|
|
respond_to do |format|
|
2016-05-04 16:49:30 +01:00
|
|
|
format.html
|
2013-08-02 19:13:41 +01:00
|
|
|
format.json do
|
2015-03-26 00:26:24 +00:00
|
|
|
@filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
|
2014-05-26 18:42:27 +01:00
|
|
|
params[:page] = params[:page].to_i == 0 ? nil : params[:page]
|
|
|
|
params[:per_page] = if BuildList::Filter::PER_PAGE.include? params[:per_page].to_i
|
|
|
|
params[:per_page].to_i
|
|
|
|
else
|
|
|
|
BuildList::Filter::PER_PAGE.first
|
|
|
|
end
|
|
|
|
@bls_count = @filter.find.count
|
|
|
|
@bls = @filter.find.recent.paginate(page: params[:page], per_page: params[:per_page])
|
2014-01-21 04:51:49 +00:00
|
|
|
@build_lists = BuildList.where(id: @bls.pluck(:id)).recent
|
2014-05-26 18:42:27 +01:00
|
|
|
.includes(:save_to_platform,
|
|
|
|
:save_to_repository,
|
|
|
|
:build_for_platform,
|
|
|
|
:user,
|
|
|
|
:source_packages,
|
|
|
|
project: :project_statistics)
|
2013-08-01 23:42:20 +01:00
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
#@build_server_status = AbfWorkerStatusPresenter.new.projects_status
|
2013-08-02 19:13:41 +01:00
|
|
|
end
|
2013-08-01 23:24:33 +01: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
|
2015-04-03 23:29:07 +01:00
|
|
|
authorize @build_list = @project.build_lists.build
|
2013-08-05 19:34:42 +01:00
|
|
|
if params[:show] == 'inline' && params[:build_list_id].present?
|
2014-11-05 13:57:20 +00:00
|
|
|
render json: new_build_list_data(@build_list, @project, params), layout: false
|
2013-08-05 19:34:42 +01:00
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
2011-12-21 14:01:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
notices, errors = [], []
|
2012-07-27 17:01:26 +01:00
|
|
|
|
2015-04-27 23:14:49 +01:00
|
|
|
@repository = Repository.find build_list_params[:save_to_repository_id]
|
|
|
|
@platform = @repository.platform
|
2012-08-06 11:59:07 +01:00
|
|
|
|
2015-04-27 23:14:49 +01:00
|
|
|
build_lists = []
|
|
|
|
build_for_platforms = Platform.joins(:repositories).where(repositories: { id: build_list_params[:include_repos] }).uniq
|
2014-01-21 04:51:49 +00:00
|
|
|
Arch.where(id: params[:arches]).each do |arch|
|
2015-04-27 23:14:49 +01:00
|
|
|
build_for_platforms.find_each do |build_for_platform|
|
|
|
|
@build_list = @project.build_lists.build(build_list_params)
|
|
|
|
@build_list.save_to_platform = @platform
|
|
|
|
@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
|
2014-05-26 18:42:27 +01:00
|
|
|
flash_options = { project_version: @build_list.project_version, arch: arch.name, build_for_platform: build_for_platform.name }
|
2015-04-03 23:29:07 +01:00
|
|
|
authorize @build_list
|
|
|
|
if @build_list.save
|
2013-08-29 18:46:11 +01:00
|
|
|
build_lists << @build_list
|
2014-05-26 18:42:27 +01:00
|
|
|
notices << t('flash.build_list.saved', flash_options)
|
2012-08-06 12:03:10 +01:00
|
|
|
else
|
2014-05-26 18:42:27 +01:00
|
|
|
errors << t('flash.build_list.save_error', flash_options)
|
2011-12-21 14:01:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-05-26 18:42:27 +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
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :new
|
2011-12-21 14:01:50 +00:00
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
BuildList.where(id: build_lists.map(&:id)).update_all(group_id: build_lists[0].id) if build_lists.size > 1
|
2011-12-21 14:01:50 +00:00
|
|
|
flash[:notice] = notices.join('<br>').html_safe
|
2016-05-04 16:58:34 +01:00
|
|
|
redirect_to project_build_lists_path(@project.name_with_owner)
|
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 publish
|
2013-03-28 11:58:26 +00:00
|
|
|
@build_list.publisher = current_user
|
2014-05-21 23:58:13 +01:00
|
|
|
do_and_back(:publish, 'publish_')
|
2012-05-04 18:12:51 +01:00
|
|
|
end
|
|
|
|
|
2014-07-23 19:02:51 +01:00
|
|
|
def dependent_projects
|
|
|
|
if request.post?
|
|
|
|
prs = params[:build_list]
|
|
|
|
if prs.present? && prs[:projects].present? && prs[:arches].present?
|
|
|
|
project_ids = prs[:projects].select{ |k, v| v == '1' }.keys
|
|
|
|
arch_ids = prs[:arches]. select{ |k, v| v == '1' }.keys
|
2016-05-28 19:21:02 +01:00
|
|
|
#FIX
|
|
|
|
# enqueue(
|
|
|
|
# BuildLists::DependentPackagesJob,
|
|
|
|
# @build_list.id,
|
|
|
|
# current_user.id,
|
|
|
|
# project_ids,
|
|
|
|
# arch_ids,
|
|
|
|
# {
|
|
|
|
# auto_publish_status: prs[:auto_publish_status],
|
|
|
|
# auto_create_container: prs[:auto_create_container],
|
|
|
|
# include_testing_subrepository: prs[:include_testing_subrepository],
|
|
|
|
# use_cached_chroot: prs[:use_cached_chroot],
|
|
|
|
# use_extra_tests: prs[:use_extra_tests]
|
|
|
|
# }
|
|
|
|
# )
|
2014-07-23 19:02:51 +01:00
|
|
|
flash[:notice] = t('flash.build_list.dependent_projects_job_added_to_queue')
|
|
|
|
redirect_to build_list_path(@build_list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-01 17:11:59 +00:00
|
|
|
def publish_into_testing
|
|
|
|
@build_list.publisher = current_user
|
2014-05-21 23:58:13 +01:00
|
|
|
do_and_back(:publish_into_testing, 'publish_')
|
|
|
|
end
|
|
|
|
|
|
|
|
def rerun_tests
|
|
|
|
do_and_back(:rerun_tests, 'rerun_tests_')
|
2012-05-04 18:12:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def reject_publish
|
2013-05-30 10:54:07 +01:00
|
|
|
@build_list.publisher = current_user
|
2014-05-21 23:58:13 +01:00
|
|
|
do_and_back(:reject_publish, 'reject_publish_')
|
2012-05-04 18:12:51 +01:00
|
|
|
end
|
2013-06-10 12:26:12 +01:00
|
|
|
|
|
|
|
def create_container
|
2014-05-21 23:58:13 +01:00
|
|
|
do_and_back(:publish_container, 'create_container_')
|
2013-06-10 12:26:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
2014-05-21 23:58:13 +01:00
|
|
|
do_and_back(:cancel, nil, 'will_be_canceled', 'cancel_fail')
|
2013-06-10 12:26:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def log
|
2014-01-21 04:51:49 +00:00
|
|
|
render json: {
|
2015-07-14 17:33:12 +01:00
|
|
|
log: @build_list.log,
|
2014-01-21 04:51:49 +00:00
|
|
|
building: @build_list.build_started?
|
2013-06-10 12:26:12 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2015-04-27 23:14:49 +01:00
|
|
|
def build_list_params
|
2015-04-28 23:28:36 +01:00
|
|
|
subject_params(BuildList)
|
2015-04-27 23:14:49 +01:00
|
|
|
end
|
|
|
|
|
2015-04-03 23:29:07 +01:00
|
|
|
# Private: before_action hook which loads BuidList.
|
|
|
|
def load_build_list
|
|
|
|
authorize @build_list =
|
|
|
|
if @project
|
|
|
|
@project.build_lists
|
|
|
|
else
|
|
|
|
BuildList
|
|
|
|
end.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2014-05-21 23:58:13 +01:00
|
|
|
def do_and_back(action, prefix, success = 'success', fail = 'fail')
|
2014-05-28 22:08:29 +01:00
|
|
|
result = @build_list.send("can_#{action}?") && @build_list.send(action)
|
2014-05-21 23:58:13 +01:00
|
|
|
message = result ? success : fail
|
|
|
|
flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}")
|
|
|
|
redirect_to :back
|
|
|
|
end
|
|
|
|
|
2013-08-03 04:58:45 +01:00
|
|
|
def create_from_build_list
|
2013-08-05 12:21:30 +01:00
|
|
|
return if params[:build_list_id].blank?
|
2014-04-07 22:54:12 +01:00
|
|
|
build_list = @project.build_lists.find(params[:build_list_id])
|
2015-06-02 19:28:35 +01:00
|
|
|
params[:build_list] = build_list.attributes
|
|
|
|
params[:arches] = [build_list.arch_id]
|
2013-08-01 18:18:46 +01:00
|
|
|
[:owner_filter, :status_filter].each { |t| params[t] = 'true' if %w(true undefined).exclude? params[t] }
|
2012-05-04 18:12:51 +01:00
|
|
|
end
|
2011-04-22 13:08:58 +01:00
|
|
|
end
|