class Gitlab::Release::Changelog::Entries

This class is a collection wrapper of changelog items, useful to generate easily changelog as String.

Public Class Methods

new() click to toggle source
# File lib/gitlab/release/changelog/entries.rb, line 8
def initialize
  # @type [Array] elements
  @elements = []
end

Public Instance Methods

push(element) click to toggle source

Add a new Entry element.

@param [Entry] element

# File lib/gitlab/release/changelog/entries.rb, line 18
def push(element)
  @elements.push(element)
end
to_s() click to toggle source

Print the changelog without any reference.

@return [String]

# File lib/gitlab/release/changelog/entries.rb, line 27
def to_s
  internal_to_s_with_reference(false)
end
to_s_with_reference() click to toggle source

Print the changelog with relative reference.

@return [String]

# File lib/gitlab/release/changelog/entries.rb, line 36
def to_s_with_reference
  internal_to_s_with_reference(true)
end
write_in_file(path, appending = false, with_reference = true) click to toggle source

Write the changelog content as String in a file.

@param [String] path Required. path The file path. You can specify a series of file paths with regex. @param [Boolean] appending Optional. Append the changelog contents at the bottom of the file. Default: false @param [Boolean] with_reference Optional. Generate the changelog with MRs and Issues reference. Default true

# File lib/gitlab/release/changelog/entries.rb, line 47
def write_in_file(path, appending = false, with_reference = true)
  # @type [String] changelog_string
  changelog_string = internal_to_s_with_reference(with_reference)

  searched_paths = Dir.glob(path)
  if !searched_paths.empty?
    searched_paths.each do |single_path|
      internal_write_on_file(single_path, changelog_string, appending)
    end
  else
    internal_write_on_file(path, changelog_string, appending)
  end
end

Private Instance Methods

internal_to_s_with_reference(with_reference) click to toggle source
# File lib/gitlab/release/changelog/entries.rb, line 67
        def internal_to_s_with_reference(with_reference)
  @elements.map { |element| element.to_s_for_changelog(with_reference) }
      .join("\n")
end
internal_write_on_file(path, content, appending) click to toggle source
# File lib/gitlab/release/changelog/entries.rb, line 61
        def internal_write_on_file(path, content, appending)
  File.open(path, appending ? "a" : "w+") do |file|
    file.puts(content)
  end
end