Skip to content
Snippets Groups Projects

Allow users to configure skip ci behavior for pipeline execution policy

13 files
+ 220
7
Compare changes
  • Side-by-side
  • Inline
Files
13
@@ -8,9 +8,11 @@ class Config
DEFAULT_SUFFIX_STRATEGY = 'on_conflict'
SUFFIX_STRATEGIES = { on_conflict: 'on_conflict', never: 'never' }.freeze
DEFAULT_SKIP_CI_STRATEGY = { allowed: false }.freeze
POLICY_JOB_SUFFIX = ':policy'
attr_reader :content, :config_strategy, :suffix_strategy, :policy_project_id, :policy_index, :name
attr_reader :content, :config_strategy, :suffix_strategy, :policy_project_id, :policy_index, , :name,
:skip_ci_strategy
def initialize(policy:, policy_project_id:, policy_index:)
@content = policy.fetch(:content).to_yaml
@@ -19,6 +21,7 @@ def initialize(policy:, policy_project_id:, policy_index:)
@config_strategy = policy.fetch(:pipeline_config_strategy).to_sym
@suffix_strategy = policy[:suffix] || DEFAULT_SUFFIX_STRATEGY
@name = policy.fetch(:name)
@skip_ci_strategy = policy[:skip_ci].presence || DEFAULT_SKIP_CI_STRATEGY
end
def strategy_override_project_ci?
@@ -35,6 +38,18 @@ def suffix
def suffix_on_conflict?
suffix_strategy == SUFFIX_STRATEGIES[:on_conflict]
end
def skip_ci_allowed?(user_id)
allowed = skip_ci_strategy[:allowed]
exceptions = skip_ci_strategy[:exceptions]
return allowed if exceptions.blank?
user_excepted = exceptions.any? { |user| user[:id] == user_id }
return !allowed if user_excepted
allowed
end
end
end
end
Loading