Sha256: cb93ddfe23f47c4e9a73e251baa691784dff15a28086bcd5795d60fb410545ae

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 Bytes

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
          repo.fetch(nil, {tags: true})
          repo.describe(nil, {tags: true, abbrev: 0})
        rescue => error
          GFSM::Output.error(error.message)
        end
      end

      def self.extract_commits_with_changelog_trailer(repo, from, to = "HEAD")
        begin
          commits = repo.log.between(from, to)
          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.4.0 lib/tools/git_utilities.rb