lib/pronto/formatter/github_formatter.rb in pronto-0.2.6 vs lib/pronto/formatter/github_formatter.rb in pronto-0.3.0
- old
+ new
@@ -1,45 +1,32 @@
-require 'octokit'
-
module Pronto
module Formatter
class GithubFormatter
def format(messages, repo)
commit_messages = messages.map do |message|
- github_slug = repo.remotes.map(&:github_slug).compact.first
+ github_slug = repo.github_slug
sha = message.commit_sha
- position = message.line.commit_line.position if message.line
- path = message.path
body = message.msg
+ path = message.path
+ position = message.line.commit_line.position if message.line
- create_comment(github_slug, sha, position, path, body)
+ comment = Github::Comment.new(github_slug, sha, body, path, position)
+ create_comment(github_slug, sha, comment)
end
"#{commit_messages.compact.count} Pronto messages posted to GitHub"
end
private
- def create_comment(repo, sha, position, path, body)
+ def create_comment(repo, sha, comment)
comments = client.commit_comments(repo, sha)
-
- existing_comment = comments.find do |comment|
- comment.position == position &&
- comment.path == path &&
- comment.body == body
- end
-
- unless existing_comment
- client.create_commit_comment(repo, sha, body, path, nil, position)
- end
+ existing = comments.any? { |c| comment == c }
+ client.create_commit_comment(repo, sha, comment) unless existing
end
- def access_token
- ENV['GITHUB_ACCESS_TOKEN']
- end
-
def client
- @client ||= Octokit::Client.new(access_token: access_token)
+ @client ||= Github.new
end
end
end
end