Sha256: 0cd23a23967607eb0f2cbbd0687c4d59de937c6cae222b5fd7ce54a6939dc187

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require_relative 'base_policy'
require_relative 'rule_policy'
require_relative '../entity_builders/issue_builder'

module Gitlab
  module Triage
    module Policies
      class SummaryPolicy < BasePolicy
        # Build an issue from several rules policies
        def build_issue
          action = actions[:summarize]

          EntityBuilders::IssueBuilder.new(
            type: type,
            action: action,
            resources: [],
            network: network).tap do |issue|
            issue.items =
              resources.map do |inner_policy_spec, inner_resources|
                Policies::RulePolicy.new(
                  type, inner_policy_spec, inner_resources, network)
                  .build_issue
                  .description
              end.join("\n\n")
          end
        end

        # Due to resources is a different type, this will never work
        # FIXME: We should try to make sure type is consistent for resources
        def comment?
          false
        end

        private

        def attach_resource_type(resources, type)
          resources.each_with_object({}) do |(rule, rule_resources), result|
            result[rule] = super(rule_resources, type)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gitlab-triage-0.16.0 lib/gitlab/triage/policies/summary_policy.rb
gitlab-triage-0.15.0 lib/gitlab/triage/policies/summary_policy.rb