Class: Release::Notes::Tag

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag:, writer:, previous_tag:) ⇒ Tag

Release::Notes::Tag initializer

Parameters:

  • tag (String)
    • a git tag (ex: v2.0.0)
  • writer (Release::Notes::Write)
    • an object containing a header, title, and associated log messages
  • previous_tag (String)
    • the previous git tag (ex: v1.3.0)


17
18
19
20
21
22
23
24
# File 'lib/release/notes/tag.rb', line 17

def initialize(tag:, writer:, previous_tag:)
  @tag = tag
  @writer = writer
  @previous_tag = previous_tag

  @_commits = {}
  @_hashes = []
end

Instance Attribute Details

#_hashesObject

Returns the value of attribute _hashes.



7
8
9
# File 'lib/release/notes/tag.rb', line 7

def _hashes
  @_hashes
end

#previous_tagObject (readonly)

Returns the value of attribute previous_tag.



8
9
10
# File 'lib/release/notes/tag.rb', line 8

def previous_tag
  @previous_tag
end

#tagObject (readonly)

Returns the value of attribute tag.



8
9
10
# File 'lib/release/notes/tag.rb', line 8

def tag
  @tag
end

Instance Method Details

#all_labelsArray (private)

Array of strings containing all labels

Returns:

  • (Array)

    array of all labels



128
129
130
# File 'lib/release/notes/tag.rb', line 128

def all_labels
  [config_features, config_bugs, config_misc]
end

#commits_available?Boolean (private)

Are there git sha's with commits?

Returns:

  • (Boolean)

    true: commits are present, false: there are no commits



53
54
55
# File 'lib/release/notes/tag.rb', line 53

def commits_available?
  @_commits.present?
end

#formatted_date(date = nil) ⇒ String (private)

Formats a supplied date

Parameters:

  • date (String) (defaults to: nil)
    • a date

Returns:

  • (String)

    formatted date



64
65
66
# File 'lib/release/notes/tag.rb', line 64

def formatted_date(date = nil)
  DateFormatter.new(date).humanize
end

#headerString (private)

Generate header title

Returns:

  • (String)

    the header to be added to changelog



73
74
75
# File 'lib/release/notes/tag.rb', line 73

def header
  config_header_title_type.yield_self { |t| title(t) } # config_header_title = "tag"
end

#log_commitsHash (private)

Creates new commit objects from the @_commits object

Returns:

  • (Hash)

    unique log messages per tag



82
83
84
85
86
# File 'lib/release/notes/tag.rb', line 82

def log_commits
  @_commits.each do |key, val|
    Commits.new(title: titles[key], value: val, writer: @writer, tagger: self).perform
  end
end

#performObject

Adds log messages to @_commits variable, and if there are commits that need to be added to changelog, add the header and associated log messages

Returns:

  • none



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/release/notes/tag.rb', line 32

def perform
  store_commits # adds to @_commits

  if commits_available? # true
    writer_digest_header(header) # <File:./release-notes.tmp.md (closed)>
    log_commits # hash [0,1,2...], messages for sha
  end

  self
rescue MissingTag => e
  $stderr.puts "<#{e.class.name.demodulize}>: #{e}" # rubocop:disable Style/StderrPuts
  raise
end

#standard_title(title) ⇒ Object (private)



159
160
161
# File 'lib/release/notes/tag.rb', line 159

def standard_title(title)
  title == "tag" ? tag : formatted_date(tag_date)
end

#store_commitsObject (private)

Adds log messages to @_commits

Returns:

  • none



102
103
104
105
106
107
108
109
# File 'lib/release/notes/tag.rb', line 102

def store_commits
  all_labels.each_with_index do |lab, i|
    system_log(label: lab).tap { |str| @_commits[i] = str if str.present? }
  end

  # if log_all = true
  @_commits[all_labels.size] = system_log(log_all: true) if config_log_all
end

#system_log(**opts) ⇒ String (private)

Create new system object that contains log messages between tag_from and tag_to with the relevant options

Parameters:

  • opts (Hash)
    • options like the label to grep

Returns:

  • (String)

    log messages that meet the criteria



119
120
121
# File 'lib/release/notes/tag.rb', line 119

def system_log(**opts)
  System.new({ tag_from: previous_tag, tag_to: tag }.merge(opts)).log
end

#tag_dateString (private)

Transform tag into date

Returns:

  • (String)

    date the tag was created



93
94
95
# File 'lib/release/notes/tag.rb', line 93

def tag_date
  System.tag_date(tag: tag)
end

#title(title) ⇒ String (private)

Title or formatted tag date

tag as the title, if not use the tag date

Parameters:

  • title (String)
    • should the title be the git tag? If yes, use the git

Returns:

  • (String)

    tag title or formatted tag date to be added to changelog

Raises:



150
151
152
153
154
155
156
157
# File 'lib/release/notes/tag.rb', line 150

def title(title)
  return standard_title(title) unless config_update_release_notes_before_tag? && tag == "HEAD"

  formatted_date unless title == "tag"
  return config_newest_tag if config_newest_tag.present?

  raise MissingTag, "No tag version was passed as an option when generating release notes"
end

#titlesArray (private)

Array of strings containing all titles

Returns:

  • (Array)

    array of all titles



137
138
139
140
# File 'lib/release/notes/tag.rb', line 137

def titles
  [config_feature_title, config_bug_title,
   config_misc_title, config_log_all_title]
end