Module: Diffend::Execute
- Defined in:
- lib/diffend/execute.rb
Overview
Executes a check for a given command
Class Method Summary collapse
- .build_allow_message(command, response) ⇒ String
-
.build_definition(command) ⇒ ::Bundler::Definition
Build bundler definition.
- .build_deny_message(command, response) ⇒ String
- .build_error(config, response) ⇒ Object
- .build_error_message(response) ⇒ String
- .build_message(config, response) ⇒ Object
- .build_message_header(type, command) ⇒ String
- .build_message_info(response) ⇒ String
- .build_verdict(config, response) ⇒ Object
- .build_warn_message(command, response) ⇒ String
-
.call(config) ⇒ Object
Build verdict.
Class Method Details
.build_allow_message(command, response) ⇒ String
94 95 96 97 98 99 100 |
# File 'lib/diffend/execute.rb', line 94 def (command, response) <<~MSG #{('an allow', command)} #{(response)}\n #{response['review_url']}\n MSG end |
.build_definition(command) ⇒ ::Bundler::Definition
Build bundler definition
21 22 23 24 25 26 27 |
# File 'lib/diffend/execute.rb', line 21 def build_definition(command) Diffend::BuildBundlerDefinition.call( command, ::Bundler.default_gemfile, ::Bundler.default_lockfile ) end |
.build_deny_message(command, response) ⇒ String
118 119 120 121 122 123 124 |
# File 'lib/diffend/execute.rb', line 118 def (command, response) <<~MSG #{('a deny', command)} #{(response)} Please go to the url below and review the issues.\n #{response['review_url']}\n MSG end |
.build_error(config, response) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/diffend/execute.rb', line 48 def build_error(config, response) (response) .tap(&config.logger.method(:error)) raise Diffend::Errors::HandledException end |
.build_error_message(response) ⇒ String
83 84 85 86 87 88 |
# File 'lib/diffend/execute.rb', line 83 def (response) <<~MSG \nDiffend returned an error for your request.\n #{response['error']}\n MSG end |
.build_message(config, response) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/diffend/execute.rb', line 31 def (config, response) if response.key?('error') build_error(config, response) elsif response.key?('action') build_verdict(config, response) else Diffend::HandleErrors::Report.call( config: config, message: :unsupported_response, payload: response, report: true ) end end |
.build_message_header(type, command) ⇒ String
130 131 132 |
# File 'lib/diffend/execute.rb', line 130 def (type, command) "\nDiffend reported #{type} verdict for #{command} command for this project." end |
.build_message_info(response) ⇒ String
137 138 139 |
# File 'lib/diffend/execute.rb', line 137 def (response) "\nQuality score: #{response['quality_score']}, allows: #{response['allows_count']}, warnings: #{response['warns_count']}, denies: #{response['denies_count']}." end |
.build_verdict(config, response) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/diffend/execute.rb', line 57 def build_verdict(config, response) case response['action'] when 'allow' (config.command, response) .tap(&config.logger.method(:info)) when 'warn' (config.command, response) .tap(&config.logger.method(:warn)) when 'deny' (config.command, response) .tap(&config.logger.method(:error)) exit 1 unless ENV.key?('DIFFEND_SKIP_DENY') else Diffend::HandleErrors::Report.call( config: config, message: :unsupported_verdict, payload: response, report: true ) end end |
.build_warn_message(command, response) ⇒ String
106 107 108 109 110 111 112 |
# File 'lib/diffend/execute.rb', line 106 def (command, response) <<~MSG #{('a warn', command)} #{(response)} Please go to the url below and review the issues.\n #{response['review_url']}\n MSG end |
.call(config) ⇒ Object
Build verdict
10 11 12 13 14 15 16 |
# File 'lib/diffend/execute.rb', line 10 def call(config) Diffend::RequestVerdict .call(config, build_definition(config.command)) .tap { |response| (config, response) } rescue Diffend::Errors::DependenciesResolveException # We are unable to resolve dependencies, no message will be printed end |