MCPcopy Create free account
hub / github.com/ddev/ddev / HasInvalidGitHubToken

Function HasInvalidGitHubToken

pkg/github/github.go:153–183  ·  view source on GitHub ↗

HasInvalidGitHubToken checks if the response indicates an invalid GitHub token. This is possible if we get 401 or 404 response.

(response any)

Source from the content-addressed store, hash-verified

151// HasInvalidGitHubToken checks if the response indicates an invalid GitHub token.
152// This is possible if we get 401 or 404 response.
153func HasInvalidGitHubToken(response any) error {
154 var httpResp *http.Response
155 switch r := response.(type) {
156 case *github.Response:
157 if r == nil {
158 return nil
159 }
160 httpResp = r.Response
161 case *http.Response:
162 httpResp = r
163 default:
164 return nil
165 }
166 if httpResp == nil || httpResp.Request == nil {
167 return nil
168 }
169 if !isGitHubURL(httpResp.Request.URL.String()) {
170 return nil
171 }
172 _, tokenVariable := GetGitHubToken()
173 if tokenVariable == "" {
174 return nil
175 }
176 if httpResp.StatusCode == http.StatusUnauthorized {
177 return fmt.Errorf("using %s, which is invalid or lacks required permissions", tokenVariable)
178 }
179 if httpResp.StatusCode == http.StatusNotFound {
180 return fmt.Errorf("using %s, which may be invalid or lack permissions", tokenVariable)
181 }
182 return nil
183}

Callers 3

AvailableUpdatesFunction · 0.92
DownloadFileExtendedFunction · 0.92
GetGitHubReleaseFunction · 0.85

Calls 3

isGitHubURLFunction · 0.85
GetGitHubTokenFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected