Open rorynolan opened 5 months ago
This is already possible, see the gitcreds package for the env var you need to define for your host. E.g. for gitlab.org:
❯ gitcreds::gitcreds_cache_envvar("https://gitlab.org")
[1] "GITHUB_PAT_GITLAB_ORG"
So GITHUB_PAT_GITLAB_ORG
should work, let me know if it doesn't because I can't try it now.
We should document this better.
Thanks for the fast response. Would you be interested in a docs-only PR to mention this?
Does it actually work? :D
It does :-)
Yeah, in that case a PR is welcome. I'll probably also add a function to pak to call gitcreds internally. We should probably also support GIT_TOKEN_*
, e.g. GIT_TOKEN_GITLAB_ORG
, the current scheme is weird for other sites.
The GIT_TOKEN_*
makes sense to me. Do you want to implement that before I make my PR?
Also, would gitcreds
be used only if available? I see it's only in pak
Suggests
.
No, I can do that later, or I can add it to the PR. gitcreds is already included in pak: https://github.com/r-lib/pak/blob/main/src/library/pkgdepends/R/git-auth.R
Dear @gaborcsardi
The method describe here to install packages from private gitlab.com/org repositories does not seem to work for private gitlab instances. See reprex anonymized below
gitcreds::gitcreds_cache_envvar("https://boulangerie.thinkr.fr")
#> [1] "GITHUB_PAT_BOULANGERIE_THINKR_FR"
Sys.setenv(
"GITHUB_PAT_BOULANGERIE_THINKR_FR" = "lefrenchmotdepasseverysecret"
)
pak::pkg_install("git::https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage")
#> Error: ! error in pak subprocess
#> Caused by error:
#> ! Could not solve package dependencies:
#> * git::https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage: ! pkgdepends resolution error for
#> git::https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage.
#> Caused by error:
#> ! Failed to download 'DESCRIPTION' from git repo at
#> <https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage>.
#> Caused by error in `stop(http_error(resp))`:
#> ! Unauthorized (HTTP 401).
pd <- pkgdepends::new_pkg_deps("git::https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage")
pd$solve()
pd$draw()
#> Error: ! Could not solve package dependencies:
#> * git::https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage: ! pkgdepends resolution error for
#> git::https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage.
#> Caused by error:
#> ! Failed to download 'DESCRIPTION' from git repo at
#> <https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage>.
#> Caused by error in `stop(http_error(resp))`:
#> ! Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422).
# Control with remotes to make sur the TOKEN is valid
options(
remotes.git_credentials = git2r::cred_user_pass(
username = "gitlab-ci-token",
password = Sys.getenv("GITHUB_PAT_boulangerie_THINKR_FR")
)
)
remotes::install_git("https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage")
#> Downloading git repo https://boulangerie.thinkr.fr/mygroup/mysubgroup/mypackage
#> Registered S3 methods overwritten by 'callr':
#> method from
#> format.callr_status_error
#> print.callr_status_error
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> * checking for file ‘/tmp/RtmpkTHZEZ/file7cca331d9c4/DESCRIPTION’ ... OK
#> * preparing ‘mypackage’:
#> * checking DESCRIPTION meta-information ... OK
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘mypackage_0.0.1.tar.gz’
#> Installing package into '/home/bob/R/x86_64-pc-linux-gnu-library/4.3'
#> (as 'lib' is unspecified)
Created on 2024-03-13 with reprex v2.1.0
Actually I encounter the errors with gitlab.com
gitcreds::gitcreds_cache_envvar("https://gitlab.com")
#> [1] "GITHUB_PAT_GITLAB_COM"
Sys.setenv(
"GITHUB_PAT_GITLAB_COM" = "lefrenchmotdepasseverysecret"
)
pak::pkg_install("git::https://gitlab.com/antoine120/myprivatepkg")
#> Error: ! error in pak subprocess
#> Caused by error:
#> ! Could not solve package dependencies:
#> * git::https://gitlab.com/antoine120/myprivatepkg: ! pkgdepends resolution error for
#> git::https://gitlab.com/antoine120/myprivatepkg.
#> Caused by error:
#> ! Failed to download 'DESCRIPTION' from git repo at
#> <https://gitlab.com/antoine120/myprivatepkg>.
#> Caused by error in `stop(http_error(resp))`:
#> ! Unauthorized (HTTP 401).
pd <- pkgdepends::new_pkg_deps("git::https://gitlab.com/antoine120/myprivatepkg")
pd$solve()
pd$draw()
#> Error: ! Could not solve package dependencies:
#> * git::https://gitlab.com/antoine120/myprivatepkg: ! pkgdepends resolution error for
#> git::https://gitlab.com/antoine120/myprivatepkg.
#> Caused by error:
#> ! Failed to download 'DESCRIPTION' from git repo at
#> <https://gitlab.com/antoine120/myprivatepkg>.
#> Caused by error in `stop(http_error(resp))`:
#> ! Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422).
# Control with remotes to make sur the TOKEN is valid
options(
remotes.git_credentials = git2r::cred_user_pass(
username = "gitlab-ci-token",
password = Sys.getenv("GITHUB_PAT_GITLAB_COM")
)
)
remotes::install_git("https://gitlab.com/antoine120/myprivatepkg")
#> Downloading git repo https://gitlab.com/antoine120/myprivatepkg
#> Registered S3 methods overwritten by 'callr':
#> method from
#> format.callr_status_error
#> print.callr_status_error
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> * checking for file ‘/tmp/RtmpIs2L18/file86c8627193d4/DESCRIPTION’ ... OK
#> * preparing ‘myprivatepkg’:
#> * checking DESCRIPTION meta-information ... OK
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘myprivatepkg_0.0.0.9000.tar.gz’
#> Installing package into '/home/bob/R/x86_64-pc-linux-gnu-library/4.3'
#> (as 'lib' is unspecified)
Created on 2024-03-13 with reprex v2.1.0
Could you please support
GITLAB_PAT
the same way you supportGITHUB_PAT
? Theremotes
package supports both.pak
is so much faster that right now my workaround is to first clone the gitlab repo and then do apak::local_install()
. I'm happy to have a crack at a PR if you give me some instruction, but also happy for you do do it yourself.Thank you for
pak
, I use it all the time.