Skip to contents
  • github_get_token - returns the user's GitHub personal access token (PAT).

  • github_set_token - defines the user's GitHub PAT by setting the GITHUB_PAT environmental variable. This value will persist until the session ends or gihub_reset_token() is called.

  • github_reset_token - removes the value stored in the GITHUB_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.

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.

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 via gitcreds_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:

Examples

if (FALSE) {
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)
}