debian-mirror-gitlab/tooling/danger/request_helper.rb

24 lines
468 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'net/http'
require 'json'
2021-03-11 19:13:27 +05:30
module Tooling
2019-12-21 20:55:43 +05:30
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-06-23 00:09:42 +05:30
JSON.parse(rsp.body)
2019-12-21 20:55:43 +05:30
end
end
end
end