Sha256: 053c470c3c7aebce38f3f85c95356a46ccbf43aded618e58c84e43c1399227d1

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'git'

module GFSM
  module Tools
    class GitUtilities
      CHANGELOG_TRAILER_REGEX = /^(?<name>Changelog):\s*(?<category>.+)$/i

      def self.load_repo(repo_path)
        Git.open(repo_path)
      end

      def self.extract_last_tag_name(repo)
        begin
          current_sort_order = repo.config("tag.sort")
          repo.fetch(tags: true)

          repo.config("tag.sort", "-v:refname")
          tags = repo.tags
          repo.config("tag.sort", current_sort_order)

          tags[0].name if !tags.empty?
        rescue
        end
      end

      def self.extract_commits_with_changelog_trailer(repo)
        last_tag_name = self.extract_last_tag_name(repo)

        begin
          commits = last_tag_name ? repo.log.between(last_tag_name, 'HEAD') : repo.log
          commits.each_with_object([]) do |commit, memo|
            trailer = commit.message.match(CHANGELOG_TRAILER_REGEX)
            memo << GFSM::Data::Commit.new(commit, trailer[:name], trailer[:category]) if trailer
          end
        rescue
          []
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gfsm-0.3.2 lib/tools/git_utilities.rb