Sha256: 90b69e0afce0dd7704285447cbd63a007e1dc9ea583335a078a47661bc8c1bfb

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 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(**)
      end

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

      private

      attr_reader :categorizer, :model

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
milestoner-17.6.0 lib/milestoner/commits/enricher.rb
milestoner-17.5.0 lib/milestoner/commits/enricher.rb
milestoner-17.3.0 lib/milestoner/commits/enricher.rb
milestoner-17.2.0 lib/milestoner/commits/enricher.rb
milestoner-17.1.0 lib/milestoner/commits/enricher.rb