class Milestoner::Commits::Tagger

Assembles all commits for a tag.

Attributes

enricher[R]
model[R]

Public Class Methods

new(enricher: Commits::Enricher.new, model: Models::Tag, **) click to toggle source
Calls superclass method
# File lib/milestoner/commits/tagger.rb, line 20
def initialize(enricher: Commits::Enricher.new, model: Models::Tag, **)
  @enricher = enricher
  @model = model
  super(**)
end

Public Instance Methods

call() click to toggle source
# File lib/milestoner/commits/tagger.rb, line 26
def call
  collect.fmap { |tags| tail tags.last(settings.build_max).map(&:version) }
         .fmap { |references| slice(references).reverse }
         .bind { |tags| tags.empty? ? Failure("No tags or commits.") : Success(tags) }
end

Private Instance Methods

add_enrichment(all, *) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 51
      def add_enrichment(all, *) = enrich(*).bind { |entry| all.append entry }

      def enrich min, max
        enricher.call(min:, max:).bind { |commits| build_record git.tag_show(max), commits }
      end

      def build_record result, commits
        result.fmap { |tag| record_for tag, commits }
      rescue Versionaire::Error => error
        logger.error error.message
        Failure error
      end

      def record_for tag, commits
        model[
          author: author(tag),
          commits:,
          committed_at: committed_at(tag.committed_at),
          sha: tag.sha,
          signature: tag.signature,
          version: Version(tag.version || settings.project_version),
        ]
      end

      def placeholder_with_commits = enricher.call.fmap { |commits| placeholder_for commits }

      def placeholder_for commits
        return commits if commits.empty?

        [
          model[
            author: commits.last.author,
            commits:,
            committed_at: Time.now,
            version: settings.project_version
          ]
        ]
      end

      def author tag
        author_enricher.call tag.with(author_name: tag.author_name || settings.project_author)
      end

      def committed_at(at) = at ? Time.at(at.to_i) : settings.loaded_at
    end
  end
end
author(tag) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 90
def author tag
  author_enricher.call tag.with(author_name: tag.author_name || settings.project_author)
end
build_record(result, commits) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 57
def build_record result, commits
  result.fmap { |tag| record_for tag, commits }
rescue Versionaire::Error => error
  logger.error error.message
  Failure error
end
collect(= git.tagged? ? git.tags("--sort=taggerdate") : placeholder_with_commits) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 36
    def collect = git.tagged? ? git.tags("--sort=taggerdate") : placeholder_with_commits

    # :reek:FeatureEnvy
    def tail references
      references.append "HEAD" if settings.build_tail == "head"
      references.prepend nil if references.one?
      references
    end

    def slice references
      references.each_cons(2).with_object [] do |(min, max), entries|
        add_enrichment entries, min, max
      end
    end

    def add_enrichment(all, *) = enrich(*).bind { |entry| all.append entry }

    def enrich min, max
      enricher.call(min:, max:).bind { |commits| build_record git.tag_show(max), commits }
    end

    def build_record result, commits
      result.fmap { |tag| record_for tag, commits }
    rescue Versionaire::Error => error
      logger.error error.message
      Failure error
    end

    def record_for tag, commits
      model[
        author: author(tag),
        commits:,
        committed_at: committed_at(tag.committed_at),
        sha: tag.sha,
        signature: tag.signature,
        version: Version(tag.version || settings.project_version),
      ]
    end

    def placeholder_with_commits = enricher.call.fmap { |commits| placeholder_for commits }

    def placeholder_for commits
      return commits if commits.empty?

      [
        model[
          author: commits.last.author,
          commits:,
          committed_at: Time.now,
          version: settings.project_version
        ]
      ]
    end

    def author tag
      author_enricher.call tag.with(author_name: tag.author_name || settings.project_author)
    end

    def committed_at(at) = at ? Time.at(at.to_i) : settings.loaded_at
  end
end
committed_at(at) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 94
  def committed_at(at) = at ? Time.at(at.to_i) : settings.loaded_at
end
enrich(min, max) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 53
def enrich min, max
  enricher.call(min:, max:).bind { |commits| build_record git.tag_show(max), commits }
end
placeholder_for(commits) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 77
def placeholder_for commits
  return commits if commits.empty?

  [
    model[
      author: commits.last.author,
      commits:,
      committed_at: Time.now,
      version: settings.project_version
    ]
  ]
end
placeholder_with_commits(= enricher.call.fmap { |commits| placeholder_for commits }) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 75
    def placeholder_with_commits = enricher.call.fmap { |commits| placeholder_for commits }

    def placeholder_for commits
      return commits if commits.empty?

      [
        model[
          author: commits.last.author,
          commits:,
          committed_at: Time.now,
          version: settings.project_version
        ]
      ]
    end

    def author tag
      author_enricher.call tag.with(author_name: tag.author_name || settings.project_author)
    end

    def committed_at(at) = at ? Time.at(at.to_i) : settings.loaded_at
  end
end
record_for(tag, commits) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 64
def record_for tag, commits
  model[
    author: author(tag),
    commits:,
    committed_at: committed_at(tag.committed_at),
    sha: tag.sha,
    signature: tag.signature,
    version: Version(tag.version || settings.project_version),
  ]
end
slice(references) click to toggle source
# File lib/milestoner/commits/tagger.rb, line 45
def slice references
  references.each_cons(2).with_object [] do |(min, max), entries|
    add_enrichment entries, min, max
  end
end
tail(references) click to toggle source

:reek: FeatureEnvy

# File lib/milestoner/commits/tagger.rb, line 39
def tail references
  references.append "HEAD" if settings.build_tail == "head"
  references.prepend nil if references.one?
  references
end