Class: Whatsnew::RemoteFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsnew/remote_files.rb

Constant Summary collapse

REPO_NOT_FOUND =
Class.new(Exception)
REPO_NOT_FOUND_MESSAGE =
"This repository cannot be found. Specify OAuth token if this is a private repository.".freeze
INVALID_OAUTH_TOKEN =
Class.new(Exception)

Instance Method Summary collapse

Constructor Details

#initialize(repo, access_token = nil) ⇒ RemoteFiles

Returns a new instance of RemoteFiles.



9
10
11
12
13
14
15
16
17
18
# File 'lib/whatsnew/remote_files.rb', line 9

def initialize(repo, access_token = nil)
  @repo = repo
  @token =
    access_token ||
    ENV.fetch("OAUTH_ACCESS_TOKEN") { prints_no_token_warning }

  if token && token.size != 40
    abort "ERROR: OAuth token should be 40-char long.".freeze
  end
end

Instance Method Details

#to_news_fileObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/whatsnew/remote_files.rb', line 20

def to_news_file
  if contents = find_from_contents
    NewsFile.new(contents)
  elsif releases = find_from_releases
    ReleaseFile.new(releases)
  else
    NoNewsFile.new
  end
rescue Octokit::NotFound
  raise REPO_NOT_FOUND, REPO_NOT_FOUND_MESSAGE
rescue Octokit::Unauthorized
  raise INVALID_OAUTH_TOKEN, "ERROR: Your OAuth token: #{token} is invalid or revoked."
end