Class: Ghrt::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/ghrt/github.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo, verbose) ⇒ Github

Returns a new instance of Github.



11
12
13
14
15
16
17
18
# File 'lib/ghrt/github.rb', line 11

def initialize(repo, verbose)
  @repo = repo
  @username = ENV['GITHUB_USERNAME']
  @token = ENV['GITHUB_TOKEN']
  raise 'GITHUB_USERNAME and GITHUB_TOKEN environment variables must be set' unless @username && @token

  @verbose = verbose
end

Instance Method Details

#review_comments(pull_request, since) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ghrt/github.rb', line 20

def review_comments(pull_request, since)
  response = []
  page = 1

  loop do
    paged_response = query_github("/pulls/#{pull_request}/comments?since=#{since}&per_page=100&page=#{page}")
    break if paged_response.empty?

    response.concat(paged_response)
    page += 1
  end

  response.select do |comment|
    comment['user']['login'] == @username &&
    DateTime.parse(comment['created_at']) >= DateTime.parse(since) if since
  end
end