Sha256: 39a2b6da9da8cebf49f0d2e975b20e65c846012c1a08629746e1b50d56ca7eb4
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true require "core" require "refinements/array" module Milestoner module Commits # Retrieves and categorizes Git repository commit tagged or untagged history. class Categorizer include Import[:settings] using Refinements::Array def initialize(collector: Collector.new, **) super(**) @collector = collector @labels = settings.commit_categories.pluck :label @pattern = labels.empty? ? // : Regexp.union(labels) end def call min: Collector::MIN, max: Collector::MAX collect(min, max).each_value { |commits| commits.sort_by!(&:subject) } .values .flatten end private attr_reader :collector, :labels, :pattern def collect min, max collector.call(min:, max:) .value_or(Core::EMPTY_ARRAY) .each .with_object categories do |commit, collection| category = commit.subject[pattern] key = collection.key?(category) ? category : "Unknown" collection[key] << commit end end def categories labels.reduce({}) { |group, prefix| group.merge prefix => [] } .merge! "Unknown" => [] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
milestoner-18.12.0 | lib/milestoner/commits/categorizer.rb |