Sha256: e127bb798bece804241452ccd2543be43a5ce3a679247bda9c5084a757ac31ea

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

# frozen_string_literal: true

require 'git'

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

      def self.extract_commits_with_changelog_trailer(repo_path = ".")
        repo = Git.open(repo_path)

        begin
          last_tag_name = repo.describe(nil, { abbrev: 0 })
        rescue
          last_tag_name = nil
        end

        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

2 entries across 2 versions & 1 rubygems

Version Path
gfsm-0.1.4 lib/tools/commits_extractor.rb
gfsm-0.1.3 lib/tools/commits_extractor.rb