Sha256: 41488b1970cb5c175d27562bb61542c8bdf35fe9f2ccb5e4530bcf998296d9a9

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 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, { :tags => true, :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.3.0 lib/tools/commits_extractor.rb
gfsm-0.2.0 lib/tools/commits_extractor.rb