Merge pull request #7252 from dawidd6/github-not-json

github: return output if JSON parsing is not desired
This commit is contained in:
Mike McQuaid 2020-04-01 12:44:22 +01:00 committed by GitHub
commit 1cbf261c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -172,7 +172,7 @@ module GitHub
end
end
def open_api(url, data: nil, request_method: nil, scopes: [].freeze)
def open_api(url, data: nil, request_method: nil, scopes: [].freeze, parse_json: true)
# This is a no-op if the user is opting out of using the GitHub API.
return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"]
@ -227,11 +227,11 @@ module GitHub
return if http_code == "204" # No Content
json = JSON.parse output
output = JSON.parse output if parse_json
if block_given?
yield json
yield output
else
json
output
end
rescue JSON::ParserError => e
raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace