MCPcopy
hub / github.com/apache/devlake / verifyToken

Function verifyToken

backend/plugins/github/token/cmd/test_refresh/main.go:215–235  ·  view source on GitHub ↗
(token string)

Source from the content-addressed store, hash-verified

213}
214
215func verifyToken(token string) error {
216 req, err := http.NewRequest("GET", "https://api.github.com/installation/repositories?per_page=1", nil)
217 if err != nil {
218 return err
219 }
220 req.Header.Set("Authorization", "Bearer "+token)
221 req.Header.Set("Accept", "application/vnd.github+json")
222
223 resp, err := http.DefaultClient.Do(req)
224 if err != nil {
225 return err
226 }
227 defer resp.Body.Close()
228
229 if resp.StatusCode != 200 {
230 body, _ := io.ReadAll(resp.Body)
231 return fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body))
232 }
233 fmt.Printf(" HTTP 200 OK (X-RateLimit-Remaining: %s)\n", resp.Header.Get("X-RateLimit-Remaining"))
234 return nil
235}
236
237func fatal(format string, args ...interface{}) {
238 fmt.Fprintf(os.Stderr, "FATAL: "+format+"\n", args...)

Callers 1

mainFunction · 0.85

Calls 4

DoMethod · 0.80
CloseMethod · 0.65
PrintfMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected