Merge branch 'add-tests' into develop
This commit is contained in:
commit
7c9edcfedb
|
@ -8,6 +8,7 @@ module GitHubChangelogGenerator
|
||||||
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
||||||
class Fetcher
|
class Fetcher
|
||||||
PER_PAGE_NUMBER = 30
|
PER_PAGE_NUMBER = 30
|
||||||
|
CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN"
|
||||||
GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: GitHub API rate limit (5000 per hour) exceeded, change log may be " \
|
GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: GitHub API rate limit (5000 per hour) exceeded, change log may be " \
|
||||||
"missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."
|
"missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ module GitHubChangelogGenerator
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def fetch_github_token
|
def fetch_github_token
|
||||||
env_var = @options[:token] ? @options[:token] : (ENV.fetch "CHANGELOG_GITHUB_TOKEN", nil)
|
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
|
||||||
|
|
||||||
unless env_var
|
unless env_var
|
||||||
@logger.warn "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow
|
@logger.warn "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow
|
||||||
|
|
36
spec/unit/fetcher_spec.rb
Normal file
36
spec/unit/fetcher_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
describe GitHubChangelogGenerator::Fetcher do
|
||||||
|
VALID_TOKEN = "0123456789abcdef"
|
||||||
|
before(:all) do
|
||||||
|
@fetcher = GitHubChangelogGenerator::Fetcher.new
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#fetch_github_token" do
|
||||||
|
token = GitHubChangelogGenerator::Fetcher::CHANGELOG_GITHUB_TOKEN
|
||||||
|
context "when token in ENV exist" do
|
||||||
|
before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) }
|
||||||
|
subject { @fetcher.fetch_github_token }
|
||||||
|
it { is_expected.to eq(VALID_TOKEN) }
|
||||||
|
end
|
||||||
|
context "when token in ENV is nil" do
|
||||||
|
before { stub_const("ENV", ENV.to_hash.merge(token => nil)) }
|
||||||
|
subject { @fetcher.fetch_github_token }
|
||||||
|
it { is_expected.to be_nil }
|
||||||
|
end
|
||||||
|
context "when token in options and ENV is nil" do
|
||||||
|
before do
|
||||||
|
stub_const("ENV", ENV.to_hash.merge(token => nil))
|
||||||
|
@fetcher = GitHubChangelogGenerator::Fetcher.new(token: VALID_TOKEN)
|
||||||
|
end
|
||||||
|
subject { @fetcher.fetch_github_token }
|
||||||
|
it { is_expected.to eq(VALID_TOKEN) }
|
||||||
|
end
|
||||||
|
context "when token in options and ENV specified" do
|
||||||
|
before do
|
||||||
|
stub_const("ENV", ENV.to_hash.merge(token => "no_matter_what"))
|
||||||
|
@fetcher = GitHubChangelogGenerator::Fetcher.new(token: VALID_TOKEN)
|
||||||
|
end
|
||||||
|
subject { @fetcher.fetch_github_token }
|
||||||
|
it { is_expected.to eq(VALID_TOKEN) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user