lib/pronto/formatter/github_formatter.rb in pronto-0.1.3 vs lib/pronto/formatter/github_formatter.rb in pronto-0.1.4
- old
+ new
@@ -4,32 +4,33 @@
module Formatter
class GithubFormatter
def format(messages)
commit_messages = messages.map do |message|
repo = github_slug(message)
- sha = commit_sha(message)
- position = message.line.position
+ sha = message.line.commit_sha
+ position = message.line.commit_line.position
path = message.path
body = message.msg
- create_commit_comment(repo, sha, position, path, body)
+ create_comment(repo, sha, position, path, body)
end
"#{commit_messages.compact.count} Pronto messages posted to GitHub"
end
private
- def create_commit_comment(repo, sha, position, path, body)
- commit_comments = client.commit_comments(repo, sha)
- existing_comment = commit_comments.find do |comment|
- comment.position = position &&
+ def create_comment(repo, sha, position, path, body)
+ comments = client.commit_comments(repo, sha)
+
+ existing_comment = comments.find do |comment|
+ comment.position == position &&
comment.path == path &&
comment.body == body
end
- if existing_comment.nil?
+ unless existing_comment
client.create_commit_comment(repo, sha, body, path, nil, position)
end
end
def access_token
@@ -40,24 +41,9 @@
@client ||= Octokit::Client.new(access_token: access_token)
end
def github_slug(message)
message.repo.remotes.map(&:github_slug).compact.first
- end
-
- def commit_sha(message)
- blamelines = blame(message).lines
- lineno = message.line.new_lineno
-
- blameline = blamelines.find { |line| line.lineno == lineno }
-
- blameline.commit.id if blameline
- end
-
- def blame(message)
- @blames ||= {}
- @blames[message.path] ||= message.repo.blame(message.path)
- @blames[message.path]
end
end
end
end