class Changelog

Central class that puts together the changelog.

Attributes

recent_changes_heading[W]

Heading for the most recent changes.

Public Class Methods

new() click to toggle source
# File lib/changelog.rb, line 24
def initialize
        @recent_changes_heading = "Unpublished changes"
end

Public Instance Methods

generate(exclude_recent = false) click to toggle source

Generates a decorated changelog for the entire commit history.

@param [bool] exclude_recent

Indicates whether to exclude recent changelog lines that were
added since the last tag.

   @return [String]
Decorated changelog, or nil if no lines were found.
# File lib/changelog.rb, line 39
def generate(exclude_recent = false)
        # Traverse tags
        @@tags = TagList.new(!exclude_recent)
        output = String.new
        @@tags.list.each_cons(2) do |current_tag, previous_tag|
                output << generate_for(current_tag, previous_tag)
        end
        output.length > 0 ? output : nil
end
generate_recent() click to toggle source

Generates a simple, undecorated list of changelog entries since the most recent tag.

@return [Array]

Array of changelog lines, or nil if no lines were found.
# File lib/changelog.rb, line 55
def generate_recent
        @@tags = TagList.new
        log = CommitChangelog.new(@@tags.list[0], @@tags.list[1])
        # Explicitly add initial commit if there is no tag yet
        # This is necessary because HEAD..OTHER_COMMIT does not include
        # OTHER_COMMIT's message, which is the desired behavior if
        # OTHER_COMMIT is a tag for a previous version, but undesired
        # if OTHER_COMMIT is the initial commit of the repository.
        log.add_commit @@tags.list[1] if @@tags.list.length == 2
        log.changelog
end

Private Instance Methods

end_separator() click to toggle source

Markdown-compatible horizontal 'ruler'.

@return [String]

# File lib/changelog.rb, line 123
def end_separator
        "\n" + ("* " * 36) +"\n\n\n"
end
generate_for(current_tag, previous_tag) click to toggle source

Generates decorated changelog information including the current_tag's annotation and all changelog lines written in commit messages since the previous_tag. Note that this will exclude previous_tag's annotation, except if previous_tag is not a tag, but the initial commit in the repository.

@param [String] current_tag

Version tag for which to collect changelog information.

   @param [String] previous_tag
Previous version tag whose changelog information does not belong to
the current version's changelog information. However, if previous_tag
is the Sha-1 hash of the initial commit, its changelog lines _will_ be
included.

   @return [String]
Changelog decorated with markdown formatting, or empty string.
# File lib/changelog.rb, line 87
  def generate_for(current_tag, previous_tag)
          tag = Tag.new(current_tag)
          commit_changelog = CommitChangelog.new(current_tag, previous_tag)

          # If previous_tag is the initial commit, make sure to include its message
          commit_changelog.add_commit previous_tag if previous_tag == @@tags.list[-1]

          # Combine changelog entries from tag annotation and commit messages
          if tag.changelog
if commit_changelog.changelog
  combined_changelog = tag.changelog.concat(commit_changelog.changelog)
else
  combined_changelog = tag.changelog
end
          else
                  combined_changelog = commit_changelog.changelog
          end
          combined_changelog.uniq! if combined_changelog

          output = String.new
          tag.heading = @recent_changes_heading unless tag.heading
          if tag.heading and (tag.text or combined_changelog)
                  output << tag.heading + " (#{tag.date})\n"
                  output << "-" * 72 + "\n"
          end
          output << tag.text.join("\n") if tag.text
          output << "\n" if tag.heading or tag.text
          output << combined_changelog.join("\n") + "\n" if combined_changelog
          output << end_separator if tag.text or combined_changelog
          output
  end