Sha256: a43be828eaeac8bd35d4f20c658b6a5b063738438ada53bf0401f427dde91b85

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require "git_plus"
require "versionaire"

module Milestoner
  module Tags
    # Handles the creation of project repository tags.
    class Creator
      using Versionaire::Cast

      def initialize categorizer: Commits::Categorizer.new,
                     presenter: Presenters::Commit,
                     container: Container

        @categorizer = categorizer
        @presenter = presenter
        @container = container
      end

      def call configuration = CLI::Configuration::Loader.call
        return false if local? configuration
        fail Error, "Unable to tag without commits." if categorizer.call.empty?

        sign configuration
      rescue Versionaire::Errors::Cast, GitPlus::Error => error
        raise Error, error.message
      end

      private

      attr_reader :categorizer, :presenter, :container

      def local? configuration
        version = Version configuration.git_tag_version

        if repository.tag_local? version
          logger.warn "Local tag exists: #{version}. Skipped."
          true
        else
          false
        end
      end

      def sign configuration
        version = configuration.git_tag_version
        content = message configuration

        if configuration.git_tag_sign
          repository.tag_sign version, content
        else
          repository.tag_unsign version, content
        end

        logger.debug "Local tag created: #{version}."
      end

      def message configuration
        categorizer.call(configuration)
                   .map { |record| presenter.new(record).line_item }
                   .then do |line_items|
                     %(Version #{configuration.git_tag_version}\n\n#{line_items.join "\n"}\n\n)
                   end
      end

      def repository = container[__method__]

      def logger = container[__method__]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
milestoner-12.2.0 lib/milestoner/tags/creator.rb
milestoner-12.1.0 lib/milestoner/tags/creator.rb
milestoner-12.0.4 lib/milestoner/tags/creator.rb
milestoner-12.0.3 lib/milestoner/tags/creator.rb