2020-02-10 12:08:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ProjectSetting < ApplicationRecord
|
2022-05-05 21:09:10 +00:00
|
|
|
ALLOWED_TARGET_PLATFORMS = %w(ios osx tvos watchos android).freeze
|
2022-03-30 00:09:03 +00:00
|
|
|
|
2020-02-10 12:08:59 +00:00
|
|
|
belongs_to :project, inverse_of: :project_setting
|
|
|
|
|
2022-07-18 18:08:47 +00:00
|
|
|
scope :for_projects, ->(projects) { where(project_id: projects) }
|
|
|
|
|
2020-06-30 18:09:13 +00:00
|
|
|
enum squash_option: {
|
|
|
|
never: 0,
|
|
|
|
always: 1,
|
|
|
|
default_on: 2,
|
|
|
|
default_off: 3
|
|
|
|
}, _prefix: 'squash'
|
|
|
|
|
2020-02-10 12:08:59 +00:00
|
|
|
self.primary_key = :project_id
|
2020-06-30 18:09:13 +00:00
|
|
|
|
2022-02-12 21:16:25 +00:00
|
|
|
validates :merge_commit_template, length: { maximum: Project::MAX_COMMIT_TEMPLATE_LENGTH }
|
|
|
|
validates :squash_commit_template, length: { maximum: Project::MAX_COMMIT_TEMPLATE_LENGTH }
|
2022-03-30 00:09:03 +00:00
|
|
|
validates :target_platforms, inclusion: { in: ALLOWED_TARGET_PLATFORMS }
|
|
|
|
|
|
|
|
validate :validates_mr_default_target_self
|
2021-11-11 09:12:21 +00:00
|
|
|
|
2022-02-15 03:13:45 +00:00
|
|
|
default_value_for(:legacy_open_source_license_available) do
|
2022-05-06 15:09:03 +00:00
|
|
|
Feature.enabled?(:legacy_open_source_license_available, type: :ops)
|
2022-02-15 03:13:45 +00:00
|
|
|
end
|
|
|
|
|
2020-06-30 18:09:13 +00:00
|
|
|
def squash_enabled_by_default?
|
|
|
|
%w[always default_on].include?(squash_option)
|
|
|
|
end
|
|
|
|
|
|
|
|
def squash_readonly?
|
|
|
|
%w[always never].include?(squash_option)
|
|
|
|
end
|
2022-01-11 18:16:38 +00:00
|
|
|
|
2022-03-30 00:09:03 +00:00
|
|
|
def target_platforms=(val)
|
|
|
|
super(val&.map(&:to_s)&.sort)
|
|
|
|
end
|
2022-01-11 18:16:38 +00:00
|
|
|
|
2022-04-26 12:09:50 +00:00
|
|
|
def human_squash_option
|
|
|
|
case squash_option
|
|
|
|
when 'never' then 'Do not allow'
|
|
|
|
when 'always' then 'Require'
|
|
|
|
when 'default_on' then 'Encourage'
|
|
|
|
when 'default_off' then 'Allow'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-11 18:16:38 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def validates_mr_default_target_self
|
|
|
|
if mr_default_target_self_changed? && !project.forked?
|
|
|
|
errors.add :mr_default_target_self, _('This setting is allowed for forked projects only')
|
|
|
|
end
|
|
|
|
end
|
2020-02-10 12:08:59 +00:00
|
|
|
end
|
2020-04-15 18:09:36 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
ProjectSetting.prepend_mod
|