lib/shipit/github_app.rb in shipit-engine-0.28.0 vs lib/shipit/github_app.rb in shipit-engine-0.28.1

- old
+ new

@@ -23,10 +23,11 @@ end end DOMAIN = 'github.com'.freeze AuthenticationFailed = Class.new(StandardError) + API_STATUS_ID = 'brv1bkgrwx7q'.freeze attr_reader :oauth_teams, :domain, :bot_login def initialize(config) super() @@ -51,10 +52,17 @@ client.access_token = token end client end + def api_status + conn = Faraday.new(url: 'https://www.githubstatus.com') + response = conn.get('/api/v2/components.json') + parsed = JSON.parse(response.body, symbolize_names: true) + parsed[:components].find { |c| c[:id] == API_STATUS_ID } + end + def verify_webhook_signature(signature, message) return true unless webhook_secret algorithm, signature = signature.split("=", 2) return false unless algorithm == 'sha1' @@ -116,16 +124,31 @@ domain != DOMAIN end def new_client(options = {}) client = Octokit::Client.new(options.reverse_merge(api_endpoint: api_endpoint)) - client.middleware = Shipit.new_faraday_stack + client.middleware = faraday_stack client end private attr_reader :webhook_secret, :oauth_id, :oauth_secret + + def faraday_stack + @faraday_stack ||= Faraday::RackBuilder.new do |builder| + builder.use( + Faraday::HttpCache, + shared_cache: false, + store: Rails.cache, + logger: Rails.logger, + serializer: NullSerializer, + ) + builder.use GitHubHTTPCacheMiddleware + builder.use Octokit::Response::RaiseError + builder.adapter Faraday.default_adapter + end + end def app_id @app_id ||= @config.fetch(:app_id) end