r-lib / gitcreds

Query git credentials from R
https://gitcreds.r-lib.org/
Other
27 stars 10 forks source link

Set token non-interactively #62

Closed royfrancis closed 2 weeks ago

royfrancis commented 2 weeks ago

I am installing packages from GitHub in a docker container and running into rate limiting. How does one set token non-interactively from an environment variable?

I am thinking of something like this..

gitcreds_set(url = "https://github.com", token = Sys.getenv("TOKEN"))

Perhaps, I am missing something.

gaborcsardi commented 2 weeks ago

Do want to use a credential helper on GitHub? Or what are you "setting" the token for?

royfrancis commented 2 weeks ago

I am installing packages from github using remotes::install_github() and I got this error:

HTTP error 403.
API rate limit exceeded for XXX.XXX.XX.XX. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Rate limit remaining: 0/60
Rate limit reset at: 2024-08-28 15:41:38 UTC

To increase your GitHub API rate limit
- Use `usethis::create_github_token()` to create a Personal Access Token.
 Use `gitcreds::gitcreds_set()` to add the token.

which is how I came across gitcreds::gitcreds_set().

But, I just noticed that remotes::install_github() has an argument called auth_token. Perhaps that's what I need.

gaborcsardi commented 2 weeks ago

remotes will pick up the GITHUB_PAT environment variable, no need to use a credential helper.

Or even better, use https://github.com/r-lib/actions/tree/v2-branch/setup-r-dependencies, look at the suggested workflows here: https://github.com/r-lib/actions/tree/v2-branch/examples