Drop all local color method calls

- The central logging method decides the color of the output
  - pass Rubocop complaints
This commit is contained in:
Olle Jonsson 2016-09-01 11:02:19 +02:00 committed by James Casey
parent f647dc0d98
commit 7e77fd6c57
6 changed files with 29 additions and 34 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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