2015-03-26 21:56:47 +00:00
|
|
|
module GitHubChangelogGenerator
|
|
|
|
# A Fetcher responsible for all requests to GitHub and all basic manipulation with related data (such as filtering, validating, e.t.c)
|
2015-03-27 10:02:39 +00:00
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
2015-03-26 21:56:47 +00:00
|
|
|
class Fetcher
|
2015-03-27 10:02:39 +00:00
|
|
|
def initialize(options = {})
|
|
|
|
@options = options
|
|
|
|
|
|
|
|
@user = @options[:user]
|
|
|
|
@project = @options[:project]
|
|
|
|
@github_token = fetch_github_token
|
|
|
|
|
|
|
|
github_options = { per_page: PER_PAGE_NUMBER }
|
|
|
|
github_options[:oauth_token] = @github_token unless @github_token.nil?
|
|
|
|
github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
|
|
|
|
github_options[:site] = options[:github_endpoint] unless options[:github_site].nil?
|
|
|
|
|
|
|
|
begin
|
|
|
|
@github = Github.new github_options
|
|
|
|
rescue
|
|
|
|
puts GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns GitHub token. First try to use variable, provided by --token option, otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def fetch_github_token
|
2015-04-03 15:40:11 +00:00
|
|
|
env_var = @options[:token] ? @options[:token] : (ENV.fetch "CHANGELOG_GITHUB_TOKEN", nil)
|
2015-03-27 10:02:39 +00:00
|
|
|
|
|
|
|
unless env_var
|
2015-04-03 15:40:11 +00:00
|
|
|
puts "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow
|
|
|
|
puts "This script can make only 50 requests to GitHub API per hour without token!".yellow
|
2015-03-27 10:02:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
env_var
|
|
|
|
end
|
2015-03-26 21:56:47 +00:00
|
|
|
end
|
|
|
|
end
|