Class: Release::Notes::Log

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Log

Returns a new instance of Log.



8
9
10
11
12
13
14
# 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

Instance Method Details

#commits_since_last_tagObject (private)



29
30
31
# 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_allArray (private)

Get all git tags and add to the changelog

Returns:

  • (Array)

    all the git tags



49
50
51
52
53
54
55
# 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_logArray (private)

Find the most recent git tag

Returns:

  • (Array)

    most recent git tag



38
39
40
41
42
# 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) ⇒ String (private)

Second to last tag in the git log

Parameters:

  • index (Integer)
    • index of the git tags array

Returns:

  • (String)

    second most recent git tag



82
83
84
# 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_tagsArray (private)

All tags in the git log

Returns:

  • (Array)

    all git tags



71
72
73
# 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?Boolean (private)

Check whether to start from the beginning of the git log

Returns:

  • (Boolean)

    append to changelog or start from beginning of git log



62
63
64
# File 'lib/release/notes/log.rb', line 62

def log_from_start?
  !config_release_notes_exist? || config_force_rewrite?
end

#performObject

Release::Notes::Log initializer

Returns:

  • none



21
22
23
24
25
# 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

#read_to_head?Boolean (private)

Returns:

  • (Boolean)


86
87
88
# 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) ⇒ String (private)

Get the next git tag or the first tag

Parameters:

  • git_tag (String)
    • a git tag

Returns:

  • (String)

    most recent git tag or the first git tag



97
98
99
# 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) ⇒ Object (private)

Create a Release::Notes::Tag object

Parameters:

  • tag (String)
    • tag to
  • previous_tag (String)
    • tag from

Returns:

  • (Object)

    Release::Notes::Tag object



109
110
111
112
113
114
115
# 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

#writerObject (private)

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

Returns:

  • (Object)

    Release::Notes::Write object



122
123
124
# File 'lib/release/notes/log.rb', line 122

def writer
  @writer ||= Write.new
end