remotes icon indicating copy to clipboard operation
remotes copied to clipboard

`install_gitlab()` example fails when GITLAB_PAT in .Renviron

Open richard-davey-arcadisgen opened this issue 4 years ago • 4 comments

I have a GITLAB_PAT environment variable defined in my .Renviron file. When I execute the code example for install_gitlab() it fails:

install_gitlab("jimhester/covr")
#> Using GitLab PAT from envvar GITLAB_PAT
#> Error: Failed to install 'covr' from GitLab:
#> cannot open URL 'https://gitlab.com/api/v4/projects/jimhester%2Fcovr/repository/commits/HEAD'

However, if I force the function not to use the auth_token then it works

remotes::install_gitlab("jimhester/covr", auth_token = NULL)
#> Downloading GitLab repo jimhester/covr@HEAD
#> from URL https://gitlab.com/api/v4/projects/1486846/repository/archive.tar.gz?sha=HEAD

Therefore, I think there is a bug with the presence of GITLAB_PAT. As an aside, this token was generated for a private repo and I am also unable to install from this location.

I am seeing the same error with my private gitlab repos on a self-hosted gitlab instance.

jonathan-g avatar Jul 20 '21 04:07 jonathan-g

Still an issue on our end too

jackbrookes avatar Sep 15 '21 10:09 jackbrookes

I think this is due to wrong permissions with the PAT. Can you give a try with read_api and read_repository scope ?

Had a similar behavior but with some more permissions this seems to work.

Hyurt avatar Nov 18 '21 08:11 Hyurt

install_gitlab("jimhester/covr")

default uses auth_token = gitlab_pat(quiet). So in this instance, whatever (likely a bad token) is in GITLAB_PAT env var is set to auth_token for remote. NB: it doesn't matter if repo is public or private.

This makes it so the remote has auth_token = NULL

install_gitlab("jimhester/covr", auth_token = NULL)

Reprex

Sys.setenv(GITLAB_PAT = "bad")
remotes::install_gitlab("jimhester/covr")
#> Using GitLab PAT from envvar GITLAB_PAT
#> Error: Failed to install 'unknown package' from GitLab:
#>   cannot open URL 'https://gitlab.com/api/v4/projects/jimhester%2Fcovr/repository/files/DESCRIPTION/raw?ref=HEAD'

Sys.unsetenv("GITLAB_PAT")
remotes::install_gitlab("jimhester/covr", upgrade = FALSE)
#> Downloading GitLab repo jimhester/covr@HEAD
#> from URL https://gitlab.com/api/v4/projects/1486846/repository/archive.tar.gz?sha=HEAD
#> * checking for file ‘/tmp/RtmpJoJ6go/remotes20166dfee185/covr-HEAD-eacb1d9cbe3c8f12b5c681506119df74b336986f/DESCRIPTION’ ... OK
#> * preparing ‘covr’:
#> * checking DESCRIPTION meta-information ... OK
#> * cleaning src
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> Removed empty directory ‘covr/revdep’
#> Omitted ‘LazyData’ from DESCRIPTION
#> * building ‘covr_2.2.0.tar.gz’
#> Installing package into '/home/gcer/R'
#> (as 'lib' is unspecified)

Created on 2023-06-02 with reprex v2.0.2

muschellij2 avatar Jun 02 '23 18:06 muschellij2