Merge branch 'develop' into fetch-refactoring
This commit is contained in:
commit
8a3ff1b799
35
.overcommit.yml
Normal file
35
.overcommit.yml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Use this file to configure the Overcommit hooks you wish to use. This will
|
||||||
|
# extend the default configuration defined in:
|
||||||
|
# https://github.com/brigade/overcommit/blob/master/config/default.yml
|
||||||
|
#
|
||||||
|
# At the topmost level of this YAML file is a key representing type of hook
|
||||||
|
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
||||||
|
# customize each hook, such as whether to only run it on certain files (via
|
||||||
|
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
||||||
|
#
|
||||||
|
# For a complete list of hooks, see:
|
||||||
|
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
|
||||||
|
#
|
||||||
|
# For a complete list of options that you can use to customize hooks, see:
|
||||||
|
# https://github.com/brigade/overcommit#configuration
|
||||||
|
#
|
||||||
|
# Uncomment the following lines to make the configuration take effect.
|
||||||
|
|
||||||
|
PreCommit:
|
||||||
|
Rubocop:
|
||||||
|
enabled: true
|
||||||
|
# on_warn: fail # Treat all warnings as failures
|
||||||
|
#
|
||||||
|
# TrailingWhitespace:
|
||||||
|
# exclude:
|
||||||
|
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
||||||
|
#
|
||||||
|
#PostCheckout:
|
||||||
|
# ALL: # Special hook name that customizes all hooks of this type
|
||||||
|
# quiet: true # Change all post-checkout hooks to only display output on failure
|
||||||
|
#
|
||||||
|
# IndexTags:
|
||||||
|
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
||||||
|
CommitMsg:
|
||||||
|
CapitalizedSubject:
|
||||||
|
enabled: false
|
|
@ -8,21 +8,22 @@ 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."
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
@user = @options[:user]
|
|
||||||
@project = @options[:project]
|
|
||||||
@github_token = fetch_github_token
|
|
||||||
@tag_times_hash = {}
|
|
||||||
|
|
||||||
@logger = Logger.new(STDOUT)
|
@logger = Logger.new(STDOUT)
|
||||||
@logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
@logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
||||||
"#{msg}\n"
|
"#{msg}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@user = @options[:user]
|
||||||
|
@project = @options[:project]
|
||||||
|
@github_token = fetch_github_token
|
||||||
|
@tag_times_hash = {}
|
||||||
github_options = {per_page: PER_PAGE_NUMBER}
|
github_options = {per_page: PER_PAGE_NUMBER}
|
||||||
github_options[:oauth_token] = @github_token unless @github_token.nil?
|
github_options[:oauth_token] = @github_token unless @github_token.nil?
|
||||||
github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
|
github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
|
||||||
|
@ -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