From 6448de26fab3012b95ca4d17e56e2e1e36a383f0 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Thu, 14 May 2015 15:57:05 +0300 Subject: [PATCH 1/9] update gemfile --- Gemfile | 6 +++--- Gemfile.lock | 51 ++++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index 81abda6..380384e 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 1287b76..ed27b31 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 From 7b356bf01a712633e5ebc17864d55e8a170a54ee Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Thu, 14 May 2015 15:57:31 +0300 Subject: [PATCH 2/9] add tests for fetching token --- lib/github_changelog_generator/fetcher.rb | 3 ++- spec/unit/fetcher_spec.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 spec/unit/fetcher_spec.rb diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 54533e5..2793bc8 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -8,6 +8,7 @@ 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." @@ -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 diff --git a/spec/unit/fetcher_spec.rb b/spec/unit/fetcher_spec.rb new file mode 100644 index 0000000..6c08d25 --- /dev/null +++ b/spec/unit/fetcher_spec.rb @@ -0,0 +1,19 @@ +describe GitHubChangelogGenerator::Fetcher do + 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 => "0123456789abcdef")) } + subject { @fetcher.fetch_github_token } + it { is_expected.to eq("0123456789abcdef") } + 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 + end +end From 50ba2695fbf64753e9ba8be6cff05ab4e162c8b4 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 11:40:32 +0300 Subject: [PATCH 3/9] add test for token in options --- spec/unit/fetcher_spec.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/unit/fetcher_spec.rb b/spec/unit/fetcher_spec.rb index 6c08d25..709563f 100644 --- a/spec/unit/fetcher_spec.rb +++ b/spec/unit/fetcher_spec.rb @@ -1,4 +1,5 @@ describe GitHubChangelogGenerator::Fetcher do + VALID_TOKEN = "0123456789abcdef" before(:all) do @fetcher = GitHubChangelogGenerator::Fetcher.new end @@ -6,14 +7,30 @@ describe GitHubChangelogGenerator::Fetcher do 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 => "0123456789abcdef")) } + before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) } subject { @fetcher.fetch_github_token } - it { is_expected.to eq("0123456789abcdef") } + 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 From 0ff48a3dba71dea2b4da0b65f276da4f2801ad2a Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 12:00:08 +0300 Subject: [PATCH 4/9] Fix #235 --- lib/github_changelog_generator/fetcher.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 54533e5..201223b 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -14,14 +14,15 @@ module GitHubChangelogGenerator def initialize(options = {}) @options = options + @logger = Logger.new(STDOUT) + @logger.formatter = proc do |_severity, _datetime, _progname, msg| + "#{msg}\n" + @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 github_options = { per_page: PER_PAGE_NUMBER } github_options[:oauth_token] = @github_token unless @github_token.nil? From bbeebf7e28f1860ac342b17e8cf82515c5b105c1 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 12:15:42 +0300 Subject: [PATCH 5/9] fx --- lib/github_changelog_generator/fetcher.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 7f8cb0a..e5d451c 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -18,13 +18,12 @@ module GitHubChangelogGenerator @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 = {} - - end 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? From bd1bebc8c49d89585fd0fbc4ba7b9239447b845c Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 12:15:42 +0300 Subject: [PATCH 6/9] fx --- lib/github_changelog_generator/fetcher.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 201223b..9b5e554 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -17,13 +17,12 @@ module GitHubChangelogGenerator @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 = {} - - end 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? From 7a2d296f678311e61f4b332941d1f1992e6df021 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 13:14:39 +0300 Subject: [PATCH 7/9] add ocercommit.yml --- .overcommit.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .overcommit.yml diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..f202568 --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,32 @@ +# 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 From dd230dd0509fd9ffcaa266452b8f471d424c6142 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 13:20:54 +0300 Subject: [PATCH 8/9] disable CapitalizedSubject --- .overcommit.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.overcommit.yml b/.overcommit.yml index f202568..5dd1e24 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -30,3 +30,6 @@ PreCommit: # # IndexTags: # enabled: true # Generate a tags file with `ctags` each time HEAD changes +CommitMsg: + CapitalizedSubject: + enabled: false From 659ef2fef5f1d6ec90c81ea4dd41cb1b67082066 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 15:51:50 +0300 Subject: [PATCH 9/9] Add rubocop run script --- .overcommit.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.overcommit.yml b/.overcommit.yml index 5dd1e24..2e2bd2c 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -16,9 +16,10 @@ # Uncomment the following lines to make the configuration take effect. PreCommit: - Rubocop: + RuboCop: enabled: true -# on_warn: fail # Treat all warnings as failures + #command: ['bundle', 'exec', 'rubocop'] + on_warn: fail # Treat all warnings as failures # # TrailingWhitespace: # exclude: