2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ProjectSetting < ApplicationRecord
|
2022-04-04 11:22:00 +05:30
|
|
|
include IgnorableColumns
|
|
|
|
|
|
|
|
ignore_column :show_diff_preview_in_email, remove_with: '14.10', remove_after: '2022-03-22'
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
belongs_to :project, inverse_of: :project_setting
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
enum squash_option: {
|
|
|
|
never: 0,
|
|
|
|
always: 1,
|
|
|
|
default_on: 2,
|
|
|
|
default_off: 3
|
|
|
|
}, _prefix: 'squash'
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
self.primary_key = :project_id
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
validates :merge_commit_template, length: { maximum: Project::MAX_COMMIT_TEMPLATE_LENGTH }
|
|
|
|
validates :squash_commit_template, length: { maximum: Project::MAX_COMMIT_TEMPLATE_LENGTH }
|
|
|
|
|
|
|
|
default_value_for(:legacy_open_source_license_available) do
|
|
|
|
Feature.enabled?(:legacy_open_source_license_available, default_enabled: :yaml, type: :ops)
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def squash_enabled_by_default?
|
|
|
|
%w[always default_on].include?(squash_option)
|
|
|
|
end
|
|
|
|
|
|
|
|
def squash_readonly?
|
|
|
|
%w[always never].include?(squash_option)
|
|
|
|
end
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
validate :validates_mr_default_target_self
|
|
|
|
|
|
|
|
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-03-13 15:44:24 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
ProjectSetting.prepend_mod
|