Sha256: 8395ac98d11dd188d9f2df39b91d62fc923fa5b65a551e524976c70fc1e0bf44

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module PrChangelog
  # Calculates a list of not released changes from `base_ref` to `current_ref`
  # those changes consist of the merged pull-request title
  class NotReleasedChanges
    attr_reader :commits_strategy

    def initialize(commits_strategy)
      @commits_strategy = commits_strategy
    end

    def emoji_tags
      tags = {}

      PrChangelog.config.tags.each_with_index do |item, index|
        tags[item[:prefix]] = Tag.new(item[:emoji], item[:title], index)
      end

      tags
    end

    def formatted_changelog
      if parsed_change_list.count.positive?
        parsed_change_list.map(&:to_s).join("\n")
      else
        no_changes_found
      end
    end

    def grouped_formatted_changelog
      if parsed_change_list.count.positive?
        GroupedChanges.new(parsed_change_list, emoji_tags).to_s
      else
        no_changes_found
      end
    end

    private

    def no_changes_found
      'No changes found'
    end

    def parsed_change_list
      @parsed_change_list ||= commits_strategy.parsed_commits.map do |commit_info|
        commits_strategy.format_commit(commit_info)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pr_changelog-0.4.1 lib/pr_changelog/not_released_changes.rb
pr_changelog-0.4.0 lib/pr_changelog/not_released_changes.rb