class Release::Notes::Write

Public Class Methods

new() click to toggle source

Release::Notes::Write initializer

@return none

# File lib/release/notes/write.rb, line 14
def initialize
  new_temp_file_template
end

Public Instance Methods

digest(str) click to toggle source

Write strings to tempfile

@param [String] str - string to add to the temp file

# File lib/release/notes/write.rb, line 23
def digest(str)
  File.open(config_temp_file, "a") { |fi| fi << str }
end
digest_header(header) click to toggle source

Adds formatted header to changelog

@param [String] header - unformatted header that needs to be added to changelog

# File lib/release/notes/write.rb, line 47
def digest_header(header)
  @header = header
  digest(header_present)
end
digest_title(title: nil, log_message: nil) click to toggle source

Formats titles to be added to the new file and removes tags from title if configured

@param [String] title - string representing a label title @param [String] log_message - string containing log messages that fall under the title

@return [String] formatted label title and log messages that fall under it.

# File lib/release/notes/write.rb, line 34
def digest_title(title: nil, log_message: nil)
  @title = title
  @log_message = log_message

  titles = title_present + format_line
  digest(titles)
end
write_new_file() click to toggle source

append old file to new temp file overwrite output file with tmp file

@return none

# File lib/release/notes/write.rb, line 58
def write_new_file
  copy_over_notes if config_release_notes_exist? && !config_force_rewrite?

  FileUtils.cp(config_temp_file, config_output_file)
  FileUtils.rm config_temp_file
end

Private Instance Methods

copy_over_notes() click to toggle source

Appends previous changelog to a temporary file

@return none

# File lib/release/notes/write.rb, line 120
def copy_over_notes
  File.open(config_temp_file, "a") do |f|
    f << NEWLINE
    IO.readlines(config_output_file)[2..-1].each { |line| f << line }
  end
end
format_line() click to toggle source

If prettify_messages is true, remove the label keyword from log message else, just return the log message

@return [String] log message to be added to changelog

# File lib/release/notes/write.rb, line 91
def format_line
  return "#{prettify_linked_messages}#{NEWLINE}" if config_prettify_messages?

  link_messages
end
header_present() click to toggle source

Formats the header

@return [String] formatted header to be added to changelog

# File lib/release/notes/write.rb, line 72
def header_present
  "#{NEWLINE}## #{@header}#{NEWLINE}"
end
new_temp_file_template() click to toggle source

Open temp file and output release notes header

@return none

# File lib/release/notes/write.rb, line 144
def new_temp_file_template
  File.open(config_temp_file, "w") do |fi|
    fi << "# Release Notes#{NEWLINE}"
  end
end
prettify_linked_messages() click to toggle source

Prettifies linked log messages

@return [String] formatted log message

# File lib/release/notes/write.rb, line 111
def prettify_linked_messages
  Prettify.new(line: link_messages).perform
end
title_present() click to toggle source

Formats the title

@return [String] formatted title to be added to changelog

# File lib/release/notes/write.rb, line 81
def title_present
  "#{NEWLINE}#{@title}#{NEWLINE}#{NEWLINE}"
end