Class: RooOnRails::Checks::GitHub::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/roo_on_rails/checks/github/token.rb

Overview

Output context:

  • github.api_client: a connected Octokit client

Instance Method Summary collapse

Methods inherited from Base

#initialize, requires, #run

Methods included from Helpers

#bold, included

Constructor Details

This class inherits a constructor from RooOnRails::Checks::Base

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/roo_on_rails/checks/github/token.rb', line 18

def call
  token = File.exist?(TOKEN_FILE) && File.read(TOKEN_FILE)
  fail! 'no token found' unless token && !token.empty?

  oauth_client = Octokit::Client.new(access_token: token)
  oauth_client.user # idempotent call to check access

  context.github!.api_client = oauth_client
  pass "connected to GitHub's API"
rescue Octokit::Error => e
  fail! "#{e.class}: #{e.message}"
end

#fixObject



31
32
33
34
35
36
37
# File 'lib/roo_on_rails/checks/github/token.rb', line 31

def fix
  token = create_access_token
  FileUtils.mkpath(File.dirname(TOKEN_FILE))
  File.write(TOKEN_FILE, token)
rescue Octokit::Error => e
  final_fail! "#{e.class}: #{e.message}"
end

#introObject



14
15
16
# File 'lib/roo_on_rails/checks/github/token.rb', line 14

def intro
  'Obtaining GitHub auth token...'
end