2019-10-16 09:07:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'net/http'
|
|
|
|
require 'json'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Danger
|
|
|
|
module RequestHelper
|
|
|
|
HTTPError = Class.new(RuntimeError)
|
|
|
|
|
|
|
|
# @param [String] url
|
|
|
|
def self.http_get_json(url)
|
|
|
|
rsp = Net::HTTP.get_response(URI.parse(url))
|
|
|
|
|
|
|
|
unless rsp.is_a?(Net::HTTPOK)
|
|
|
|
raise HTTPError, "Failed to read #{url}: #{rsp.code} #{rsp.message}"
|
|
|
|
end
|
|
|
|
|
2020-05-20 15:08:20 +00:00
|
|
|
JSON.parse(rsp.body)
|
2019-10-16 09:07:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|