Class: Release::Notes::Write

Inherits:
Object
  • Object
show all
Includes:
Configurable, Link
Defined in:
lib/release/notes/write.rb

Instance Method Summary collapse

Constructor Details

#initializeObject

Release::Notes::Write initializer



14
15
16
# File 'lib/release/notes/write.rb', line 14

def initialize
  new_temp_file_template
end

Instance Method Details

#copy_over_notesObject (private)

Appends previous changelog to a temporary file

Returns:

  • none



120
121
122
123
124
125
# 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

#digest(str) ⇒ Object

Write strings to tempfile

Parameters:

  • str (String)
    • string to add to the temp file


23
24
25
# File 'lib/release/notes/write.rb', line 23

def digest(str)
  File.open(config_temp_file, "a") { |fi| fi << str }
end

#digest_header(header) ⇒ Object

Adds formatted header to changelog

Parameters:

  • header (String)
    • unformatted header that needs to be added to changelog


47
48
49
50
# 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) ⇒ String

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

Parameters:

  • title (String) (defaults to: nil)
    • string representing a label title
  • log_message (String) (defaults to: nil)
    • string containing log messages that fall under the title

Returns:

  • (String)

    formatted label title and log messages that fall under it.



34
35
36
37
38
39
40
# 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

#format_lineString (private)

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

Returns:

  • (String)

    log message to be added to changelog



91
92
93
94
95
# File 'lib/release/notes/write.rb', line 91

def format_line
  return "#{prettify_linked_messages}#{NEWLINE}" if config_prettify_messages?

  link_messages
end

#header_presentString (private)

Formats the header

Returns:

  • (String)

    formatted header to be added to changelog



72
73
74
# File 'lib/release/notes/write.rb', line 72

def header_present
  "#{NEWLINE}## #{@header}#{NEWLINE}"
end

Returns the log message if message linking is not configured else, return the linked log_message

Returns:

  • (String)

    original or updated log essage



133
134
135
136
137
# File 'lib/release/notes/write.rb', line 133

def link_message(log_message)
  return log_message unless config_link_commits?

  link_lines(lines: log_message)
end

Calls link_message method with a log message

Returns:

  • (String)

    log message to be added to the changelog



102
103
104
# File 'lib/release/notes/write.rb', line 102

def link_messages
  link_message @log_message
end

#new_temp_file_templateObject (private)

Open temp file and output release notes header

Returns:

  • none



144
145
146
147
148
# 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_messagesString (private)

Prettifies linked log messages

Returns:

  • (String)

    formatted log message



111
112
113
# File 'lib/release/notes/write.rb', line 111

def prettify_linked_messages
  Prettify.new(line: link_messages).perform
end

#title_presentString (private)

Formats the title

Returns:

  • (String)

    formatted title to be added to changelog



81
82
83
# File 'lib/release/notes/write.rb', line 81

def title_present
  "#{NEWLINE}#{@title}#{NEWLINE}#{NEWLINE}"
end

#write_new_fileObject

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

Returns:

  • none



58
59
60
61
62
63
# 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