Class: LockDiff::Github::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/lock_diff/github/client.rb', line 14

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

Instance Method Details

#add_comment(repository, number, comment) ⇒ Object



55
56
57
# File 'lib/lock_diff/github/client.rb', line 55

def add_comment(repository, number, comment)
  @client.add_comment(repository, number, comment)
end

#contents(repository, options = {}) ⇒ Object



43
44
45
46
47
48
# File 'lib/lock_diff/github/client.rb', line 43

def contents(repository, options = {})
  return [] unless repository
  @client.contents(repository, options).map do |content|
    Content.new(content)
  end
end

#exist_releases?(repository) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/lock_diff/github/client.rb', line 38

def exist_releases?(repository)
  return false unless repository
  @client.releases(repository).empty?
end

#file(repository, path:, ref:) ⇒ Object



18
19
20
21
# File 'lib/lock_diff/github/client.rb', line 18

def file(repository, path:, ref:)
  content = @client.contents(repository, path: path, ref: ref)
  Base64.decode64(content.content)
end

#newer_pull_requests(repository) ⇒ Object



27
28
29
30
# File 'lib/lock_diff/github/client.rb', line 27

def newer_pull_requests(repository)
  @client.pull_requests(repository).
    map { |pull_request| Github::PullRequest.new(pull_request) }
end

#pull_request(repository, number) ⇒ Object



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

def pull_request(repository, number)
  Github::PullRequest.new(@client.pull_request(repository, number))
end

#pull_request_content_path(repository, number, file_name) ⇒ Object



32
33
34
35
36
# File 'lib/lock_diff/github/client.rb', line 32

def pull_request_content_path(repository, number, file_name)
  content = @client.pull_request_files(repository, number).
    find { |file| file.filename.include?(file_name) }
  content&.filename
end

#tag_names(repository, options = {}) ⇒ Object



50
51
52
53
# File 'lib/lock_diff/github/client.rb', line 50

def tag_names(repository, options = {})
  return [] unless repository
  @client.tags(repository, options).map(&:name)
end