2011-04-07 14:20:21 +01:00
|
|
|
class BuildList < ActiveRecord::Base
|
2014-03-11 08:58:36 +00:00
|
|
|
include CommitAndVersion
|
|
|
|
include FileStoreClean
|
2012-12-06 14:41:24 +00:00
|
|
|
include AbfWorker::ModelHelper
|
2014-03-11 07:39:25 +00:00
|
|
|
include Feed::BuildList
|
|
|
|
include BuildListObserver
|
|
|
|
include EventLoggable
|
2012-11-06 14:13:16 +00:00
|
|
|
|
2011-04-07 14:20:21 +01:00
|
|
|
belongs_to :project
|
|
|
|
belongs_to :arch
|
2014-01-21 04:51:49 +00:00
|
|
|
belongs_to :save_to_platform, class_name: 'Platform'
|
|
|
|
belongs_to :save_to_repository, class_name: 'Repository'
|
|
|
|
belongs_to :build_for_platform, class_name: 'Platform'
|
2011-12-20 17:09:29 +00:00
|
|
|
belongs_to :user
|
2014-01-21 04:51:49 +00:00
|
|
|
belongs_to :builder, class_name: 'User'
|
|
|
|
belongs_to :publisher, class_name: 'User'
|
2012-05-04 18:12:51 +01:00
|
|
|
belongs_to :advisory
|
2014-02-25 14:54:57 +00:00
|
|
|
belongs_to :mass_build, counter_cache: true, touch: true
|
2014-01-21 04:51:49 +00:00
|
|
|
has_many :items, class_name: '::BuildList::Item', dependent: :destroy
|
|
|
|
has_many :packages, class_name: '::BuildList::Package', dependent: :destroy
|
2014-03-11 12:39:57 +00:00
|
|
|
has_many :source_packages, -> { where(package_type: 'source') }, class_name: '::BuildList::Package'
|
2012-05-04 18:12:51 +01:00
|
|
|
|
2013-05-30 09:49:21 +01:00
|
|
|
UPDATE_TYPES = %w[bugfix security enhancement recommended newpackage]
|
|
|
|
RELEASE_UPDATE_TYPES = %w[bugfix security]
|
2013-11-21 19:49:06 +00:00
|
|
|
EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm]
|
2013-10-17 19:00:15 +01:00
|
|
|
EXTERNAL_NODES = %w[owned everything]
|
2012-05-04 18:12:51 +01:00
|
|
|
|
2014-02-19 21:19:49 +00:00
|
|
|
AUTO_PUBLISH_STATUS_NONE = 'none'
|
|
|
|
AUTO_PUBLISH_STATUS_DEFAULT = 'default'
|
|
|
|
AUTO_PUBLISH_STATUS_TESTING = 'testing'
|
|
|
|
AUTO_PUBLISH_STATUSES = [AUTO_PUBLISH_STATUS_NONE, AUTO_PUBLISH_STATUS_DEFAULT, AUTO_PUBLISH_STATUS_TESTING]
|
|
|
|
|
2012-07-27 17:01:26 +01:00
|
|
|
validates :project_id, :project_version, :arch, :include_repos,
|
2014-01-21 04:51:49 +00:00
|
|
|
:build_for_platform_id, :save_to_platform_id, :save_to_repository_id, presence: true
|
|
|
|
validates_numericality_of :priority, greater_than_or_equal_to: 0
|
2014-03-11 07:39:25 +00:00
|
|
|
validates :external_nodes, inclusion: { in: EXTERNAL_NODES }, allow_blank: true
|
|
|
|
validates :auto_publish_status, inclusion: { in: AUTO_PUBLISH_STATUSES }
|
2014-01-21 04:51:49 +00:00
|
|
|
validates :update_type, inclusion: UPDATE_TYPES,
|
|
|
|
unless: Proc.new { |b| b.advisory.present? }
|
2014-03-11 07:39:25 +00:00
|
|
|
validates :update_type, inclusion: { in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform') },
|
2014-01-21 04:51:49 +00:00
|
|
|
if: Proc.new { |b| b.advisory.present? }
|
2014-03-11 07:39:25 +00:00
|
|
|
validate -> {
|
2013-02-04 09:09:43 +00:00
|
|
|
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.main? && save_to_platform_id != build_for_platform_id
|
2011-10-22 16:28:41 +01:00
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
validate -> {
|
2013-02-04 09:09:43 +00:00
|
|
|
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_build_for_platform')) unless build_for_platform.main?
|
2012-11-20 16:14:51 +00:00
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
validate -> {
|
2013-07-05 09:18:39 +01:00
|
|
|
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) if save_to_repository.platform_id != save_to_platform.id
|
2012-07-30 20:25:57 +01:00
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
validate -> {
|
2014-01-21 04:51:49 +00:00
|
|
|
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos')) if build_for_platform.repositories.where(id: include_repos).count != include_repos.size
|
2012-09-04 13:44:28 +01:00
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
validate -> {
|
2012-12-26 13:06:17 +00:00
|
|
|
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project')) unless save_to_repository.projects.exists?(project_id)
|
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
before_validation -> { self.include_repos = include_repos.uniq if include_repos.present? }, on: :create
|
2014-01-21 04:51:49 +00:00
|
|
|
before_validation :prepare_extra_repositories, on: :create
|
|
|
|
before_validation :prepare_extra_build_lists, on: :create
|
|
|
|
before_validation :prepare_extra_params, on: :create
|
2014-02-20 15:06:07 +00:00
|
|
|
before_validation :prepare_auto_publish_status, on: :create
|
2012-12-26 13:06:17 +00:00
|
|
|
|
2012-12-25 03:09:26 +00:00
|
|
|
attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash,
|
|
|
|
:arch_id, :project_id, :save_to_repository_id, :update_type,
|
2013-05-27 19:13:00 +01:00
|
|
|
:save_to_platform_id, :project_version, :auto_create_container,
|
2013-11-07 15:49:43 +00:00
|
|
|
:extra_repositories, :extra_build_lists, :extra_params, :external_nodes,
|
2014-02-19 21:19:49 +00:00
|
|
|
:include_testing_subrepository, :auto_publish_status
|
2012-05-11 18:44:19 +01:00
|
|
|
|
2013-11-01 17:11:59 +00:00
|
|
|
LIVE_TIME = 4.week # for unpublished
|
|
|
|
MAX_LIVE_TIME = 3.month # for published
|
|
|
|
STATUSES, HUMAN_STATUSES = [], {}
|
|
|
|
[
|
|
|
|
%w(SUCCESS 0),
|
|
|
|
# %w(ERROR 1),
|
|
|
|
# %w(PROJECT_SOURCE_ERROR 6),
|
|
|
|
# %w(DEPENDENCIES_ERROR 555),
|
|
|
|
%w(BUILD_ERROR 666),
|
|
|
|
%w(BUILD_STARTED 3000),
|
|
|
|
%w(BUILD_CANCELED 5000),
|
|
|
|
%w(WAITING_FOR_RESPONSE 4000),
|
|
|
|
%w(BUILD_PENDING 2000),
|
|
|
|
%w(BUILD_PUBLISHED 6000),
|
|
|
|
%w(BUILD_PUBLISH 7000),
|
|
|
|
%w(FAILED_PUBLISH 8000),
|
|
|
|
%w(REJECTED_PUBLISH 9000),
|
|
|
|
%w(BUILD_CANCELING 10000),
|
|
|
|
%w(TESTS_FAILED 11000),
|
|
|
|
%w(BUILD_PUBLISHED_INTO_TESTING 12000),
|
|
|
|
%w(BUILD_PUBLISH_INTO_TESTING 13000),
|
|
|
|
%w(FAILED_PUBLISH_INTO_TESTING 14000)
|
|
|
|
].each do |kind, value|
|
|
|
|
value = value.to_i
|
|
|
|
const_set kind, value
|
|
|
|
STATUSES << value
|
|
|
|
HUMAN_STATUSES[value] = kind.downcase.to_sym
|
|
|
|
end
|
|
|
|
STATUSES.freeze
|
|
|
|
HUMAN_STATUSES.freeze
|
2011-04-07 14:20:21 +01:00
|
|
|
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :recent, -> { order(updated_at: :desc) }
|
|
|
|
scope :for_extra_build_lists, ->(ids, current_ability, save_to_platform) {
|
2014-03-14 21:55:28 +00:00
|
|
|
s = all
|
2014-01-21 04:51:49 +00:00
|
|
|
s = s.where(id: ids).published_container.accessible_by(current_ability, :read)
|
|
|
|
s = s.where(save_to_platform_id: save_to_platform.id) if save_to_platform && save_to_platform.main?
|
2013-06-05 14:48:11 +01:00
|
|
|
s
|
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :for_status, ->(status) { where(status: status) if status.present? }
|
|
|
|
scope :for_user, ->(user) { where(user_id: user.id) }
|
|
|
|
scope :not_owned_external_nodes, -> { where("#{table_name}.external_nodes is null OR #{table_name}.external_nodes != ?", :owned) }
|
|
|
|
scope :external_nodes, ->(type) { where("#{table_name}.external_nodes = ?", type) }
|
|
|
|
scope :oldest, -> { where("#{table_name}.updated_at < ?", Time.zone.now - 15.seconds) }
|
|
|
|
scope :for_platform, ->(platform) { where(build_for_platform_id: platform) }
|
|
|
|
scope :by_mass_build, ->(mass_build) { where(mass_build_id: mass_build) }
|
|
|
|
scope :scoped_to_arch, ->(arch) { where(arch_id: arch) if arch.present? }
|
|
|
|
scope :scoped_to_save_platform, ->(pl_id) { where(save_to_platform_id: pl_id) if pl_id.present? }
|
|
|
|
scope :scoped_to_project_version, ->(pr_version) { where(project_version: pr_version) if pr_version.present? }
|
2014-03-11 09:56:06 +00:00
|
|
|
scope :scoped_to_is_circle, ->(is_circle) { where(is_circle: is_circle) }
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :for_creation_date_period, ->(start_date, end_date) {
|
2014-03-14 21:55:28 +00:00
|
|
|
s = all
|
2013-02-28 15:27:50 +00:00
|
|
|
s = s.where(["#{table_name}.created_at >= ?", start_date]) if start_date
|
|
|
|
s = s.where(["#{table_name}.created_at <= ?", end_date]) if end_date
|
2012-04-13 23:27:24 +01:00
|
|
|
s
|
2011-04-07 14:20:21 +01:00
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :for_notified_date_period, ->(start_date, end_date) {
|
2014-03-14 21:55:28 +00:00
|
|
|
s = all
|
2013-07-04 19:25:07 +01:00
|
|
|
s = s.where("#{table_name}.updated_at >= ?", start_date) if start_date.present?
|
|
|
|
s = s.where("#{table_name}.updated_at <= ?", end_date) if end_date.present?
|
2012-04-13 23:27:24 +01:00
|
|
|
s
|
2011-04-07 14:20:21 +01:00
|
|
|
}
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :scoped_to_project_name, ->(project_name) {
|
|
|
|
joins(:project).where('projects.name LIKE ?', "%#{project_name}%") if project_name.present?
|
|
|
|
}
|
|
|
|
scope :scoped_to_new_core, ->(new_core) { where(new_core: new_core) }
|
|
|
|
scope :outdated, -> {
|
|
|
|
where("#{table_name}.created_at < ? AND #{table_name}.status NOT IN (?) OR #{table_name}.created_at < ?",
|
|
|
|
Time.now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], Time.now - MAX_LIVE_TIME)
|
|
|
|
}
|
|
|
|
scope :published_container, -> { where(container_status: BUILD_PUBLISHED) }
|
2012-05-11 18:44:19 +01:00
|
|
|
|
2011-04-11 11:47:57 +01:00
|
|
|
serialize :additional_repos
|
2011-12-21 14:01:50 +00:00
|
|
|
serialize :include_repos
|
2012-11-27 14:22:17 +00:00
|
|
|
serialize :results, Array
|
2013-02-22 11:04:14 +00:00
|
|
|
serialize :extra_repositories, Array
|
|
|
|
serialize :extra_build_lists, Array
|
2013-09-20 19:21:23 +01:00
|
|
|
serialize :extra_params, Hash
|
2012-05-11 18:44:19 +01:00
|
|
|
|
2014-03-17 20:18:46 +00:00
|
|
|
after_create :place_build
|
2013-01-28 14:44:06 +00:00
|
|
|
after_destroy :remove_container
|
2011-04-11 11:47:57 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
state_machine :status, initial: :waiting_for_response do
|
2012-05-28 18:47:53 +01:00
|
|
|
|
2014-02-10 15:17:09 +00:00
|
|
|
after_transition(on: :place_build) do |build_list, transition|
|
|
|
|
build_list.add_job_to_abf_worker_queue if build_list.external_nodes.blank?
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
after_transition on: :published,
|
|
|
|
do: [:set_version_and_tag, :actualize_packages]
|
|
|
|
after_transition on: :publish, do: :set_publisher
|
|
|
|
after_transition(on: :publish) do |build_list, transition|
|
2014-01-09 22:56:11 +00:00
|
|
|
if transition.from == BUILD_PUBLISHED_INTO_TESTING
|
|
|
|
build_list.cleanup_packages_from_testing
|
|
|
|
end
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
after_transition on: :cancel, do: :cancel_job
|
2012-06-14 14:36:40 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
after_transition on: [:published, :fail_publish, :build_error, :tests_failed], do: :notify_users
|
|
|
|
after_transition on: :build_success, do: :notify_users,
|
2014-03-11 08:58:36 +00:00
|
|
|
unless: ->(build_list) { build_list.auto_publish? || build_list.auto_publish_into_testing? }
|
2012-06-14 14:36:40 +01:00
|
|
|
|
2012-06-01 11:58:17 +01:00
|
|
|
event :place_build do
|
2014-01-21 04:51:49 +00:00
|
|
|
transition waiting_for_response: :build_pending
|
2012-06-01 11:58:17 +01:00
|
|
|
end
|
|
|
|
|
2012-06-13 19:33:23 +01:00
|
|
|
event :start_build do
|
2014-01-21 04:51:49 +00:00
|
|
|
transition build_pending: :build_started
|
2012-06-13 18:24:50 +01:00
|
|
|
end
|
|
|
|
|
2012-05-28 18:47:53 +01:00
|
|
|
event :cancel do
|
2013-01-24 06:33:16 +00:00
|
|
|
transition [:build_pending, :build_started] => :build_canceling
|
2012-12-06 17:34:09 +00:00
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
# build_canceling: :build_canceled - canceling from UI
|
|
|
|
# build_started: :build_canceled - canceling from worker by time-out (time_living has been expired)
|
2012-12-06 17:34:09 +00:00
|
|
|
event :build_canceled do
|
2014-02-21 19:07:27 +00:00
|
|
|
transition [:build_canceling, :build_started, :build_pending] => :build_canceled
|
2012-05-28 18:47:53 +01:00
|
|
|
end
|
|
|
|
|
2012-06-13 18:24:50 +01:00
|
|
|
event :published do
|
|
|
|
transition [:build_publish, :rejected_publish] => :build_published
|
|
|
|
end
|
|
|
|
|
|
|
|
event :fail_publish do
|
|
|
|
transition [:build_publish, :rejected_publish] => :failed_publish
|
|
|
|
end
|
|
|
|
|
2012-05-28 18:47:53 +01:00
|
|
|
event :publish do
|
2013-11-01 17:11:59 +00:00
|
|
|
transition [
|
|
|
|
:success,
|
|
|
|
:failed_publish,
|
|
|
|
:build_published,
|
|
|
|
:tests_failed,
|
|
|
|
:failed_publish_into_testing,
|
|
|
|
:build_published_into_testing
|
|
|
|
] => :build_publish
|
|
|
|
transition [:success, :failed_publish, :failed_publish_into_testing] => :failed_publish
|
2012-05-28 18:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
event :reject_publish do
|
2013-11-01 17:11:59 +00:00
|
|
|
transition [
|
|
|
|
:success,
|
|
|
|
:failed_publish,
|
|
|
|
:tests_failed,
|
|
|
|
:failed_publish_into_testing,
|
|
|
|
:build_published_into_testing
|
|
|
|
] => :rejected_publish
|
|
|
|
end
|
|
|
|
|
|
|
|
# ===== into testing - start
|
|
|
|
|
|
|
|
event :published_into_testing do
|
|
|
|
transition [:build_publish_into_testing, :rejected_publish] => :build_published_into_testing
|
2012-05-28 18:47:53 +01:00
|
|
|
end
|
|
|
|
|
2013-11-01 17:11:59 +00:00
|
|
|
event :fail_publish_into_testing do
|
|
|
|
transition [:build_publish_into_testing, :rejected_publish] => :failed_publish_into_testing
|
|
|
|
end
|
|
|
|
|
|
|
|
event :publish_into_testing do
|
|
|
|
transition [
|
|
|
|
:success,
|
|
|
|
:failed_publish,
|
|
|
|
:tests_failed,
|
|
|
|
:failed_publish_into_testing,
|
|
|
|
:build_published_into_testing
|
|
|
|
] => :build_publish_into_testing
|
|
|
|
transition [:success, :failed_publish, :failed_publish_into_testing] => :failed_publish_into_testing
|
2012-05-28 18:47:53 +01:00
|
|
|
end
|
|
|
|
|
2013-11-01 17:11:59 +00:00
|
|
|
# ===== into testing - end
|
|
|
|
|
2012-06-14 14:36:40 +01:00
|
|
|
event :build_success do
|
2014-03-05 21:44:37 +00:00
|
|
|
transition [:build_started, :build_canceling, :build_canceled] => :success
|
2012-06-13 18:24:50 +01:00
|
|
|
end
|
|
|
|
|
2013-02-06 13:50:49 +00:00
|
|
|
[:build_error, :tests_failed].each do |kind|
|
|
|
|
event kind do
|
2014-03-05 21:44:37 +00:00
|
|
|
transition [:build_started, :build_canceling, :build_canceled] => kind
|
2013-02-06 13:50:49 +00:00
|
|
|
end
|
2013-02-05 18:49:26 +00:00
|
|
|
end
|
|
|
|
|
2012-05-28 18:47:53 +01:00
|
|
|
HUMAN_STATUSES.each do |code,name|
|
2014-01-21 04:51:49 +00:00
|
|
|
state name, value: code
|
2012-05-28 18:47:53 +01:00
|
|
|
end
|
2012-06-18 17:19:09 +01:00
|
|
|
end
|
2012-05-28 18:47:53 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
later :publish, queue: :clone_build
|
2014-02-10 15:17:09 +00:00
|
|
|
later :add_job_to_abf_worker_queue, queue: :clone_build
|
2013-01-28 14:44:06 +00:00
|
|
|
|
|
|
|
HUMAN_CONTAINER_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_publish,
|
|
|
|
BUILD_PUBLISHED => :container_published,
|
|
|
|
BUILD_PUBLISH => :container_publish,
|
|
|
|
FAILED_PUBLISH => :container_failed_publish
|
2013-04-04 12:27:51 +01:00
|
|
|
}.freeze
|
2013-01-28 14:44:06 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
state_machine :container_status, initial: :waiting_for_publish do
|
2013-01-28 14:44:06 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
after_transition on: :publish_container, do: :create_container
|
|
|
|
after_transition on: [:fail_publish_container, :destroy_container],
|
|
|
|
do: :remove_container
|
2013-01-28 14:44:06 +00:00
|
|
|
|
|
|
|
event :publish_container do
|
2013-02-06 13:21:47 +00:00
|
|
|
transition [:waiting_for_publish, :container_failed_publish] => :container_publish,
|
2014-01-21 04:51:49 +00:00
|
|
|
if: :can_create_container?
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
event :published_container do
|
2014-01-21 04:51:49 +00:00
|
|
|
transition container_publish: :container_published
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
event :fail_publish_container do
|
2014-01-21 04:51:49 +00:00
|
|
|
transition container_publish: :container_failed_publish
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
event :destroy_container do
|
2013-01-29 13:17:35 +00:00
|
|
|
transition [:container_failed_publish, :container_published, :waiting_for_publish] => :waiting_for_publish
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
HUMAN_CONTAINER_STATUSES.each do |code,name|
|
2014-01-21 04:51:49 +00:00
|
|
|
state name, value: code
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-18 17:19:09 +01:00
|
|
|
def set_version_and_tag
|
2014-01-21 04:51:49 +00:00
|
|
|
pkg = self.packages.where(package_type: 'source', project_id: self.project_id).first
|
2012-06-27 15:57:30 +01:00
|
|
|
# TODO: remove 'return' after deployment ABF kernel 2.0
|
2012-10-11 11:55:06 +01:00
|
|
|
return if pkg.nil? # For old client that does not sends data about packages
|
2012-06-18 17:19:09 +01:00
|
|
|
self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}"
|
2012-07-17 09:02:56 +01:00
|
|
|
system("cd #{self.project.repo.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit
|
2012-06-18 17:19:09 +01:00
|
|
|
save
|
2012-05-28 18:47:53 +01:00
|
|
|
end
|
|
|
|
|
2012-08-24 16:19:26 +01:00
|
|
|
def actualize_packages
|
|
|
|
ActiveRecord::Base.transaction do
|
2012-12-03 17:43:24 +00:00
|
|
|
# packages from previous build_list
|
2014-01-21 04:51:49 +00:00
|
|
|
self.last_published.limit(2).last.packages.update_all actual: false
|
|
|
|
self.packages.update_all actual: true
|
2012-08-24 16:19:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-28 14:44:06 +00:00
|
|
|
def can_create_container?
|
2013-11-01 17:11:59 +00:00
|
|
|
[SUCCESS, BUILD_PUBLISH, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status)
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
|
|
|
|
2014-01-13 21:51:12 +00:00
|
|
|
def can_publish_into_repository?
|
|
|
|
return true if !save_to_repository.synchronizing_publications? || save_to_platform.personal? || project.architecture_dependent?
|
|
|
|
arch_ids = save_to_platform.platform_arch_settings.by_default.pluck(:arch_id)
|
|
|
|
BuildList.where(
|
2014-01-21 04:51:49 +00:00
|
|
|
project_id: project_id,
|
|
|
|
save_to_repository_id: save_to_repository_id,
|
|
|
|
arch_id: arch_ids,
|
|
|
|
commit_hash: commit_hash,
|
|
|
|
status: [
|
2014-01-13 21:51:12 +00:00
|
|
|
SUCCESS,
|
|
|
|
BUILD_PUBLISHED,
|
|
|
|
BUILD_PUBLISH,
|
|
|
|
FAILED_PUBLISH,
|
|
|
|
TESTS_FAILED,
|
|
|
|
BUILD_PUBLISHED_INTO_TESTING,
|
|
|
|
BUILD_PUBLISH_INTO_TESTING,
|
|
|
|
FAILED_PUBLISH_INTO_TESTING
|
|
|
|
]
|
|
|
|
).group(:arch_id).count == arch_ids.size
|
|
|
|
end
|
|
|
|
|
2012-05-29 18:28:11 +01:00
|
|
|
#TODO: Share this checking on product owner.
|
|
|
|
def can_cancel?
|
2013-01-24 06:33:16 +00:00
|
|
|
build_started? || build_pending?
|
2012-05-29 18:28:11 +01:00
|
|
|
end
|
|
|
|
|
2013-09-16 15:14:55 +01:00
|
|
|
# Comparison between versions of current and last published build_list
|
2013-09-16 17:35:37 +01:00
|
|
|
# @return [Boolean]
|
2013-09-16 15:14:55 +01:00
|
|
|
# - false if no new packages
|
|
|
|
# - false if version of packages is less than version of pubished packages.
|
|
|
|
# - true if version of packages is equal to version of pubished packages (only if platform is not released).
|
|
|
|
# - true if version of packages is greater than version of pubished packages.
|
2013-09-10 14:58:58 +01:00
|
|
|
def has_new_packages?
|
2014-01-21 04:51:49 +00:00
|
|
|
if last_bl = last_published.joins(:source_packages).where(build_list_packages: {actual: true}).last
|
2013-09-09 20:04:56 +01:00
|
|
|
source_packages.each do |nsp|
|
|
|
|
sp = last_bl.source_packages.find{ |sp| nsp.name == sp.name }
|
2013-09-16 15:14:55 +01:00
|
|
|
return true unless sp
|
|
|
|
comparison = nsp.rpmvercmp(sp)
|
|
|
|
return comparison == 1 || (comparison == 0 && !save_to_platform.released?)
|
2013-09-09 19:40:58 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
return true # no published packages
|
|
|
|
end
|
|
|
|
return false # no new packages
|
|
|
|
end
|
|
|
|
|
2014-02-19 21:19:49 +00:00
|
|
|
def auto_publish?
|
|
|
|
auto_publish_status == AUTO_PUBLISH_STATUS_DEFAULT
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_publish_into_testing?
|
|
|
|
auto_publish_status == AUTO_PUBLISH_STATUS_TESTING
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: remove later
|
|
|
|
def auto_publish=(value)
|
|
|
|
self.auto_publish_status = value.present? ? AUTO_PUBLISH_STATUS_DEFAULT : AUTO_PUBLISH_STATUS_NONE
|
|
|
|
end
|
|
|
|
|
2013-09-10 14:58:58 +01:00
|
|
|
def can_auto_publish?
|
2014-01-14 18:42:35 +00:00
|
|
|
auto_publish? && can_publish? && has_new_packages? && can_publish_into_repository?
|
2013-09-10 14:58:58 +01:00
|
|
|
end
|
|
|
|
|
2013-02-22 14:29:22 +00:00
|
|
|
def can_publish?
|
2014-01-21 04:51:49 +00:00
|
|
|
[SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && extra_build_lists_published? && save_to_repository.projects.exists?(id: project_id)
|
2012-06-22 11:33:03 +01:00
|
|
|
end
|
|
|
|
|
2013-02-22 11:04:14 +00:00
|
|
|
def extra_build_lists_published?
|
|
|
|
# All extra build lists should be published before publishing this build list for main platforms!
|
2013-02-22 09:09:37 +00:00
|
|
|
return true unless save_to_platform.main?
|
2014-01-21 04:51:49 +00:00
|
|
|
BuildList.where(id: extra_build_lists).where('status != ?', BUILD_PUBLISHED).count == 0
|
2013-02-22 09:09:37 +00:00
|
|
|
end
|
|
|
|
|
2013-07-31 14:08:43 +01:00
|
|
|
def human_average_build_time
|
2014-01-21 04:51:49 +00:00
|
|
|
I18n.t('layout.project_statistics.human_average_build_time', {hours: (average_build_time/3600).to_i, minutes: (average_build_time%3600/60).to_i})
|
2012-05-29 18:28:11 +01:00
|
|
|
end
|
|
|
|
|
2013-07-31 14:08:43 +01:00
|
|
|
def formatted_average_build_time
|
|
|
|
"%02d:%02d" % [average_build_time / 3600, average_build_time % 3600 / 60]
|
|
|
|
end
|
|
|
|
|
|
|
|
def average_build_time
|
2013-10-03 19:54:11 +01:00
|
|
|
return 0 unless project
|
2014-01-14 18:42:35 +00:00
|
|
|
@average_build_time ||= project.project_statistics.
|
|
|
|
find{ |ps| ps.arch_id == arch_id }.try(:average_build_time) || 0
|
2012-06-01 11:58:17 +01:00
|
|
|
end
|
|
|
|
|
2012-05-11 19:00:27 +01:00
|
|
|
def self.human_status(status)
|
|
|
|
I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}")
|
2011-04-07 14:20:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def human_status
|
|
|
|
self.class.human_status(status)
|
|
|
|
end
|
|
|
|
|
2012-06-29 19:31:40 +01:00
|
|
|
def self.status_by_human(human)
|
2013-01-24 11:32:00 +00:00
|
|
|
HUMAN_STATUSES.key human
|
2012-06-29 19:31:40 +01:00
|
|
|
end
|
|
|
|
|
2011-04-11 11:47:57 +01:00
|
|
|
def set_items(items_hash)
|
|
|
|
self.items = []
|
|
|
|
|
|
|
|
items_hash.each do |level, items|
|
|
|
|
items.each do |item|
|
2014-01-21 04:51:49 +00:00
|
|
|
self.items << self.items.build(name: item['name'], version: item['version'], level: level.to_i)
|
2011-04-11 11:47:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-12-21 23:31:05 +00:00
|
|
|
|
2012-05-17 22:19:57 +01:00
|
|
|
def set_packages(pkg_hash, project_name)
|
2014-03-18 13:58:51 +00:00
|
|
|
prj = Project.joins(repositories: :platform).where('platforms.id = ?', save_to_platform.id).find_by!(name: project_name)
|
2012-05-17 22:19:57 +01:00
|
|
|
build_package(pkg_hash['srpm'], 'source', prj) {|p| p.save!}
|
2012-05-14 20:08:31 +01:00
|
|
|
pkg_hash['rpm'].each do |rpm_hash|
|
2012-05-17 22:19:57 +01:00
|
|
|
build_package(rpm_hash, 'binary', prj) {|p| p.save!}
|
2012-05-14 20:08:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-29 15:50:22 +01:00
|
|
|
def event_log_message
|
2014-01-21 04:51:49 +00:00
|
|
|
{project: project.name, version: project_version, arch: arch.name}.inspect
|
2011-10-29 15:50:22 +01:00
|
|
|
end
|
|
|
|
|
2012-04-12 15:55:32 +01:00
|
|
|
def current_duration
|
2014-03-25 20:36:54 +00:00
|
|
|
if started_at
|
|
|
|
(Time.now.utc - started_at.utc).to_i
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
2012-04-12 15:55:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def human_current_duration
|
2014-01-21 04:51:49 +00:00
|
|
|
I18n.t("layout.build_lists.human_current_duration", {hours: (current_duration/3600).to_i, minutes: (current_duration%3600/60).to_i})
|
2012-04-12 15:55:32 +01:00
|
|
|
end
|
|
|
|
|
2012-04-12 11:29:04 +01:00
|
|
|
def human_duration
|
2014-01-21 04:51:49 +00:00
|
|
|
I18n.t("layout.build_lists.human_duration", {hours: (duration.to_i/3600).to_i, minutes: (duration.to_i%3600/60).to_i})
|
2012-04-12 11:29:04 +01:00
|
|
|
end
|
|
|
|
|
2012-04-13 21:49:29 +01:00
|
|
|
def in_work?
|
2013-01-24 11:32:00 +00:00
|
|
|
status == BUILD_STARTED
|
|
|
|
#[WAITING_FOR_RESPONSE, BUILD_PENDING, BUILD_STARTED].include?(status)
|
2012-04-12 11:29:04 +01:00
|
|
|
end
|
|
|
|
|
2012-10-19 08:32:12 +01:00
|
|
|
def associate_and_create_advisory(params)
|
|
|
|
build_advisory(params){ |a| a.update_type = update_type }
|
|
|
|
advisory.attach_build_list(self)
|
|
|
|
end
|
|
|
|
|
2012-10-19 15:03:09 +01:00
|
|
|
def can_attach_to_advisory?
|
2012-10-19 08:32:12 +01:00
|
|
|
!save_to_repository.publish_without_qa &&
|
2012-10-19 15:03:09 +01:00
|
|
|
save_to_platform.main? &&
|
2012-10-19 08:32:12 +01:00
|
|
|
save_to_platform.released &&
|
2012-11-30 13:10:17 +00:00
|
|
|
build_published?
|
2012-10-18 15:17:50 +01:00
|
|
|
end
|
|
|
|
|
2012-11-29 17:56:03 +00:00
|
|
|
def log(load_lines)
|
2013-01-28 14:44:06 +00:00
|
|
|
new_core? ? abf_worker_log : I18n.t('layout.build_lists.log.not_available')
|
2012-10-18 15:17:50 +01:00
|
|
|
end
|
|
|
|
|
2013-11-18 14:59:12 +00:00
|
|
|
def last_published(testing = false)
|
2014-01-21 04:51:49 +00:00
|
|
|
BuildList.where(project_id: self.project_id,
|
|
|
|
save_to_repository_id: self.save_to_repository_id)
|
2013-01-12 01:36:00 +00:00
|
|
|
.for_platform(self.build_for_platform_id)
|
|
|
|
.scoped_to_arch(self.arch_id)
|
2013-11-18 14:59:12 +00:00
|
|
|
.for_status(testing ? BUILD_PUBLISHED_INTO_TESTING : BUILD_PUBLISHED)
|
2013-01-12 01:36:00 +00:00
|
|
|
.recent
|
|
|
|
end
|
|
|
|
|
2013-02-14 21:49:18 +00:00
|
|
|
def sha1_of_file_store_files
|
|
|
|
packages.pluck(:sha1).compact | (results || []).map{ |r| r['sha1'] }.compact
|
|
|
|
end
|
|
|
|
|
2012-12-06 14:41:24 +00:00
|
|
|
def abf_worker_args
|
2013-02-14 12:50:13 +00:00
|
|
|
repos = include_repos
|
2012-12-06 14:41:24 +00:00
|
|
|
include_repos_hash = {}.tap do |h|
|
2014-01-21 04:51:49 +00:00
|
|
|
Repository.where(id: (repos | (extra_repositories || [])) ).each do |repo|
|
2013-06-26 10:53:37 +01:00
|
|
|
path, prefix = repo.platform.public_downloads_url(
|
2013-05-16 16:25:03 +01:00
|
|
|
repo.platform.main? ? nil : build_for_platform.name,
|
|
|
|
arch.name,
|
|
|
|
repo.name
|
2013-06-26 10:53:37 +01:00
|
|
|
), "#{repo.platform.name}_#{repo.name}_"
|
|
|
|
h["#{prefix}release"] = insert_token_to_path(path + 'release', repo.platform)
|
|
|
|
h["#{prefix}updates"] = insert_token_to_path(path + 'updates', repo.platform) if repo.platform.main?
|
2013-11-07 15:49:43 +00:00
|
|
|
h["#{prefix}testing"] = insert_token_to_path(path + 'testing', repo.platform) if include_testing_subrepository?
|
2012-12-06 14:41:24 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-19 09:42:57 +00:00
|
|
|
host = EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
|
2014-01-21 04:51:49 +00:00
|
|
|
BuildList.where(id: extra_build_lists).each do |bl|
|
2013-05-06 18:40:30 +01:00
|
|
|
path = "#{APP_CONFIG['downloads_url']}/#{bl.save_to_platform.name}/container/"
|
2013-02-19 09:42:57 +00:00
|
|
|
path << "#{bl.id}/#{bl.arch.name}/#{bl.save_to_repository.name}/release"
|
2013-06-26 10:53:37 +01:00
|
|
|
include_repos_hash["container_#{bl.id}"] = insert_token_to_path(path, bl.save_to_platform)
|
2013-02-19 09:42:57 +00:00
|
|
|
end
|
2012-12-06 14:41:24 +00:00
|
|
|
|
2013-05-16 19:50:18 +01:00
|
|
|
git_project_address = project.git_project_address user
|
2013-10-17 19:26:47 +01:00
|
|
|
# git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production?
|
2013-09-20 19:43:03 +01:00
|
|
|
|
|
|
|
cmd_params = {
|
|
|
|
'GIT_PROJECT_ADDRESS' => git_project_address,
|
|
|
|
'COMMIT_HASH' => commit_hash,
|
|
|
|
'EXTRA_CFG_OPTIONS' => extra_params['cfg_options'],
|
2013-11-21 19:49:06 +00:00
|
|
|
'EXTRA_CFG_URPM_OPTIONS' => extra_params['cfg_urpm_options'],
|
2013-09-20 19:43:03 +01:00
|
|
|
'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_rpm'],
|
|
|
|
'EXTRA_BUILD_RPM_OPTIONS' => extra_params['build_rpm']
|
2013-09-20 19:57:52 +01:00
|
|
|
}.map{ |k, v| "#{k}='#{v}'" }.join(' ')
|
2013-09-20 19:43:03 +01:00
|
|
|
|
2012-12-06 14:41:24 +00:00
|
|
|
{
|
2014-01-21 04:51:49 +00:00
|
|
|
id: id,
|
|
|
|
time_living: (build_for_platform.platform_arch_settings.by_arch(arch).first.try(:time_living) || PlatformArchSetting::DEFAULT_TIME_LIVING),
|
|
|
|
distrib_type: build_for_platform.distrib_type,
|
|
|
|
cmd_params: cmd_params,
|
|
|
|
include_repos: include_repos_hash,
|
|
|
|
platform: {
|
|
|
|
type: build_for_platform.distrib_type,
|
|
|
|
name: build_for_platform.name,
|
|
|
|
arch: arch.name
|
2013-08-12 15:26:57 +01:00
|
|
|
},
|
2014-01-21 04:51:49 +00:00
|
|
|
user: {uname: user.uname, email: user.email}
|
2012-12-06 14:41:24 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-01-09 22:56:11 +00:00
|
|
|
def cleanup_packages_from_testing
|
|
|
|
AbfWorker::BuildListsPublishTaskManager.cleanup_packages_from_testing(
|
|
|
|
build_for_platform_id,
|
|
|
|
save_to_repository_id,
|
|
|
|
id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-02-04 22:43:01 +00:00
|
|
|
def self.next_build
|
2014-03-18 21:52:40 +00:00
|
|
|
kind_id = Redis.current.spop(USER_BUILDS_SET)
|
2014-02-26 20:50:39 +00:00
|
|
|
key = "user_build_#{kind_id}_rpm_worker_default" if kind_id
|
|
|
|
task = Resque.pop(key) if key
|
2014-03-18 21:52:40 +00:00
|
|
|
Redis.current.sadd(USER_BUILDS_SET, kind_id) if task
|
2014-02-26 20:50:39 +00:00
|
|
|
|
|
|
|
|
2014-03-18 21:52:40 +00:00
|
|
|
kind_id ||= Redis.current.spop(MASS_BUILDS_SET)
|
2014-02-26 20:50:39 +00:00
|
|
|
key ||= "mass_build_#{kind_id}_rpm_worker" if kind_id
|
|
|
|
task ||= Resque.pop(key) if key
|
2014-03-18 21:52:40 +00:00
|
|
|
Redis.current.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/
|
2014-02-04 22:43:01 +00:00
|
|
|
|
2014-02-21 17:41:52 +00:00
|
|
|
if task
|
|
|
|
build_list = BuildList.where(id: task['args'][0]['id']).first
|
|
|
|
build_list.delayed_add_job_to_abf_worker_queue
|
|
|
|
build_list
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-10 20:14:52 +00:00
|
|
|
def delayed_add_job_to_abf_worker_queue(*args)
|
2014-02-11 17:34:48 +00:00
|
|
|
restart_job if status == BUILD_PENDING
|
2014-02-04 22:43:01 +00:00
|
|
|
end
|
2014-02-10 19:36:10 +00:00
|
|
|
later :delayed_add_job_to_abf_worker_queue, delay: 60, queue: :clone_build
|
2014-02-04 22:43:01 +00:00
|
|
|
|
2012-05-14 20:08:31 +01:00
|
|
|
protected
|
2011-04-11 17:37:09 +01:00
|
|
|
|
2013-01-28 14:44:06 +00:00
|
|
|
def create_container
|
|
|
|
AbfWorker::BuildListsPublishTaskManager.create_container_for self
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_container
|
|
|
|
system "rm -rf #{save_to_platform.path}/container/#{id}" if save_to_platform
|
|
|
|
end
|
|
|
|
|
2012-12-28 14:00:37 +00:00
|
|
|
def abf_worker_priority
|
|
|
|
mass_build_id ? '' : 'default'
|
|
|
|
end
|
|
|
|
|
|
|
|
def abf_worker_base_queue
|
|
|
|
'rpm_worker'
|
|
|
|
end
|
|
|
|
|
2013-06-26 10:53:37 +01:00
|
|
|
def insert_token_to_path(path, platform)
|
|
|
|
if platform.hidden?
|
|
|
|
path.gsub(/^http:\/\//, "http://#{user.authentication_token}:@")
|
|
|
|
else
|
|
|
|
path
|
2012-12-13 12:24:29 +00:00
|
|
|
end
|
2012-12-06 14:41:24 +00:00
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
def notify_users
|
|
|
|
unless mass_build_id
|
2013-08-28 16:20:18 +01:00
|
|
|
users = [user, publisher].compact.uniq.select{ |u| u.notifier.can_notify? && u.notifier.new_build? }
|
|
|
|
|
2013-08-28 16:13:11 +01:00
|
|
|
# find associated users
|
2014-03-19 22:01:42 +00:00
|
|
|
users |= project.all_members(:notifier).select do |u|
|
2013-08-28 16:13:11 +01:00
|
|
|
u.notifier.can_notify? && u.notifier.new_associated_build?
|
|
|
|
end if project
|
|
|
|
users.each{ |u| UserMailer.build_list_notification(self, u).deliver }
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
end # notify_users
|
|
|
|
|
2012-05-17 22:19:57 +01:00
|
|
|
def build_package(pkg_hash, package_type, prj)
|
2012-05-14 20:08:31 +01:00
|
|
|
packages.create(pkg_hash) do |p|
|
2012-05-17 22:19:57 +01:00
|
|
|
p.project = prj
|
2012-05-14 20:08:31 +01:00
|
|
|
p.platform = save_to_platform
|
|
|
|
p.package_type = package_type
|
|
|
|
yield p
|
|
|
|
end
|
|
|
|
end
|
2013-02-04 11:43:42 +00:00
|
|
|
|
2013-03-28 11:58:26 +00:00
|
|
|
def set_publisher
|
|
|
|
self.publisher ||= user
|
|
|
|
save
|
|
|
|
end
|
|
|
|
|
2013-02-19 14:52:02 +00:00
|
|
|
def current_ability
|
|
|
|
@current_ability ||= Ability.new(user)
|
|
|
|
end
|
|
|
|
|
2013-02-21 14:46:52 +00:00
|
|
|
def prepare_extra_repositories
|
|
|
|
if save_to_platform && save_to_platform.main?
|
|
|
|
self.extra_repositories = nil
|
|
|
|
else
|
2013-05-16 15:48:44 +01:00
|
|
|
self.extra_repositories = Repository.joins(:platform).
|
2014-01-21 04:51:49 +00:00
|
|
|
where(id: extra_repositories, platforms: {platform_type: 'personal'}).
|
2013-02-22 10:27:24 +00:00
|
|
|
accessible_by(current_ability, :read).pluck('repositories.id')
|
2013-02-19 10:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-22 11:04:14 +00:00
|
|
|
def prepare_extra_build_lists
|
2013-06-05 14:48:11 +01:00
|
|
|
bls = BuildList.for_extra_build_lists(extra_build_lists, current_ability, save_to_platform)
|
2013-06-04 20:59:08 +01:00
|
|
|
if save_to_platform
|
2013-02-21 15:16:16 +00:00
|
|
|
if save_to_platform.distrib_type == 'rhel'
|
|
|
|
bls = bls.where('
|
|
|
|
(build_lists.arch_id = ? AND projects.publish_i686_into_x86_64 is not true) OR
|
|
|
|
(projects.publish_i686_into_x86_64 is true)
|
|
|
|
', arch_id).joins(:project)
|
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
bls = bls.where(arch_id: arch_id)
|
2013-02-21 15:16:16 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-22 11:04:14 +00:00
|
|
|
self.extra_build_lists = bls.pluck('build_lists.id')
|
2013-02-19 10:06:11 +00:00
|
|
|
end
|
|
|
|
|
2014-02-20 15:06:07 +00:00
|
|
|
def prepare_auto_publish_status
|
|
|
|
if external_nodes.present?
|
|
|
|
self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE
|
|
|
|
end
|
|
|
|
if auto_publish? && !save_to_repository.publish_without_qa?
|
|
|
|
self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE
|
|
|
|
end
|
|
|
|
if auto_publish? || auto_publish_into_testing?
|
|
|
|
self.auto_create_container = false
|
|
|
|
end
|
2014-02-20 15:25:17 +00:00
|
|
|
true
|
2014-02-20 15:06:07 +00:00
|
|
|
end
|
|
|
|
|
2013-09-20 19:21:23 +01:00
|
|
|
def prepare_extra_params
|
|
|
|
if extra_params.present?
|
|
|
|
params = extra_params.slice(*BuildList::EXTRA_PARAMS)
|
|
|
|
params.update(params) do |k,v|
|
|
|
|
v.strip.gsub(I18n.t("activerecord.attributes.build_list.extra_params.#{k}"), '').gsub(/[^\w\s-]/, '')
|
|
|
|
end
|
|
|
|
self.extra_params = params.select{ |k,v| v.present? }
|
|
|
|
end
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
end
|