Class: Blakey::Source::Github

Inherits:
Base
  • Object
show all
Defined in:
lib/blakey/source/github.rb

Constant Summary collapse

VULNERABILITY_ALERTS_PREVIEW_HEADER =
'application/vnd.github.dorian-preview+json'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token: nil, repo_path: nil) ⇒ Github

Returns a new instance of Github.



9
10
11
12
13
# File 'lib/blakey/source/github.rb', line 9

def initialize(access_token: nil, repo_path: nil)
  @access_token = (access_token || ENV['BLAKEY_SOURCE_GITHUB_ACCESS_TOKEN'])
  @octokit_client ||= ::Octokit::Client.new(access_token: @access_token)
  @repo_path = repo_path
end

Instance Attribute Details

#repo_pathObject (readonly)

Returns the value of attribute repo_path.



15
16
17
# File 'lib/blakey/source/github.rb', line 15

def repo_path
  @repo_path
end

Instance Method Details

#read_file(file_path) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/blakey/source/github.rb', line 17

def read_file(file_path)
  begin
    encoded_file_content = octokit_client.contents(repo_path, path: file_path).content
  rescue Octokit::NotFound => e
    raise FileNotFound.new(e)
  end

  Base64.decode64(encoded_file_content).chomp
end

#repository_overviewObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/blakey/source/github.rb', line 27

def repository_overview
  {
    open_issues_count: repository.open_issues_count,
    open_pull_requests_count: open_pull_requests_count,
    language: repository.language,
    visibility: repository.private? ? 'private' : 'public',
    url: repository.html_url,
    updated_at: repository.updated_at,
    created_at: repository.created_at,
    last_pushed_at: repository.pushed_at,
    vulnerability_alerts_enabled: vulnerability_alerts_enabled?
  }
end