gracefully handle missing admin:org scope

This commit is contained in:
vaindil 2023-05-03 11:28:04 -04:00
parent 8fa69c4915
commit ef30d875b5

View file

@ -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
}