aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/gist-logs.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cmd/gist-logs.rb')
-rw-r--r--Library/Homebrew/cmd/gist-logs.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb
index acc9a10ea..5954c031e 100644
--- a/Library/Homebrew/cmd/gist-logs.rb
+++ b/Library/Homebrew/cmd/gist-logs.rb
@@ -37,12 +37,12 @@ module Homebrew
if ARGV.include?("--new-issue") || ARGV.switch?("n")
auth = :AUTH_TOKEN
- unless GitHub.api_credentials
+ if GitHub.api_credentials_type == :none
puts "You can create a personal access token: https://github.com/settings/tokens"
puts "and then set HOMEBREW_GITHUB_API_TOKEN as authentication method."
puts
- auth = :AUTH_BASIC
+ auth = :AUTH_USER_LOGIN
end
url = new_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url, auth)
@@ -118,9 +118,21 @@ module Homebrew
headers = GitHub.api_headers
headers["Content-Type"] = "application/json"
+ basic_auth_credentials = nil
+ if auth != :AUTH_USER_LOGIN
+ token, username = GitHub.api_credentials
+ case GitHub.api_credentials_type
+ when :keychain
+ basic_auth_credentials = [username, token]
+ when :environment
+ headers["Authorization"] = "token #{token}"
+ end
+ end
+
request = Net::HTTP::Post.new(path, headers)
+ request.basic_auth(*basic_auth_credentials) if basic_auth_credentials
- login(request) if auth == :AUTH_BASIC
+ login(request) if auth == :AUTH_USER_LOGIN
request.body = Utils::JSON.dump(data)
request
@@ -133,6 +145,7 @@ module Homebrew
when Net::HTTPCreated
Utils::JSON.load get_body(response)
else
+ GitHub.api_credentials_error_message(response)
raise "HTTP #{response.code} #{response.message} (expected 201)"
end
end