Class: PrNotifier::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/pr-notifier/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:) ⇒ Github

Returns a new instance of Github.



23
24
25
# File 'lib/pr-notifier/github.rb', line 23

def initialize(access_token:)
  @client = Octokit::Client.new(access_token: access_token)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



21
22
23
# File 'lib/pr-notifier/github.rb', line 21

def client
  @client
end

Instance Method Details

#fetch_prs_by(repo) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pr-notifier/github.rb', line 27

def fetch_prs_by(repo)
  prs = client.pull_requests(repo, { state: "open" })
  prs.map do |pr|
    PullRequest.new(
      repo: repo,
      repo_url: pr.head.repo.html_url,
      url: pr.html_url,
      title: pr.title,
      body: pr.body,
      reviewers: pr.requested_reviewers.map { |reviewer| reviewer[:login] },
      assignees: pr.assignees.map { |assignee| assignee[:login] },
      creator: pr.user[:login],
      created_at: pr.created_at,
    )
  end                                                      
end