class Circlemator::PrCommenter

Public Class Methods

new(opts) click to toggle source
# File lib/circlemator/pr_commenter.rb, line 6
def initialize(opts)
  github_repo = opts.fetch(:github_repo)
  raise "#{github_repo} is invalid" unless github_repo.is_a? GithubRepo

  @github_repo = github_repo
  @sha = opts.fetch(:sha)
  @opts = opts
end

Public Instance Methods

comment(text) click to toggle source
# File lib/circlemator/pr_commenter.rb, line 15
def comment(text)
  _, pr_url = PrFinder.new(@opts).find_pr
  raise 'PR not found!' unless pr_url

  response = @github_repo.post "#{pr_url}/reviews", body: { commit_id: @sha,
                                                            body: text,
                                                            event: 'COMMENT',
                                                          }.to_json

  if response.code != 200
    body = JSON.parse(response.body)
    raise "PR Comment Failed: #{body.fetch('message')}"
  end
end