Sha256: 62defe051d98a3b34ab256a437b41013bb0f6e9cf4d9c5c3f8f222b899f1dd10

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 Bytes

Contents

module Pronto
  module Formatter
    class GithubFormatter
      def format(messages, repo)
        messages = messages.uniq { |message| [message.msg, message.line.new_lineno] }
        client = Github.new(repo)

        commit_messages = messages.map do |message|
          sha = message.commit_sha
          body = message.msg
          path = message.path
          position = message.line.commit_line.position if message.line

          create_comment(client, sha, body, path, position)
        end

        "#{commit_messages.compact.count} Pronto messages posted to GitHub"
      end

      private

      def create_comment(client, sha, body, path, position)
        comment = Github::Comment.new(sha, body, path, position)
        comments = client.commit_comments(sha)
        existing = comments.any? { |c| comment == c }
        client.create_commit_comment(comment) unless existing
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pronto-0.4.3 lib/pronto/formatter/github_formatter.rb
pronto-0.4.2 lib/pronto/formatter/github_formatter.rb
pronto-0.4.1 lib/pronto/formatter/github_formatter.rb
pronto-0.4.0 lib/pronto/formatter/github_formatter.rb