From f15681ccd9ae827551906c51c88bf64dd6634333 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Wed, 3 Feb 2021 01:00:43 +0530 Subject: [PATCH] utils/github: fix false positive API credential error --- Library/Homebrew/utils/github.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index aacf78d421..75fd5ae3d1 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -150,13 +150,11 @@ module GitHub return if response_headers.empty? scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ") - return if scopes.present? - - needed_human_scopes = needed_scopes.join(", ") + needed_scopes = Set.new(scopes || needed_scopes) credentials_scopes = response_headers["x-oauth-scopes"] - return if needed_human_scopes.blank? && credentials_scopes.blank? + return if needed_scopes.subset?(Set.new(credentials_scopes.to_s.split(", "))) - needed_human_scopes = "none" if needed_human_scopes.blank? + needed_scopes = needed_scopes.to_a.join(", ").presence || "none" credentials_scopes = "none" if credentials_scopes.blank? what = case api_credentials_type @@ -168,7 +166,7 @@ module GitHub @api_credentials_error_message ||= onoe <<~EOS Your #{what} credentials do not have sufficient scope! - Scopes required: #{needed_human_scopes} + Scopes required: #{needed_scopes} Scopes present: #{credentials_scopes} Create a personal access token: #{ALL_SCOPES_URL}