Sha256: c49fad5a6b1885706f8d26ca7d6c15e6883ab546c12c0b7e3e78dba9b32658d5

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "core"
require "dry/monads"

module Milestoner
  module Tags
    # Handles the creation of project repository tags.
    class Creator
      include Import[:git, :logger]
      include Dry::Monads[:result]

      def initialize(
        collector: Commits::Collector.new,
        builder: Builders::Stream.new(io: StringIO.new),
        **
      )
        @collector = collector
        @builder = builder
        super(**)
      end

      def call version
        return Success version if local? version

        collect.bind { create version }
      end

      private

      attr_reader :collector, :builder

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

      def collect = collector.call.alt_map { |message| message.sub("fatal: y", "Y").sub("\n", ".") }

      def create(version) = build(version).bind { |body| git.tag_create version, body }

      def build(version) = builder.call.fmap { |body| "Version #{version}\n\n#{body}\n\n" }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
milestoner-18.11.0 lib/milestoner/tags/creator.rb
milestoner-18.10.0 lib/milestoner/tags/creator.rb
milestoner-18.9.0 lib/milestoner/tags/creator.rb
milestoner-18.8.0 lib/milestoner/tags/creator.rb
milestoner-18.7.0 lib/milestoner/tags/creator.rb
milestoner-18.6.0 lib/milestoner/tags/creator.rb
milestoner-18.5.0 lib/milestoner/tags/creator.rb
milestoner-18.4.0 lib/milestoner/tags/creator.rb
milestoner-18.3.0 lib/milestoner/tags/creator.rb
milestoner-18.2.0 lib/milestoner/tags/creator.rb