Sha256: 2c1840bf8ce210815398c8b17c6bc884fc9c5aea13b791a241dd86bb25adc7be

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "dry/monads"

module Milestoner
  module Commits
    # Enriches commits and associated trailers for final processing.
    class Enricher
      include Import[:input]

      include Enrichers::Import[
        :author,
        :body,
        :collaborators,
        :format,
        :issue,
        :milestone,
        :notes,
        :review,
        :signers,
        :uri
      ]

      include Dry::Monads[:result]

      def initialize(categorizer: Commits::Categorizer.new, model: Models::Commit, **)
        @categorizer = categorizer
        @model = model
        super(**)
        @commands = %i[author body collaborators format issue milestone notes review signers uri]
      end

      def call
        categorizer.call
                   .map { |commit| record_for commit }
                   .then { |commits| Success commits }
      end

      private

      attr_reader :categorizer, :model, :commands

      def record_for(commit) = model.for(commit, **build_attributes(commit))

      def build_attributes commit
        commands.each.with_object({}) do |command, attributes|
          attributes[command] = __send__(command).call commit
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
milestoner-17.0.0 lib/milestoner/commits/enricher.rb