# frozen_string_literal: true module Diffend # Verifies voting verdicts for gems module Voting class << self # Build verdict # # @param command [String] either install or update # @param definition [Bundler::Definition] definition for your source def call(command, definition) Versions::Remote .call(command, definition) .tap { |response| build_message(command, response) } end def build_message(command, response) if response.key?('error') build_error(response) elsif response.key?('action') build_verdict(command, response) else raise UnsupportedResponse, response['action'] end end def build_error(response) build_error_message(response) .tap(&Bundler.ui.method(:error)) exit 1 end def build_verdict(command, response) case response['action'] when 'allow' build_allow_message(command, response) .tap(&Bundler.ui.method(:confirm)) when 'deny' build_deny_message(command, response) .tap(&Bundler.ui.method(:error)) exit 1 else raise UnsupportedAction, response['action'] end end def build_error_message(response) <<~MSG \nDiffend returned an error for your request.\n #{response['error']}\n MSG end def build_allow_message(command, response) <<~MSG \nDiffend reported an allow verdict for #{command} command for this project.\n All of our #{response['allows_count'] + response['denies_count']} checks succeeded.\n #{response['review_url']}\n MSG end def build_deny_message(command, response) <<~MSG \nDiffend reported a deny verdict for #{command} command for this project.\n #{response['denies_count']} out of our #{response['allows_count'] + response['denies_count']} checks failed. Please go to the url below and review the issues.\n #{response['review_url']}\n MSG end end end end