Move logging to separate class, disable logging during test execution.
This commit is contained in:
parent
a0cf2f54ee
commit
ff6115247e
|
@ -23,9 +23,10 @@ Gem::Specification.new do |spec|
|
||||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||||
spec.require_paths = ["lib"]
|
spec.require_paths = ["lib"]
|
||||||
|
|
||||||
spec.add_development_dependency "bundler", "~> 1.7"
|
|
||||||
spec.add_development_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("colorize", ["~> 0.7"])
|
||||||
|
|
||||||
|
# Development only
|
||||||
|
spec.add_development_dependency "bundler", "~> 1.7"
|
||||||
|
spec.add_development_dependency "rake", "~> 10.0"
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
## [0.0.4](https://github.com/skywinder/changelog_test/tree/0.0.4) (2015-05-22)
|
## [0.0.4](https://github.com/skywinder/changelog_test/tree/0.0.4) (2015-05-22)
|
||||||
|
|
||||||
[Full Changelog](https://github.com/skywinder/changelog_test/compare/v0.0.3...0.0.4)
|
|
||||||
|
|
||||||
**Closed issues:**
|
**Closed issues:**
|
||||||
|
|
||||||
- Test issue, that should appear in 0.0.4 [\#3](https://github.com/skywinder/changelog_test/issues/3)
|
- Test issue, that should appear in 0.0.4 [\#3](https://github.com/skywinder/changelog_test/issues/3)
|
||||||
|
@ -12,24 +10,10 @@
|
||||||
|
|
||||||
- Add automatically generated change log file. [\#5](https://github.com/skywinder/changelog_test/pull/5) ([skywinder](https://github.com/skywinder))
|
- Add automatically generated change log file. [\#5](https://github.com/skywinder/changelog_test/pull/5) ([skywinder](https://github.com/skywinder))
|
||||||
|
|
||||||
## [v0.0.3](https://github.com/skywinder/changelog_test/tree/v0.0.3) (2015-03-04)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/skywinder/changelog_test/compare/v0.0.2...v0.0.3)
|
|
||||||
|
|
||||||
**Merged pull requests:**
|
|
||||||
|
|
||||||
- fix \#3. hotfix. Should appear in v0.0.3 [\#4](https://github.com/skywinder/changelog_test/pull/4) ([skywinder](https://github.com/skywinder))
|
- fix \#3. hotfix. Should appear in v0.0.3 [\#4](https://github.com/skywinder/changelog_test/pull/4) ([skywinder](https://github.com/skywinder))
|
||||||
|
|
||||||
## [v0.0.2](https://github.com/skywinder/changelog_test/tree/v0.0.2) (2015-03-04)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/skywinder/changelog_test/compare/v0.0.1...v0.0.2)
|
|
||||||
|
|
||||||
**Merged pull requests:**
|
|
||||||
|
|
||||||
- Here is a test hotfix should appear in v.0.0.2 [\#2](https://github.com/skywinder/changelog_test/pull/2) ([skywinder](https://github.com/skywinder))
|
- Here is a test hotfix should appear in v.0.0.2 [\#2](https://github.com/skywinder/changelog_test/pull/2) ([skywinder](https://github.com/skywinder))
|
||||||
|
|
||||||
## [v0.0.1](https://github.com/skywinder/changelog_test/tree/v0.0.1) (2015-03-02)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
|
@ -5,6 +5,7 @@ require "json"
|
||||||
require "colorize"
|
require "colorize"
|
||||||
require "benchmark"
|
require "benchmark"
|
||||||
|
|
||||||
|
require_relative "github_changelog_generator/helper"
|
||||||
require_relative "github_changelog_generator/parser"
|
require_relative "github_changelog_generator/parser"
|
||||||
require_relative "github_changelog_generator/generator/generator"
|
require_relative "github_changelog_generator/generator/generator"
|
||||||
require_relative "github_changelog_generator/version"
|
require_relative "github_changelog_generator/version"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
require "logger"
|
|
||||||
|
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
# A Fetcher responsible for all requests to GitHub and all basic manipulation with related data
|
# A Fetcher responsible for all requests to GitHub and all basic manipulation with related data
|
||||||
|
@ -6,6 +5,7 @@ module GitHubChangelogGenerator
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
||||||
|
|
||||||
class Fetcher
|
class Fetcher
|
||||||
PER_PAGE_NUMBER = 30
|
PER_PAGE_NUMBER = 30
|
||||||
CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN"
|
CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN"
|
||||||
|
@ -16,12 +16,6 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options || {}
|
@options = options || {}
|
||||||
|
|
||||||
@logger = Logger.new(STDOUT)
|
|
||||||
@logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
|
||||||
"#{msg}\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
@user = @options[:user]
|
@user = @options[:user]
|
||||||
@project = @options[:project]
|
@project = @options[:project]
|
||||||
@github_token = fetch_github_token
|
@github_token = fetch_github_token
|
||||||
|
@ -41,7 +35,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)
|
||||||
|
|
||||||
@logger.warn NO_TOKEN_PROVIDED.yellow unless env_var
|
Helper.log.warn NO_TOKEN_PROVIDED.yellow unless env_var
|
||||||
|
|
||||||
env_var
|
env_var
|
||||||
end
|
end
|
||||||
|
@ -62,11 +56,11 @@ module GitHubChangelogGenerator
|
||||||
begin
|
begin
|
||||||
value = yield
|
value = yield
|
||||||
rescue Github::Error::Unauthorized => e
|
rescue Github::Error::Unauthorized => e
|
||||||
@logger.error e.body.red
|
Helper.log.error e.body.red
|
||||||
abort "Error: wrong GitHub token"
|
abort "Error: wrong GitHub token"
|
||||||
rescue Github::Error::Forbidden => e
|
rescue Github::Error::Forbidden => e
|
||||||
@logger.warn e.body.red
|
Helper.log.warn e.body.red
|
||||||
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||||
end
|
end
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
@ -83,10 +77,10 @@ module GitHubChangelogGenerator
|
||||||
print_empty_line
|
print_empty_line
|
||||||
|
|
||||||
if tags.count == 0
|
if tags.count == 0
|
||||||
@logger.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'".yellow
|
||||||
else
|
else
|
||||||
@logger.info "Found #{tags.count} tags"
|
Helper.log.info "Found #{tags.count} tags"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,10 +106,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
break if @options[:max_issues] && issues.length >= @options[:max_issues]
|
break if @options[:max_issues] && issues.length >= @options[:max_issues]
|
||||||
end
|
end
|
||||||
print_empty_line
|
print_empty_line
|
||||||
@logger.info "Received issues: #{issues.count}"
|
Helper.log.info "Received issues: #{issues.count}"
|
||||||
|
|
||||||
rescue
|
rescue
|
||||||
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||||
end
|
end
|
||||||
|
|
||||||
# separate arrays of issues and pull requests:
|
# separate arrays of issues and pull requests:
|
||||||
|
@ -140,10 +134,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
end
|
end
|
||||||
print_empty_line
|
print_empty_line
|
||||||
rescue
|
rescue
|
||||||
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||||
end
|
end
|
||||||
|
|
||||||
@logger.info "Fetching merged dates: #{pull_requests.count}"
|
Helper.log.info "Fetching merged dates: #{pull_requests.count}"
|
||||||
pull_requests
|
pull_requests
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -170,7 +164,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
repo: @options[:project],
|
repo: @options[:project],
|
||||||
issue_number: issue["number"]
|
issue_number: issue["number"]
|
||||||
rescue
|
rescue
|
||||||
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||||
end
|
end
|
||||||
issue[:events] = obj.body
|
issue[:events] = obj.body
|
||||||
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}")
|
||||||
|
@ -184,7 +178,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
# to clear line from prev print
|
# to clear line from prev print
|
||||||
print_empty_line
|
print_empty_line
|
||||||
|
|
||||||
@logger.info "Fetching events for issues and PR: #{i}"
|
Helper.log.info "Fetching events for issues and PR: #{i}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Try to find tag date in local hash.
|
# Try to find tag date in local hash.
|
||||||
|
@ -203,7 +197,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
@options[:project],
|
@options[:project],
|
||||||
tag_name["commit"]["sha"]
|
tag_name["commit"]["sha"]
|
||||||
rescue
|
rescue
|
||||||
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||||
end
|
end
|
||||||
time_string = github_git_data_commits_get["committer"]["date"]
|
time_string = github_git_data_commits_get["committer"]["date"]
|
||||||
@tag_times_hash[tag_name["name"]] = Time.parse(time_string)
|
@tag_times_hash[tag_name["name"]] = Time.parse(time_string)
|
||||||
|
|
37
lib/github_changelog_generator/helper.rb
Normal file
37
lib/github_changelog_generator/helper.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
require "logger"
|
||||||
|
module GitHubChangelogGenerator
|
||||||
|
module Helper
|
||||||
|
# @return true if the currently running program is a unit test
|
||||||
|
def self.test?
|
||||||
|
defined?SpecHelper
|
||||||
|
end
|
||||||
|
|
||||||
|
if test?
|
||||||
|
@log ||= Logger.new(nil) # don't show any logs when running tests
|
||||||
|
else
|
||||||
|
@log ||= Logger.new(STDOUT)
|
||||||
|
end
|
||||||
|
@log.formatter = proc do |severity, _datetime, _progname, msg|
|
||||||
|
string = "#{msg}\n"
|
||||||
|
|
||||||
|
if severity == "DEBUG"
|
||||||
|
string = string.magenta
|
||||||
|
elsif severity == "INFO"
|
||||||
|
string = string.white
|
||||||
|
elsif severity == "WARN"
|
||||||
|
string = string.yellow
|
||||||
|
elsif severity == "ERROR"
|
||||||
|
string = string.red
|
||||||
|
elsif severity == "FATAL"
|
||||||
|
string = string.red.bold
|
||||||
|
end
|
||||||
|
|
||||||
|
string
|
||||||
|
end
|
||||||
|
|
||||||
|
# Logging happens using this method
|
||||||
|
class << self
|
||||||
|
attr_reader :log
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,7 +2,7 @@
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require "pp"
|
require "pp"
|
||||||
require_relative "version"
|
require_relative "version"
|
||||||
|
require_relative "helper"
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
class Parser
|
class Parser
|
||||||
# parse options with optparse
|
# parse options with optparse
|
||||||
|
@ -21,7 +21,7 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:verbose]
|
if options[:verbose]
|
||||||
puts "Performing task with options:"
|
Helper.log.info "Performing task with options:"
|
||||||
pp options
|
pp options
|
||||||
puts ""
|
puts ""
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,10 @@ require "codeclimate-test-reporter"
|
||||||
require "simplecov"
|
require "simplecov"
|
||||||
require "coveralls"
|
require "coveralls"
|
||||||
|
|
||||||
|
# This module is only used to check the environment is currently a testing env
|
||||||
|
module SpecHelper
|
||||||
|
end
|
||||||
|
|
||||||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
||||||
Coveralls::SimpleCov::Formatter,
|
Coveralls::SimpleCov::Formatter,
|
||||||
SimpleCov::Formatter::HTMLFormatter,
|
SimpleCov::Formatter::HTMLFormatter,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user