cleaned up caching and added to options parser

This commit is contained in:
Andrew Waage 2016-05-23 18:28:00 -07:00 committed by Olle Jonsson
parent 10cf2a0f04
commit 41271b1ecb
2 changed files with 23 additions and 5 deletions

View File

@ -20,6 +20,12 @@ module GitHubChangelogGenerator
@project = @options[:project]
# Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
@since = @options[:since] # eg. Time.parse("2016-01-01 10:00:00").iso8601
# Use ActiveSupport::Cache::FileStore to cache http requests
@http_cache = @options[:http_cache]
@cache_file = @options.fetch(:cache_file, '/tmp/github-changelog-http-cache') if @http_cache
@cache_log = @options.fetch(:cache_log, '/tmp/github-changelog-logger.log') if @http_cache
init_cache if @http_cache
@github_token = fetch_github_token
@request_options = { :per_page => PER_PAGE_NUMBER }
@ -27,16 +33,16 @@ module GitHubChangelogGenerator
@github_options[:access_token] = @github_token unless @github_token.nil?
@github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
init_middleware
client_type = @options[:github_endpoint].nil? ? Octokit::Client : Octokit::EnterpriseAdminClient
@client = client_type.new(@github_options)
end
def init_middleware
def init_cache
middleware_opts = {
:serializer => Marshal,
:store => ActiveSupport::Cache::FileStore.new('/tmp/cache'),
:logger => Logger.new('/tmp/github-changelog-logger.log'),
:store => ActiveSupport::Cache::FileStore.new(@cache_file),
:logger => Logger.new(@cache_log),
:shared_cache => false
}
stack = Faraday::RackBuilder.new do |builder|

View File

@ -161,6 +161,15 @@ module GitHubChangelogGenerator
opts.on("--release-branch [RELEASE-BRANCH]", "Limit pull requests to the release branch, such as master or release") do |release_branch|
options[:release_branch] = release_branch
end
opts.on("--[no-]http-cache", "Use HTTP Cache to cache Github API requests (useful for large repos) Default is true.") do |http_cache|
options[:http_cache] = http_cache
end
opts.on("--cache-file [CACHE-FILE]", "Filename to use for cache. Default is /tmp/github-changelog-http-cache") do |cache_file|
options[:cache_file] = cache_file
end
opts.on("--cache-log [CACHE-LOG]", "Filename to use for cache log. Default is /tmp/github-changelog-logger.log") do |cache_log|
options[:cache_log] = cache_log
end
opts.on("--[no-]verbose", "Run verbosely. Default is true") do |v|
options[:verbose] = v
end
@ -204,7 +213,10 @@ module GitHubChangelogGenerator
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin"
git_remote: "origin",
http_cache: true,
cache_file: '/tmp/github-changelog-http-cache',
cache_log: '/tmp/github-changelog-logger.log',
}
end