From df64ab5ba1350b5bfee3f0aa4afa61de56a7e663 Mon Sep 17 00:00:00 2001 From: Andrew Waage Date: Wed, 18 May 2016 15:40:25 -0700 Subject: [PATCH] first pass at caching. still WIP. Need to parameterize some things --- github_changelog_generator.gemspec | 2 ++ lib/github_changelog_generator.rb | 3 +++ lib/github_changelog_generator/octo_fetcher.rb | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index d6e1f35..cc34887 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -28,4 +28,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "github_api", ">= 0.14" spec.add_runtime_dependency "rainbow", ">= 2.1" spec.add_runtime_dependency("octokit", ["~> 4.0"]) + spec.add_runtime_dependency("faraday-http-cache") + spec.add_runtime_dependency("activesupport") end diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 44b584c..558b451 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -3,6 +3,9 @@ require "github_api" require "octokit" +require 'faraday-http-cache' +require "logger" +require "active_support" require "json" require "benchmark" diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 7b6fa3b..53ec212 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -27,10 +27,26 @@ 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 + middleware_opts = { + :serializer => Marshal, + :store => ActiveSupport::Cache::FileStore.new('/tmp/cache'), + :logger => Logger.new('/tmp/github-changelog-logger.log'), + :shared_cache => false + } + stack = Faraday::RackBuilder.new do |builder| + builder.use Faraday::HttpCache, middleware_opts + builder.use Octokit::Response::RaiseError + builder.adapter Faraday.default_adapter + # builder.response :logger + end + Octokit.middleware = stack + end # Fetch all tags from repo #