module Release::Notes::Link

Public Instance Methods

replace(line, issue_number, label, index) click to toggle source

Replace log messages with linked messages

@param [String] line - log message to replace @param [String] issue_number - word to replace @param [String] label - label to replace with @param [Integer] index - index of the linked site

@return [String] formatted linked line

# File lib/release/notes/link.rb, line 97
def replace(line, issue_number, label, index)
  identifier = "#{label.split(/\s/)[0]} #{issue_number}"
  humanized = "#{config_link_to_humanize[index]} #{issue_number}"
  linked = "[#{humanized}](#{config_link_to_sites[index]}#{issue_number.tr('^0-9', '')})"

  line.gsub! identifier, linked
  line
end
replace_lines(line, label, index) click to toggle source

Replace a word in the changelog

@param [String line - a line from the log messages @param [String] label - a specified label @param [Integer] index - index of log message

@return none

# File lib/release/notes/link.rb, line 67
def replace_lines(line, label, index)
  replace_words(line.split(/\s/))
  @new_lines += "#{replace(line, @word, label, index)}#{NEWLINE}" if @word
end
replace_words(words) click to toggle source

Replace words if log message

@param [Array] words - split git log message

@return [String] word to replace in the log message

# File lib/release/notes/link.rb, line 79
def replace_words(words)
  words.each do |word|
    next unless (word =~ /^#.*/)&.zero?

    @word = word
  end
end
split_lines(lines) click to toggle source

Format lines or add link if log message should be linked

@param [String] lines - log messages for a given git commit

@return [Array] label log messages should be linked to

# File lib/release/notes/link.rb, line 33
def split_lines(lines)
  lines.split(NEWLINE).each do |line|
    unless config_link_to_labels&.any? { |la| line.include? la }
      @new_lines += "#{line}#{NEWLINE}"
      next
    end
    split_words(line)
  end
end
split_words(line) click to toggle source

Determine if log message has a pre-determined label

@param [String] line - a line from the log messages

@return none

# File lib/release/notes/link.rb, line 50
def split_words(line)
  config_link_to_labels.each_with_index do |label, i|
    next unless line.include? label

    replace_lines(line, label, i)
  end
end