Class: GFSM::Tools::GitUtilities

Inherits:
Object
  • Object
show all
Defined in:
lib/tools/git_utilities.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.extract_commits_with_changelog_trailer(repo, from, to = "HEAD") ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tools/git_utilities.rb', line 22

def self.extract_commits_with_changelog_trailer(repo, from, to = "HEAD")
  begin
    commits = from.nil? ? repo.log : 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

.extract_last_tag_name(repo) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/tools/git_utilities.rb', line 14

def self.extract_last_tag_name(repo)
  begin
    repo.fetch(nil, {tags: true})
    repo.describe(nil, {tags: true, abbrev: 0})
  rescue
  end
end

.load_repo(repo_path) ⇒ Object



10
11
12
# File 'lib/tools/git_utilities.rb', line 10

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