Class: Pronto::Formatter::GithubPullRequestFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/formatter/github_pull_request_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(messages, repo) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pronto/formatter/github_pull_request_formatter.rb', line 4

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

  commit_messages = messages.map do |message|
    body = message.msg
    path = message.path

    commits = repo.commits_until(message.commit_sha)

    line = nil
    sha = commits.find do |commit|
      patches = repo.show_commit(commit)
      line = patches.find_line(message.full_path, message.line.new_lineno)
      line
    end

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

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