lib/milestoner/commits/collector.rb in milestoner-17.6.0 vs lib/milestoner/commits/collector.rb in milestoner-17.9.0

- old
+ new

@@ -1,17 +1,29 @@ # frozen_string_literal: true +require "dry/monads" + module Milestoner module Commits - # Collects commits since last tag or all commits if untagged. + # Collects commits since last tag, a specific range, or all commits if untagged. class Collector + include Dry::Monads[:result] include Import[:git] - def call = git.tagged? ? latest : all + MIN = :last + MAX = :HEAD + def call(min: MIN, max: MAX) = git.tagged? ? slice(min, max) : all + private - def latest = git.tag_last.bind { |tag| git.commits "#{tag}..HEAD" } + def slice min, max + case [min, max] + in MIN, MAX then git.tag_last.bind { |tag| git.commits "#{tag}..#{max}" } + in String, String then git.commits "#{min}..#{max}" + else Failure "Invalid minimum and/or maximum range: #{min}..#{max}." + end + end def all = git.commits end end end