class Release::Notes::Log

Public Class Methods

new(opts = {}) click to toggle source
# File lib/release/notes/log.rb, line 8
def initialize(opts = {})
  Release::Notes.configure do |c|
    c.set_instance_var(:newest_tag, opts["tag"])
    c.set_instance_var(:force_rewrite, opts["rewrite"])
    c.set_instance_var(:ignore_head, opts["ignore-head"])
  end
end

Public Instance Methods

perform() click to toggle source

Release::Notes::Log initializer

@return none

# File lib/release/notes/log.rb, line 21
def perform
  log_from_start? ? find_all_tags_and_log_all : find_last_tag_and_log

  writer.write_new_file
end

Private Instance Methods

commits_since_last_tag() click to toggle source
# File lib/release/notes/log.rb, line 29
def commits_since_last_tag
  tag_logger("HEAD", find_previous_tag(0))
end
find_all_tags_and_log_all() click to toggle source

Get all git tags and add to the changelog

@return [Array] all the git tags

# File lib/release/notes/log.rb, line 49
def find_all_tags_and_log_all
  git_all_tags.each_with_index do |ta, i|
    tag_logger(ta, find_previous_tag(i + 1))
  end

  commits_since_last_tag if read_to_head?
end
find_last_tag_and_log() click to toggle source

Find the most recent git tag

@return [Array] most recent git tag

# File lib/release/notes/log.rb, line 38
def find_last_tag_and_log
  return commits_since_last_tag if read_to_head?

  tag_logger(System.last_tag.strip, find_previous_tag(1))
end
find_previous_tag(idx) click to toggle source

Second to last tag in the git log

@param [Integer] index - index of the git tags array

@return [String] second most recent git tag

# File lib/release/notes/log.rb, line 82
def find_previous_tag(idx)
  git_all_tags[idx].yield_self { |t| tag(t) }.strip
end
git_all_tags() click to toggle source

All tags in the git log

@return [Array] all git tags

# File lib/release/notes/log.rb, line 71
def git_all_tags
  @git_all_tags ||= System.all_tags.split(NEWLINE).reverse
end
log_from_start?() click to toggle source

Check whether to start from the beginning of the git log

@return [Boolean] append to changelog or start from beginning of git log

# File lib/release/notes/log.rb, line 62
def log_from_start?
  !config_release_notes_exist? || config_force_rewrite?
end
read_to_head?() click to toggle source
# File lib/release/notes/log.rb, line 86
def read_to_head?
  config_update_release_notes_before_tag? && !config_ignore_head?
end
tag(git_tag) click to toggle source

Get the next git tag or the first tag

@param [String] git_tag - a git tag

@return [String] most recent git tag or the first git tag

# File lib/release/notes/log.rb, line 97
def tag(git_tag)
  git_tag.present? ? git_tag : System.first_commit
end
tag_logger(tag, previous_tag) click to toggle source

Create a Release::Notes::Tag object

@param [String] tag - tag to @param [String] previous_tag - tag from

@return [Object] Release::Notes::Tag object

# File lib/release/notes/log.rb, line 109
def tag_logger(tag, previous_tag)
  Tag.new(
    tag: tag,
    previous_tag: previous_tag,
    writer: writer,
  ).perform
end
writer() click to toggle source

Create write object containing the header, title, and log messages for a given tag

@return [Object] Release::Notes::Write object

# File lib/release/notes/log.rb, line 122
def writer
  @writer ||= Write.new
end