Module: Diffend::Voting

Defined in:
lib/diffend/voting.rb,
lib/diffend/voting/versions/local.rb,
lib/diffend/voting/versions/remote.rb

Overview

Verifies voting verdicts for gems

Defined Under Namespace

Modules: Versions

Class Method Summary collapse

Class Method Details

.build_allow_message(command, response) ⇒ String

Parameters:

  • command (String) —

    either install or update

  • response (Hash) —

    response from diffend API

Returns:

  • (String)


81
82
83
84
85
86
87
# File 'lib/diffend/voting.rb', line 81

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

.build_deny_message(command, response) ⇒ String

Parameters:

  • command (String) —

    either install or update

  • response (Hash) —

    response from diffend API

Returns:

  • (String)


93
94
95
96
97
98
99
# File 'lib/diffend/voting.rb', line 93

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

.build_error(response) ⇒ Object

Parameters:

  • response (Hash) —

    response from diffend API



37
38
39
40
41
42
# File 'lib/diffend/voting.rb', line 37

def build_error(response)
  build_error_message(response)
    .tap(&Bundler.ui.method(:error))

  exit 1
end

.build_error_message(response) ⇒ String

Parameters:

  • response (Hash) —

    response from diffend API

Returns:

  • (String)


70
71
72
73
74
75
# File 'lib/diffend/voting.rb', line 70

def build_error_message(response)
  <<~MSG
    \nDiffend returned an error for your request.\n
    #{response['error']}\n
  MSG
end

.build_message(command, config, response) ⇒ Object

Parameters:

  • command (String) —

    either install or update

  • config (OpenStruct) —

    diffend config

  • response (Hash) —

    response from diffend API



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/diffend/voting.rb', line 21

def build_message(command, config, response)
  if response.key?('error')
    build_error(response)
  elsif response.key?('action')
    build_verdict(command, config, response)
  else
    Diffend::HandleErrors::Report.call(
      config: config,
      message: :unsupported_response,
      payload: response,
      report: true
    )
  end
end

.build_verdict(command, config, response) ⇒ Object

Parameters:

  • command (String) —

    either install or update

  • config (OpenStruct) —

    diffend config

  • response (Hash) —

    response from diffend API



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/diffend/voting.rb', line 47

def build_verdict(command, config, 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
    Diffend::HandleErrors::Report.call(
      config: config,
      message: :unsupported_verdict,
      payload: response,
      report: true
    )
  end
end

.call(command, config, definition) ⇒ Object

Build verdict

Parameters:

  • command (String) —

    either install or update

  • config (OpenStruct) —

    diffend config

  • definition (Bundler::Definition) —

    definition for your source



12
13
14
15
16
# File 'lib/diffend/voting.rb', line 12

def call(command, config, definition)
  Versions::Remote
    .call(command, config, definition)
    .tap { |response| build_message(command, config, response) }
end