Merge pull request #408 from jamesc/jc/remove-colorize

Replace GPL'd colorize gem with MIT-licensed rainbow
This commit is contained in:
Olle Jonsson 2016-09-01 21:15:42 +02:00 committed by GitHub
commit 96491a21e0
8 changed files with 31 additions and 37 deletions

View File

@ -2,7 +2,7 @@ PATH
remote: . remote: .
specs: specs:
github_changelog_generator (1.13.1) github_changelog_generator (1.13.1)
colorize (>= 0.7) rainbow (>= 2.1)
github_api (>= 0.12) github_api (>= 0.12)
rake (>= 10.0) rake (>= 10.0)
@ -15,7 +15,6 @@ GEM
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
codeclimate-test-reporter (0.6.0) codeclimate-test-reporter (0.6.0)
simplecov (>= 0.7.1, < 1.0.0) simplecov (>= 0.7.1, < 1.0.0)
colorize (0.8.1)
coveralls (0.8.14) coveralls (0.8.14)
json (>= 1.8, < 3) json (>= 1.8, < 3)
simplecov (~> 0.12.0) simplecov (~> 0.12.0)

View File

@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "rake", ">= 10.0" spec.add_runtime_dependency "rake", ">= 10.0"
spec.add_runtime_dependency "github_api", ">= 0.12" spec.add_runtime_dependency "github_api", ">= 0.12"
spec.add_runtime_dependency "colorize", ">= 0.7" spec.add_runtime_dependency "rainbow", ">= 2.1"
spec.add_development_dependency "overcommit", ">= 0.31" spec.add_development_dependency "overcommit", ">= 0.31"
spec.add_development_dependency "rspec", ">= 3.2" spec.add_development_dependency "rspec", ">= 3.2"

View File

@ -2,7 +2,6 @@
require "github_api" require "github_api"
require "json" require "json"
require "colorize"
require "benchmark" require "benchmark"
require_relative "github_changelog_generator/helper" require_relative "github_changelog_generator/helper"

View File

@ -34,7 +34,7 @@ module GitHubChangelogGenerator
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)
Helper.log.warn NO_TOKEN_PROVIDED.yellow unless env_var Helper.log.warn NO_TOKEN_PROVIDED unless env_var
env_var env_var
end end
@ -53,11 +53,11 @@ module GitHubChangelogGenerator
begin begin
value = yield value = yield
rescue Github::Error::Unauthorized => e rescue Github::Error::Unauthorized => e
Helper.log.error e.response_message.red Helper.log.error e.response_message
abort "Error: wrong GitHub token" abort "Error: wrong GitHub token"
rescue Github::Error::Forbidden => e rescue Github::Error::Forbidden => e
Helper.log.warn e.response_message.red Helper.log.warn e.response_message
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
end end
value value
end end
@ -76,9 +76,9 @@ module GitHubChangelogGenerator
end end
print_empty_line print_empty_line
if tags.count == 0 if tags.empty?
Helper.log.warn "Warning: Can't find any tags in repo.\ Helper.log.warn "Warning: Can't find any tags in repo.\
Make sure, that you push tags to remote repo via 'git push --tags'".yellow Make sure, that you push tags to remote repo via 'git push --tags'"
else else
Helper.log.info "Found #{tags.count} tags" Helper.log.info "Found #{tags.count} tags"
end end
@ -110,8 +110,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
Helper.log.info "Received issues: #{issues.count}" Helper.log.info "Received issues: #{issues.count}"
rescue Github::Error::Forbidden => e rescue Github::Error::Forbidden => e
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ").red Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
end end
# separate arrays of issues and pull requests: # separate arrays of issues and pull requests:
@ -145,8 +145,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
end end
print_empty_line print_empty_line
rescue Github::Error::Forbidden => e rescue Github::Error::Forbidden => e
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ").red Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
end end
Helper.log.info "Fetching merged dates: #{pull_requests.count}" Helper.log.info "Fetching merged dates: #{pull_requests.count}"
@ -182,8 +182,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
issue[:events].concat(page) issue[:events].concat(page)
end end
rescue Github::Error::Forbidden => e rescue Github::Error::Forbidden => e
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ").red Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
end end
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}") print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
i += 1 i += 1
@ -209,8 +209,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
@options[:project], @options[:project],
tag["commit"]["sha"] tag["commit"]["sha"]
rescue Github::Error::Forbidden => e rescue Github::Error::Forbidden => e
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ").red Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
end end
time_string = commit_data["committer"]["date"] time_string = commit_data["committer"]["date"]
Time.parse(time_string) Time.parse(time_string)

View File

@ -74,7 +74,7 @@ module GitHubChangelogGenerator
commit = @fetcher.fetch_commit(event) commit = @fetcher.fetch_commit(event)
issue[:actual_date] = commit[:author][:date] issue[:actual_date] = commit[:author][:date]
rescue rescue
puts "Warning: Can't fetch commit #{event[:commit_id]}. It is probably referenced from another repo.".yellow puts "Warning: Can't fetch commit #{event[:commit_id]}. It is probably referenced from another repo."
issue[:actual_date] = issue[:closed_at] issue[:actual_date] = issue[:closed_at]
end end
end end

View File

@ -39,10 +39,10 @@ module GitHubChangelogGenerator
index2 = hash[tag2] index2 = hash[tag2]
log += generate_log_between_tags(all_tags[index1], all_tags[index2]) log += generate_log_between_tags(all_tags[index1], all_tags[index2])
else else
raise ChangelogGeneratorError, "Can't find tag #{tag2} -> exit".red raise ChangelogGeneratorError, "Can't find tag #{tag2} -> exit"
end end
else else
raise ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".red raise ChangelogGeneratorError, "Can't find tag #{tag1} -> exit"
end end
log log
end end
@ -141,7 +141,7 @@ module GitHubChangelogGenerator
(1...filtered_tags.size).each do |index| (1...filtered_tags.size).each do |index|
log += generate_log_between_tags(filtered_tags[index], filtered_tags[index - 1]) log += generate_log_between_tags(filtered_tags[index], filtered_tags[index - 1])
end end
if @filtered_tags.count != 0 if filtered_tags.any?
log += generate_log_between_tags(nil, filtered_tags.last) log += generate_log_between_tags(nil, filtered_tags.last)
end end

View File

@ -19,7 +19,7 @@ module GitHubChangelogGenerator
# @param [Hash] tag_name name of the tag # @param [Hash] tag_name name of the tag
# @return [Time] time of specified tag # @return [Time] time of specified tag
def get_time_of_tag(tag_name) def get_time_of_tag(tag_name)
raise ChangelogGeneratorError, "tag_name is nil".red if tag_name.nil? raise ChangelogGeneratorError, "tag_name is nil" if tag_name.nil?
name_of_tag = tag_name["name"] name_of_tag = tag_name["name"]
time_for_name = @tag_times_hash[name_of_tag] time_for_name = @tag_times_hash[name_of_tag]
@ -99,7 +99,7 @@ module GitHubChangelogGenerator
filtered_tags = all_tags filtered_tags = all_tags
tag = @options[:due_tag] tag = @options[:due_tag]
if tag if tag
if (all_tags.count > 0) && (all_tags.map(&:name).include? tag) if all_tags.any? && all_tags.map(&:name).include?(tag)
idx = all_tags.index { |t| t.name == tag } idx = all_tags.index { |t| t.name == tag }
last_index = all_tags.count - 1 last_index = all_tags.count - 1
filtered_tags = if idx > 0 && idx < last_index filtered_tags = if idx > 0 && idx < last_index

View File

@ -1,4 +1,6 @@
require "logger" require "logger"
require "rainbow"
module GitHubChangelogGenerator module GitHubChangelogGenerator
module Helper module Helper
# @return true if the currently running program is a unit test # @return true if the currently running program is a unit test
@ -13,20 +15,14 @@ module GitHubChangelogGenerator
end end
@log.formatter = proc do |severity, _datetime, _progname, msg| @log.formatter = proc do |severity, _datetime, _progname, msg|
string = "#{msg}\n" string = "#{msg}\n"
case severity
if severity == "DEBUG" when "DEBUG" then Rainbow(string).magenta
string = string.magenta when "INFO" then Rainbow(string).white
elsif severity == "INFO" when "WARN" then Rainbow(string).yellow
string = string.white when "ERROR" then Rainbow(string).red
elsif severity == "WARN" when "FATAL" then Rainbow(string).red.bright
string = string.yellow else string
elsif severity == "ERROR"
string = string.red
elsif severity == "FATAL"
string = string.red.bold
end end
string
end end
# Logging happens using this method # Logging happens using this method