From ef30d875b503a295cd7d3e11678f858d49eb80d0 Mon Sep 17 00:00:00 2001 From: vaindil Date: Wed, 3 May 2023 11:28:04 -0400 Subject: [PATCH] gracefully handle missing admin:org scope --- pkg/cmd/ruleset/shared/http.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cmd/ruleset/shared/http.go b/pkg/cmd/ruleset/shared/http.go index 2276f8989..4899369bf 100644 --- a/pkg/cmd/ruleset/shared/http.go +++ b/pkg/cmd/ruleset/shared/http.go @@ -1,8 +1,10 @@ package shared import ( + "errors" "fmt" "net/http" + "strings" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/ghrepo" @@ -58,6 +60,10 @@ func listRulesets(httpClient *http.Client, query string, variables map[string]in var data RulesetResponse err := client.GraphQL(host, query, variables, &data) if err != nil { + if strings.Contains(err.Error(), "requires one of the following scopes: ['admin:org']") { + return nil, errors.New("the 'admin:org' scope is required to view organization rulesets, try running 'gh auth refresh -s admin:org'") + } + return nil, err }