diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-05 16:20:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-05 16:20:45 +0000 |
commit | d298fad0c0564454271cba11e6f20c19681534ac (patch) | |
tree | 0a19d07d8b3bdd2574617305c300e404f2ace581 /tooling/danger/request_helper.rb | |
parent | c9f9eec79cab801a50db698f682aacffbedf07f7 (diff) | |
download | gitlab-ce-13.9.0-rc41.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc41
Diffstat (limited to 'tooling/danger/request_helper.rb')
-rw-r--r-- | tooling/danger/request_helper.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tooling/danger/request_helper.rb b/tooling/danger/request_helper.rb new file mode 100644 index 00000000000..d6b99f562f9 --- /dev/null +++ b/tooling/danger/request_helper.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'net/http' +require 'json' + +module Tooling + 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 + + JSON.parse(rsp.body) + end + end + end +end |