github_rate_limit {ghclass} | R Documentation |
Tools for handling GitHub personal access tokens (PAT)
Description
-
github_get_token
- returns the user's GitHub personal access token (PAT). -
github_set_token
- defines the user's GitHub PAT by setting theGITHUB_PAT
environmental variable. This value will persist until the session ends orgihub_reset_token()
is called. -
github_reset_token
- removes the value stored in theGITHUB_PAT
environmental variable. -
github_test_token
- checks if a PAT is valid by attempting to authenticate with the GitHub API. -
github_token_scopes
- returns a vector of scopes granted to the token.
Usage
github_rate_limit()
github_graphql_rate_limit()
github_get_token()
github_set_token(token)
github_reset_token()
github_test_token(token = github_get_token())
github_token_scopes(token = github_get_token())
Arguments
token |
Character. Either the literal token, or the path to a file containing the token. |
Details
This package looks for the personal access token (PAT) in the following places (in order):
Value of
GITHUB_PAT
environmental variable.Any GitHub PAT token(s) stored with
gitcreds
viagitcreds_set()
.
For additional details on creating a GitHub PAT see the usethis vignette on Managing Git(Hub) Credentials. For those who do not wish to read the entire article, the quick start method is to use:
-
usethis::create_github_token()
- to create the token and then, -
gitcreds::gitcreds_set()
- to securely cache the token.
Value
github_get_token()
returns the current PAT as a character string with the gh_pat
class. See gh::gh_token()
for additional details.
github_set_token()
and github_reset_token()
return the result of Sys.setenv()
and
Sys.unsetenv()
respectively.
github_test_token()
invisibly returns a logical value, TRUE
if the test passes,
FALSE
if not.
github_token_scopes()
returns a character vector of granted scopes.
Examples
## Not run:
github_test_token()
github_token_scopes()
(pat = github_get_token())
github_set_token("ghp_BadTokenBadTokenBadTokenBadTokenBadToken")
github_get_token()
github_test_token()
github_set_token(pat)
## End(Not run)