Sha256: 2de048851c4cb3b1f2eeec91b892f594c3cd014e9f137a24282b3b493e6dcf75
Contents?: true
Size: 1.31 KB
Versions: 3
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[:git, :input] using Refinements::Array def initialize(collector: Collector.new, **) @collector = collector super(**) @labels = input.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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
milestoner-17.11.0 | lib/milestoner/commits/categorizer.rb |
milestoner-17.10.0 | lib/milestoner/commits/categorizer.rb |
milestoner-17.9.0 | lib/milestoner/commits/categorizer.rb |