Class: Worklog::Github::Client

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

Overview

Client to interact with GitHub API

Defined Under Namespace

Classes: GithubAPIError

Constant Summary collapse

EVENT_FILTER =
Set.new(%w[
  PullRequestEvent
  PullRequestReviewEvent

]).freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

Returns a new instance of Client.



22
23
24
# File 'lib/github/client.rb', line 22

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#fetch_eventsObject

Fetch events for a given user from Github API



27
28
29
30
31
32
33
# File 'lib/github/client.rb', line 27

def fetch_events
  verify_token!

  WorkLogger.debug 'Fetching most recent GitHub events...'
  responses = fetch_event_pages
  responses.filter_map { |event| create_event(event) }
end

#pull_request_comments(repo, pr_number) ⇒ Object



41
42
43
44
45
# File 'lib/github/client.rb', line 41

def pull_request_comments(repo, pr_number)
  response = HTTParty.get("https://api.github.com/repos/#{repo}/pulls/#{pr_number}/comments",
                          headers: { 'Authorization' => "token #{TOKEN}" })
  response.parsed_response
end

#pull_request_data(repo, pr_number) ⇒ Object



35
36
37
38
39
# File 'lib/github/client.rb', line 35

def pull_request_data(repo, pr_number)
  response = HTTParty.get("https://api.github.com/repos/#{repo}/pulls/#{pr_number}",
                          headers: { 'Authorization' => "token #{TOKEN}" })
  response.parsed_response
end