class Pronto::Formatter::GitFormatter
Public Instance Methods
Source
# File lib/pronto/formatter/git_formatter.rb, line 16 def client_module raise NotImplementedError end
Source
# File lib/pronto/formatter/git_formatter.rb, line 4 def format(messages, repo, patches) client = client_module.new(repo) existing = existing_comments(messages, client, repo) comments = new_comments(messages, patches) additions = remove_duplicate_comments(existing, comments) submit_comments(client, additions) approve_pull_request(comments.count, additions.count, client) if defined?(self.approve_pull_request) "#{additions.count} Pronto messages posted to #{pretty_name} (#{existing.count} existing)" end
Source
# File lib/pronto/formatter/git_formatter.rb, line 20 def pretty_name raise NotImplementedError end
Protected Instance Methods
Source
# File lib/pronto/formatter/git_formatter.rb, line 26 def existing_comments(*) raise NotImplementedError end
Source
# File lib/pronto/formatter/git_formatter.rb, line 30 def line_number(*) raise NotImplementedError end
Source
# File lib/pronto/formatter/git_formatter.rb, line 34 def submit_comments(*) raise NotImplementedError end
Private Instance Methods
Source
# File lib/pronto/formatter/git_formatter.rb, line 44 def consolidate_comments(comments) comment = comments.first if comments.length > 1 joined_body = join_comments(comments) Comment.new(comment.sha, joined_body, comment.path, comment.position) else comment end end
Source
# File lib/pronto/formatter/git_formatter.rb, line 54 def dedupe_comments(existing, comments) body = existing.map(&:body).join(' ') comments.reject { |comment| body.include?(comment.body) } end
Source
# File lib/pronto/formatter/git_formatter.rb, line 40 def grouped_comments(comments) comments.group_by { |comment| [comment.path, comment.position] } end
Source
# File lib/pronto/formatter/git_formatter.rb, line 59 def join_comments(comments) comments.map { |comment| "- #{comment.body}" }.join("\n") end
Source
# File lib/pronto/formatter/git_formatter.rb, line 63 def new_comment(message, patches) config.logger.log("Creating a comment from message: #{message.inspect}") sha = message.commit_sha body = config.message_format(self.class.name) % message.to_h path = message.path lineno = line_number(message, patches) if message.line Comment.new(sha, body, path, lineno) end
Source
# File lib/pronto/formatter/git_formatter.rb, line 74 def new_comments(messages, patches) comments = messages .uniq .map { |message| new_comment(message, patches) } grouped_comments(comments) end
Source
# File lib/pronto/formatter/git_formatter.rb, line 81 def remove_duplicate_comments(old_comments, new_comments) new_comments.each_with_object([]) do |(key, comments), memo| existing = old_comments[key] comments = dedupe_comments(existing, comments) if existing if config.consolidate_comments? && !comments.empty? comment = consolidate_comments(comments) memo.push(comment) else memo.concat(comments) end end end