class Unwrappr::Writers::GithubCommitLog

Inform of the number of commits included in the change. Annotate several commits, and link to the Github compare page on which we can see all the commits and file changes.

Implements the `annotation_writer` interface required by the LockFileAnnotator.

Constants

MAX_COMMITS
MAX_MESSAGE
SHA_LENGTH

Public Class Methods

new(gem_change, gem_change_info) click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 20
def initialize(gem_change, gem_change_info)
  @gem_change = gem_change
  @gem_change_info = gem_change_info
end
write(gem_change, gem_change_info) click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 16
def self.write(gem_change, gem_change_info)
  new(gem_change, gem_change_info).write
end

Public Instance Methods

write() click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 25
      def write
        return nil if comparison.nil?

        collapsed_section('Commits', <<~MESSAGE)
          A change of **#{comparison.total_commits}** commits. See the full changes on [the compare page](#{comparison.html_url}).

          #{list_commits_introduction}
          #{commit_messages.join("\n")}
        MESSAGE
      end

Private Instance Methods

collapsed_section(summary, body) click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 60
      def collapsed_section(summary, body)
        <<~MESSAGE
          <details>
          <summary>#{summary}</summary>

          #{body}

          </details>
        MESSAGE
      end
commit_message(commit) click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 50
def commit_message(commit)
  message = commit.commit.message.lines.first.strip
  message = "#{message[0, MAX_MESSAGE]}…" if message.length > MAX_MESSAGE
  "- (#{commit.sha[0, SHA_LENGTH]}) [#{message}](#{commit.html_url})"
end
commit_messages() click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 46
def commit_messages
  comparison.commits.first(MAX_COMMITS).map(&method(:commit_message))
end
comparison() click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 56
def comparison
  @gem_change_info[:github_comparison]
end
list_commits_introduction() click to toggle source
# File lib/unwrappr/writers/github_commit_log.rb, line 38
def list_commits_introduction
  if comparison.commits.length > MAX_COMMITS
    "These are the first #{MAX_COMMITS} commits:"
  else
    'These are the individual commits:'
  end
end