Class: ChangeLogger

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

Instance Method Summary collapse

Constructor Details

#initialize(repo_dir, is_bare = false) ⇒ ChangeLogger

Returns a new instance of ChangeLogger.



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

def initialize(repo_dir, is_bare = false)
  @repo = Grit::Repo.new(repo_dir, :is_bare => is_bare)
end

Instance Method Details

#changelog(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/changelogger.rb', line 11

def changelog(options = {})
  commit_formatter = options[:commit_formatter] || CommitFormatter.new
  commit_filter = options[:commit_filter] || CommitFilter.new
  header_formatter = options[:header_formatter] || HeaderFormatter.new

  tags = @repo.tags

  changelog = ""
  changelog += header_formatter.format(options[:top_version]) unless options[:top_version].nil?

  @repo.commits(@repo.head.name, false).each do |commit|
    tag = tags.find { |t| t.commit.id == commit.id }
    changelog += header_formatter.format(tag.name) unless tag.nil?
    changelog += commit_formatter.format(commit) + "\n" unless !commit_filter.filter(commit)
  end

  changelog
end