diff options
| author | Mike McQuaid | 2016-03-25 18:35:06 +0800 |
|---|---|---|
| committer | Xu Cheng | 2016-03-28 18:22:47 +0800 |
| commit | 6135da800e4f93ded3a5a331d0efa691f4822afb (patch) | |
| tree | ba02645a64a9a866bb77bcb586f07addee060c7c /Library/Homebrew/cmd/gist-logs.rb | |
| parent | ca2abb2be6686a8f2e7c64f5d334ab70be97a1b7 (diff) | |
| download | brew-6135da800e4f93ded3a5a331d0efa691f4822afb.tar.bz2 | |
utils, gist-logs: improve/fix credential handling.
The API used (`Net::HTTP::Post`) does not handle basic authentication
credentials in the same way as `open` so fix both cases so they work.
Also, do some general usability tweaks to point out to people what could
be wrong with their tokens or credentials to help them debug.
Closes Homebrew/homebrew#50410.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/cmd/gist-logs.rb')
| -rw-r--r-- | Library/Homebrew/cmd/gist-logs.rb | 19 |
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 |
