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.



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

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#fetch_eventsObject

Fetch events for a given user from Github API



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

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



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

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



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

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