MCPcopy
hub / github.com/cli/cli / GetScopes

Function GetScopes

pkg/cmd/auth/shared/oauth_scopes.go:35–62  ·  view source on GitHub ↗

GetScopes performs a GitHub API request and returns the value of the X-Oauth-Scopes header.

(httpClient httpClient, hostname, authToken string)

Source from the content-addressed store, hash-verified

33
34// GetScopes performs a GitHub API request and returns the value of the X-Oauth-Scopes header.
35func GetScopes(httpClient httpClient, hostname, authToken string) (string, error) {
36 apiEndpoint := ghinstance.RESTPrefix(hostname)
37
38 req, err := http.NewRequest("GET", apiEndpoint, nil)
39 if err != nil {
40 return "", err
41 }
42
43 req.Header.Set("Authorization", "token "+authToken)
44
45 res, err := httpClient.Do(req)
46 if err != nil {
47 return "", err
48 }
49
50 defer func() {
51 // Ensure the response body is fully read and closed
52 // before we reconnect, so that we reuse the same TCPconnection.
53 _, _ = io.Copy(io.Discard, res.Body)
54 res.Body.Close()
55 }()
56
57 if res.StatusCode != 200 {
58 return "", api.HandleHTTPError(res)
59 }
60
61 return res.Header.Get("X-Oauth-Scopes"), nil
62}
63
64// HasMinimumScopes performs a GitHub API request and returns an error if the token used in the request
65// lacks the minimum required scopes for performing API operations with gh.

Callers 3

refreshRunFunction · 0.92
buildEntryFunction · 0.92
HasMinimumScopesFunction · 0.85

Calls 7

RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected