| Conditions | 4 |
| Total Lines | 39 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package main |
||
| 15 | func main() { |
||
| 16 | fmt.Print("\033[H\033[2J") //clear screen |
||
| 17 | println("") |
||
| 18 | utils.InfoNotice(`GitHub Token Limit Checker`) |
||
| 19 | utils.InfoNotice(fmt.Sprintf(`v%s`, version)) |
||
| 20 | println("") |
||
| 21 | |||
| 22 | client := &http.Client{} |
||
| 23 | token := githubapi.GetGithubTokenFromEnv() |
||
| 24 | |||
| 25 | rateLimitResponse, err := githubapi.FetchRateLimit(client, token) |
||
| 26 | if err != nil { |
||
| 27 | utils.ErrorNotice(fmt.Sprintf("Error fetching rate limit: %v\n", err)) |
||
| 28 | println("") |
||
| 29 | os.Exit(3) |
||
| 30 | } |
||
| 31 | |||
| 32 | // Default limit is 60 if no token is provided |
||
| 33 | if rateLimitResponse.Resources.Core.Limit == 60 { |
||
| 34 | utils.CautionNotice("Please provide a GitHub token to in the environment variable " + githubapi.DefaultTokenEnv + ".") |
||
| 35 | println("") |
||
| 36 | os.Exit(3) |
||
| 37 | } |
||
| 38 | |||
| 39 | core := rateLimitResponse.Resources.Core |
||
| 40 | resetTime := core.Reset.Time |
||
| 41 | //fmt.Printf("%+v\n", core) |
||
| 42 | |||
| 43 | utils.SuccessNotice(fmt.Sprintf("Using token: %s", utils.ObscureToken(token))) |
||
| 44 | |||
| 45 | if core.Remaining > 0 { |
||
| 46 | utils.SuccessNotice(fmt.Sprintf("You have %d/%d requests left this hour", core.Remaining, core.Limit)) |
||
| 47 | } else { |
||
| 48 | now := time.Now() |
||
| 49 | durationUntilReset := resetTime.Sub(now).Minutes() |
||
| 50 | utils.CautionNotice("You have no requests left.") |
||
| 51 | utils.CautionNotice(fmt.Sprintf("The limit will reset in %.0f minutes at %s", durationUntilReset, resetTime)) |
||
| 52 | } |
||
| 53 | println("") |
||
| 54 | } |
||
| 55 |