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

24 lines
475 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# 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-24 23:13:21 +05:30
Gitlab::Json.parse(rsp.body)
2019-12-21 20:55:43 +05:30
end
end
end
end