Sha256: 426c8aab3fec27c1715aa73d5ce6184dde1d1de47acd7d897570b93327621e27

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'json'

module Diffend
  # Module responsible for fetching diffend verdict on local context
  module RequestVerdict
    # Exceptions that we handle when there is a resolve issue
    RESOLVE_EXCEPTIONS = [
      ::Bundler::GemNotFound,
      ::Bundler::GitError,
      ::Bundler::PermissionError,
      ::Bundler::VersionConflict
    ].freeze

    class << self
      # @param config [Diffend::Config]
      # @param definition [::Bundler::Definition] definition for your source
      def call(config, definition)
        payload = Diffend::LocalContext.call(config, definition)

        response = Diffend::Request.call(
          build_request_object(config, payload)
        )

        JSON.parse(response.body)
      rescue *RESOLVE_EXCEPTIONS
        raise ::Diffend::Errors::DependenciesResolveException
      rescue StandardError => e
        Diffend::HandleErrors::Report.call(
          exception: e,
          payload: payload || {},
          config: config,
          message: :unhandled_exception,
          report: true
        )
      end

      # @param config [Diffend::Config]
      # @param payload [Hash]
      #
      # @return [Diffend::RequestObject]
      def build_request_object(config, payload)
        Diffend::RequestObject.new(
          config: config,
          url: config.commands_url,
          payload: payload,
          request_method: :post
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
diffend-monitor-0.2.40 lib/diffend/request_verdict.rb
diffend-0.2.40 lib/diffend/request_verdict.rb
diffend-monitor-0.2.39 lib/diffend/request_verdict.rb
diffend-0.2.39 lib/diffend/request_verdict.rb
diffend-monitor-0.2.38 lib/diffend/request_verdict.rb
diffend-0.2.38 lib/diffend/request_verdict.rb