Class: Omnibus::ChangeLog

Inherits:
Object
  • Object
show all
Defined in:
lib/omnibus/changelog.rb

Constant Summary collapse

CHANGELOG_TAG =
"ChangeLog-Entry".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_ref = nil, end_ref = "HEAD", git_repo = GitRepository.new("./")) ⇒ ChangeLog

Returns a new instance of ChangeLog.



8
9
10
11
12
# File 'lib/omnibus/changelog.rb', line 8

def initialize(start_ref = nil, end_ref = "HEAD", git_repo = GitRepository.new("./"))
  @start_ref = start_ref
  @end_ref = end_ref
  @git_repo = git_repo
end

Instance Attribute Details

#end_refObject (readonly)

Returns the value of attribute end_ref.



7
8
9
# File 'lib/omnibus/changelog.rb', line 7

def end_ref
  @end_ref
end

Instance Method Details

#authorsObject



14
15
16
# File 'lib/omnibus/changelog.rb', line 14

def authors
  git_repo.authors(start_ref, end_ref)
end

#changelog_entriesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omnibus/changelog.rb', line 18

def changelog_entries
  entries = []
  current_entry = []
  git_repo.commit_messages(start_ref, end_ref).each do |l|
    if blank?(l)
      entries << current_entry
      current_entry = []
    elsif tagged?(l)
      entries << current_entry
      current_entry = Array(l.sub(/^#{CHANGELOG_TAG}:[\s]*/, ""))
    elsif !current_entry.empty?
      current_entry << l
    end
  end
  entries << current_entry
  entries.reject(&:empty?).map(&:join)
end

#start_refObject



36
37
38
# File 'lib/omnibus/changelog.rb', line 36

def start_ref
  @start_ref ||= git_repo.latest_tag
end