Sha256: 223fa5b5a0d5cab9d7d8c09d67a929749658fa2837508b4e5a1bbb5bfe280c23

Contents?: true

Size: 1.73 KB

Versions: 15

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Gitlab
  module Triage
    module Policies
      class BasePolicy
        InvalidPolicyError = Class.new(StandardError)

        attr_reader :type, :policy_spec, :resources, :network
        attr_accessor :summary

        def initialize(type, policy_spec, resources, network)
          @type = type
          @policy_spec = policy_spec
          @resources = resources
          @network = network
        end

        def validate!
          raise InvalidPolicyError, 'Policies that comment_on_summary must include summarize action' if comment_on_summary? && !summarize?
        end

        def name
          @name ||= (policy_spec[:name] || "#{type}-#{object_id}")
        end

        def source
          case type
          when 'epics'
            'groups'
          else
            'projects'
          end
        end

        def source_id_sym
          case type
          when 'epics'
            :group_id
          else
            :project_id
          end
        end

        def actions
          @actions ||= policy_spec.fetch(:actions) { {} }
        end

        def summarize?
          actions.key?(:summarize)
        end

        def comment_on_summary?
          actions.key?(:comment_on_summary)
        end

        def comment?
          # The actual keys are strings
          (actions.keys.map(&:to_sym) - [:summarize, :comment_on_summary, :delete, :issue]).any?
        end

        def issue?
          actions.key?(:issue)
        end

        def delete?
          actions.key?(:delete) && actions[:delete]
        end

        def build_issue
          raise NotImplementedError
        end

        def build_summary
          raise NotImplementedError
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
gitlab-triage-1.43.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.42.2 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.42.1 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.42.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.41.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.40.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.30.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.29.0 lib/gitlab/triage/policies/base_policy.rb
payping-gitlab-triage-0.1.3 lib/gitlab/triage/policies/base_policy.rb
payping-gitlab-triage-0.1.2 lib/gitlab/triage/policies/base_policy.rb
payping-gitlab-triage-0.1.1 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.28.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.27.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.26.0 lib/gitlab/triage/policies/base_policy.rb
gitlab-triage-1.25.0 lib/gitlab/triage/policies/base_policy.rb