class Skunk::Command::StatusSharer
Knows how to share status to an API
Constants
- DEFAULT_URL
Attributes
status_message[R]
Public Instance Methods
status_reporter=(status_reporter)
click to toggle source
# File lib/skunk/cli/commands/status_sharer.rb, line 16 def status_reporter=(status_reporter) self.analysed_modules = status_reporter.analysed_modules end
Private Instance Methods
base_url()
click to toggle source
:reek: UtilityFunction
# File lib/skunk/cli/commands/status_sharer.rb, line 37 def base_url ENV["SHARE_URL"] || DEFAULT_URL end
json_results()
click to toggle source
# File lib/skunk/cli/commands/status_sharer.rb, line 59 def json_results sorted_modules.map(&:to_hash) end
json_summary()
click to toggle source
# File lib/skunk/cli/commands/status_sharer.rb, line 41 def json_summary result = { total_skunk_score: total_skunk_score, analysed_modules_count: analysed_modules_count, skunk_score_average: skunk_score_average, skunk_version: Skunk::VERSION } if worst result[:worst_skunk_score] = { file: worst.pathname.to_s, skunk_score: worst.skunk_score } end result end
not_sharing?()
click to toggle source
:reek: UtilityFunction
# File lib/skunk/cli/commands/status_sharer.rb, line 64 def not_sharing? ENV["SHARE"] != "true" && ENV["SHARE_URL"].to_s == "" end
payload()
click to toggle source
# File lib/skunk/cli/commands/status_sharer.rb, line 68 def payload JSON.generate( "entries" => json_results, "summary" => json_summary, "options" => { "compare" => "false" } ) end
post_payload()
click to toggle source
:reek: TooManyStatements
# File lib/skunk/cli/commands/status_sharer.rb, line 79 def post_payload req = Net::HTTP::Post.new(url) req.body = payload http = Net::HTTP.new(url.hostname, url.port) if url.scheme == "https" http.use_ssl = true http.ssl_version = :TLSv1_2 end http.start do |connection| connection.request req end end
url()
click to toggle source
# File lib/skunk/cli/commands/status_sharer.rb, line 94 def url URI(File.join(base_url, "reports")) end