gh (version 1.0.1)

gh_whoami: Info on current GitHub user and token

Description

Reports wallet name, GitHub login, and GitHub URL for the current authenticated user, the first bit of the token, and the associated scopes.

Usage

gh_whoami(.token = NULL, .api_url = NULL, .send_headers = NULL)

Arguments

.token

Authentication token.

.api_url

Github API url (default: https://api.github.com). Used if endpoint just contains a path.

.send_headers

Named character vector of header field values (excepting Authorization, which is handled via .token). This can be used to override or augment the defaults, which are as follows: the Accept field defaults to "application/vnd.github.v3+json" and the User-Agent field defaults to "https://github.com/r-lib/gh". This can be used to, e.g., provide a custom media type, in order to access a preview feature of the API.

Value

A gh_response object, which is also a list.

Details

Get a personal access token for the GitHub API from https://github.com/settings/tokens and select the scopes necessary for your planned tasks. The repo scope, for example, is one many are likely to need. The token itself is a string of 40 letters and digits. You can store it any way you like and provide explicitly via the .token argument to gh().

However, many prefer to define an environment variable GITHUB_PAT (or GITHUB_TOKEN) with this value in their .Renviron file. Add a line that looks like this, substituting your PAT:

GITHUB_PAT=8c70fd8419398999c9ac5bacf3192882193cadf2

Put a line break at the end! If you<U+2019>re using an editor that shows line numbers, there should be (at least) two lines, where the second one is empty. Restart R for this to take effect. Call gh_whoami() to confirm success.

To get complete information on the authenticated user, call gh("/user").

For token management via API (versus the browser), use the OAuth Authorizations API. This API requires Basic Authentication using your username and password, not tokens, and is outside the scope of the gh package.

Examples

Run this code
# NOT RUN {
gh_whoami()

## explicit token + use with GitHub Enterprise
gh_whoami(.token = "8c70fd8419398999c9ac5bacf3192882193cadf2",
          .api_url = "https://github.foobar.edu/api/v3")
# }

Run the code above in your browser using DataLab