class ConventionalChangelog::Writer

Public Class Methods

new(file_name) click to toggle source
Calls superclass method
# File lib/conventional_changelog/writer.rb, line 19
def initialize(file_name)
  FileUtils.touch file_name
  super file_name, 'r+'

  @new_body = StringIO.new
  @previous_body = read
end

Public Instance Methods

write!(options) click to toggle source
# File lib/conventional_changelog/writer.rb, line 27
def write!(options)
  build_new_lines options
  seek 0
  write @new_body.string
  write @previous_body
end

Private Instance Methods

append_changes(commits, type, title) click to toggle source
# File lib/conventional_changelog/writer.rb, line 49
def append_changes(commits, type, title)
  unless (type_commits = commits.select { |commit| commit[:type] == type }).empty?
    @new_body.puts "#### #{title}", ""
    type_commits.group_by { |commit| commit[:component] }.each do |component, component_commits|
      @new_body.puts "* **#{component}**" if component
      component_commits.each { |commit| write_commit commit, component }
      @new_body.puts ""
    end
    @new_body.puts ""
  end
end
commits() click to toggle source
# File lib/conventional_changelog/writer.rb, line 45
def commits
  @commits ||= Git.commits filter_key => last_id
end
last_id() click to toggle source
# File lib/conventional_changelog/writer.rb, line 73
def last_id
  return nil if @previous_body.to_s.length == 0
  matches = @previous_body.split("\n")[0].to_s.match(/"(.*)"/)

  if matches
    matches[1]
  elsif manually_set_id = ENV['CONVENTIONAL_CHANGELOG_LAST_RELEASE']
    manually_set_id
  else
    raise LastReleaseNotFound.new
  end
end
version_header(id) click to toggle source
# File lib/conventional_changelog/writer.rb, line 36
    def version_header(id)
      <<-HEADER
<a name="#{id}"></a>
### #{version_header_title(id)}


      HEADER
    end
write_commit(commit, componentized) click to toggle source
# File lib/conventional_changelog/writer.rb, line 61
def write_commit(commit, componentized)
  @new_body.puts "#{componentized ? '  ' : ''}* #{commit[:change]} ([#{commit[:id]}](/../../commit/#{commit[:id]}))"
end
write_section(commits, id) click to toggle source
# File lib/conventional_changelog/writer.rb, line 65
def write_section(commits, id)
  return if commits.empty?

  @new_body.puts version_header(id)
  append_changes commits, "feat", "Features"
  append_changes commits, "fix", "Bug Fixes"
end