Class: ConventionalChangelog::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/conventional_changelog/git.rb

Constant Summary collapse

DELIMITER =
"/////"

Class Method Summary collapse

Class Method Details

.commits(options) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/conventional_changelog/git.rb', line 7

def self.commits(options)
  log(options).split("\n").map { |commit| commit.split DELIMITER }.select { |commit| options[:since_date].nil? or commit[1] > options[:since_date] }.map do |commit|
    comment = commit[2].match(/(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)/)
    next unless comment
    { id: commit[0], date: commit[1], type: comment[1], component: comment[3], change: comment[4] }
  end.compact
end

.log(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/conventional_changelog/git.rb', line 15

def self.log(options)
  output, status = Open3.capture2(%Q{
    git log \
      --pretty=format:"%h#{DELIMITER}%ad#{DELIMITER}%s%x09" --date=short \
      --grep="^(feat|fix)(\\(.*\\))?:" -E \
      #{version_filter(options)}
  })

  if status.success?
    output
  else
    raise "Can't load Git commits, check your arguments"
  end
end

.version_filter(options) ⇒ Object



30
31
32
# File 'lib/conventional_changelog/git.rb', line 30

def self.version_filter(options)
  options[:since_version] ? "#{options[:since_version]}..HEAD" : ""
end