Merge branch 'develop'

This commit is contained in:
Petr Korolev 2015-05-18 16:05:18 +03:00
commit 0b04797171
5 changed files with 108 additions and 34 deletions

36
.overcommit.yml Normal file
View File

@ -0,0 +1,36 @@
# 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
#command: ['bundle', 'exec', 'rubocop']
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

View File

@ -1,9 +1,9 @@
source "https://rubygems.org"
gem "rake"
gem "rake", ">=10.4.2"
gem "github_api"
gem "colorize"
gem "github_api", ">=0.12.3"
gem "colorize", ">=0.7.7"
group :test do
gem "rspec"

View File

@ -1,24 +1,24 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.7)
addressable (2.3.8)
ast (2.0.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
codeclimate-test-reporter (0.4.7)
simplecov (>= 0.7.1, < 1.0.0)
colorize (0.7.5)
coveralls (0.7.12)
multi_json (~> 1.10)
colorize (0.7.7)
coveralls (0.8.1)
json (~> 1.8)
rest-client (>= 1.6.8, < 2)
simplecov (~> 0.9.1)
simplecov (~> 0.10.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.23)
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
@ -30,11 +30,12 @@ GEM
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.3)
oauth2
hashie (3.4.0)
hashie (3.4.1)
http-cookie (1.0.2)
domain_name (~> 0.5)
jwt (1.4.1)
mime-types (2.4.3)
json (1.8.2)
jwt (1.5.0)
mime-types (2.5)
mini_portile (0.6.2)
multi_json (1.11.0)
multi_xml (0.5.5)
@ -48,10 +49,10 @@ GEM
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
parser (2.2.0.3)
parser (2.2.2.2)
ast (>= 1.1, < 3.0)
powerpack (0.1.0)
rack (1.6.0)
powerpack (0.1.1)
rack (1.6.1)
rainbow (2.0.0)
rake (10.4.2)
rest-client (1.8.0)
@ -62,45 +63,45 @@ GEM
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.2)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
rspec-expectations (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-mocks (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
rubocop (0.29.1)
rubocop (0.31.0)
astrolabe (~> 1.3)
parser (>= 2.2.0.1, < 3.0)
parser (>= 2.2.2.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.5)
simplecov (0.9.2)
simplecov (0.10.0)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.9.0)
simplecov-html (0.9.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
thread_safe (0.3.5)
tins (1.3.5)
tins (1.5.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.6)
unf_ext (0.0.7.1)
PLATFORMS
ruby
DEPENDENCIES
codeclimate-test-reporter
colorize
colorize (>= 0.7.7)
coveralls
github_api
rake
github_api (>= 0.12.3)
rake (>= 10.4.2)
rspec
rubocop
simplecov

View File

@ -8,21 +8,22 @@ module GitHubChangelogGenerator
# fetcher = GitHubChangelogGenerator::Fetcher.new options
class Fetcher
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 " \
"missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."
def initialize(options = {})
@options = options
@user = @options[:user]
@project = @options[:project]
@github_token = fetch_github_token
@tag_times_hash = {}
@logger = Logger.new(STDOUT)
@logger.formatter = proc do |_severity, _datetime, _progname, msg|
"#{msg}\n"
end
@user = @options[:user]
@project = @options[:project]
@github_token = fetch_github_token
@tag_times_hash = {}
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?
@ -40,7 +41,7 @@ module GitHubChangelogGenerator
#
# @return [String]
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
@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
View 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