Welcome to mirror list, hosted at ThFree Co, Russian Federation.

request_helper.rb « danger « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 06da4ed9ad36b71a850b193e3adf3c4da758fd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

        JSON.parse(rsp.body)
      end
    end
  end
end