Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renv does not see gitcreds PAT #2095

Open
stefanocoretta opened this issue Feb 22, 2025 · 4 comments
Open

renv does not see gitcreds PAT #2095

stefanocoretta opened this issue Feb 22, 2025 · 4 comments

Comments

@stefanocoretta
Copy link

Hi! I have installed gitcreds and set a token with gitcreds_set(), made sure the environment does not have a GITHUB_PAT set and set git config --global credential.helper osxkeychain, but renv still returns this message:

- GitHub authentication credentials are not available.
- Please set GITHUB_PAT, or ensure the 'gitcreds' package is installed.

macOS: Sequoia 15.3.1
R: 4.2.2
renv: 1.1.1

@stefanocoretta
Copy link
Author

Ah, buried in the usethis docs (https://usethis.r-lib.org/articles/git-credentials.html#what-about-the-remotes-and-pak-packages) there is a hint that remotes (used by renv) does not see the credentials unless it's in the GITHUB_PAT and you can temporarily set that in an R session by "tickling" gitcreds with gitcreds::gitcreds_get().

It would be useful if this was mentioned in the renv docs too or that a more specific pointer is added in the message - See https://usethis.r-lib.org/articles/git-credentials.html for more details..

@kevinushey
Copy link
Collaborator

renv/R/download.R

Lines 552 to 580 in 3ef2009

if (gitcreds) {
# ensure URL has protocol pre-pended
url <- renv_retrieve_origin(url)
# request credentials for URL
dlog("download", "requesting git credentials for url '%s'", url)
creds <- tryCatch(
gitcreds::gitcreds_get(url),
error = function(cnd) {
warning(conditionMessage(cnd))
NULL
}
)
# use if available
if (!is.null(creds))
return(creds$password)
}
# ask the user to set a GITHUB_PAT
if (once()) {
writeLines(c(
"- GitHub authentication credentials are not available.",
"- Please set GITHUB_PAT, or ensure the 'gitcreds' package is installed.",
"- See https://usethis.r-lib.org/articles/git-credentials.html for more details."
))
}

You can try using the R debugger to step through around there to see why your credentials aren't found.

@stefanocoretta
Copy link
Author

Thanks! I tried that and gitcreds::gitcreds_get(url) returns NULL with url "https://api.github.com/repos/stefanocoretta/coretta2018itapol"

Error in throw(new_error("gitcreds_no_credentials", url = url)) : 
  Could not find any credentials

I think gitcreds does not recognise api.github.com as github.com. But how come the url starts with "https://api.github.com"?

If I then just do gitcreds::gitcreds_get() the creds are found and if I then proceed with gitcreds::gitcreds_get(url) they are also found. This might be a gitcreds issue maybe?

@kevinushey
Copy link
Collaborator

renv uses the GitHub API endpoints in a number of places, e.g. when downloading package sources and resolving remote specifications, and those go through https://api.github.com. This might be a gitcreds issue, but I'm not totally certain -- perhaps renv should strip the api. prefix from the URL when resolving credentials?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants