Class: Circlemator::PrCommenter

Inherits:
Object
  • Object
show all
Defined in:
lib/circlemator/pr_commenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ PrCommenter

Returns a new instance of PrCommenter.



6
7
8
9
10
11
12
13
# 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

Instance Method Details

#comment(text) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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