X Tutup
Skip to content

Commit 97ea5e7

Browse files
authored
Fix obtained scope mapping to include implied scopes (cli#5256)
* Fix obtained scope mapping to include missing scopes As is, `gotScopes` does not contain certain scopes because it doesn't check for the "special" scopes that imply other scopes. For example, the `repo` scope implies `repo:invite`. * Add a comment in ScopesSuggestion explaining branch statements * Delete whitespace to appease go-fmt
1 parent a9e92c9 commit 97ea5e7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

api/client.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,23 @@ func ScopesSuggestion(resp *http.Response) string {
236236
for _, s := range strings.Split(tokenHasScopes, ",") {
237237
s = strings.TrimSpace(s)
238238
gotScopes[s] = struct{}{}
239-
if strings.HasPrefix(s, "admin:") {
239+
240+
// Certain scopes may be grouped under a single "top-level" scope. The following branch
241+
// statements include these grouped/implied scopes when the top-level scope is encountered.
242+
// See https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps.
243+
if s == "repo" {
244+
gotScopes["repo:status"] = struct{}{}
245+
gotScopes["repo_deployment"] = struct{}{}
246+
gotScopes["public_repo"] = struct{}{}
247+
gotScopes["repo:invite"] = struct{}{}
248+
gotScopes["security_events"] = struct{}{}
249+
} else if s == "user" {
250+
gotScopes["read:user"] = struct{}{}
251+
gotScopes["user:email"] = struct{}{}
252+
gotScopes["user:follow"] = struct{}{}
253+
} else if s == "codespace" {
254+
gotScopes["codespace:secrets"] = struct{}{}
255+
} else if strings.HasPrefix(s, "admin:") {
240256
gotScopes["read:"+strings.TrimPrefix(s, "admin:")] = struct{}{}
241257
gotScopes["write:"+strings.TrimPrefix(s, "admin:")] = struct{}{}
242258
} else if strings.HasPrefix(s, "write:") {

0 commit comments

Comments
 (0)
X Tutup