Drop all local color method calls
- The central logging method decides the color of the output - pass Rubocop complaints
This commit is contained in:
parent
f647dc0d98
commit
7e77fd6c57
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
require "github_api"
|
require "github_api"
|
||||||
require "json"
|
require "json"
|
||||||
require "rainbow/ext/string"
|
|
||||||
require "benchmark"
|
require "benchmark"
|
||||||
|
|
||||||
require_relative "github_changelog_generator/helper"
|
require_relative "github_changelog_generator/helper"
|
||||||
|
|
|
@ -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.color(: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.color(: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.color(:red)
|
Helper.log.warn e.response_message
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.color(: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'".color(: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'".color(:yello
|
||||||
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(", ").color(:red)
|
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.color(: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'".color(:yello
|
||||||
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(", ").color(:red)
|
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.color(: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'".color(:yello
|
||||||
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(", ").color(:red)
|
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.color(: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'".color(:yello
|
||||||
@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(", ").color(:red)
|
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.color(: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)
|
||||||
|
|
|
@ -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.".color(: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
|
||||||
|
|
|
@ -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".color(:red)
|
raise ChangelogGeneratorError, "Can't find tag #{tag2} -> exit"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".color(: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
|
||||||
|
|
||||||
|
|
|
@ -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".color(: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
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
require "logger"
|
require "logger"
|
||||||
|
require "rainbow/ext/string"
|
||||||
|
|
||||||
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 string.color(:magenta)
|
||||||
string = string.color(:magenta)
|
when "INFO" then string.color(:white)
|
||||||
elsif severity == "INFO"
|
when "WARN" then string.color(:yellow)
|
||||||
string = string.color(:white)
|
when "ERROR" then string.color(:red)
|
||||||
elsif severity == "WARN"
|
when "FATAL" then string.color(:red).bright
|
||||||
string = string.color(:yellow)
|
else string
|
||||||
elsif severity == "ERROR"
|
|
||||||
string = string.color(:red)
|
|
||||||
elsif severity == "FATAL"
|
|
||||||
string = string.color(:red).bright
|
|
||||||
end
|
end
|
||||||
|
|
||||||
string
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Logging happens using this method
|
# Logging happens using this method
|
||||||
|
|
Loading…
Reference in New Issue
Block a user