Skip to content

Commit

Permalink
Merge pull request #700 from rstudio/aron-gitlab-subgroup
Browse files Browse the repository at this point in the history
escape GitLab repositories, as they may have paths
  • Loading branch information
aronatkins authored Jan 9, 2023
2 parents ff99461 + de0a009 commit dcf7fff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
it will either look for a `tar` binary on the `PATH` on Unix, or look for the
system `tar` on Windows. If no binary is found in those locations, it will use
R's internal `tar` implementation. (#648)
- Allow GitLab downloads from repositories having paths (#699).
- Update some RStudio references to Posit.

# Packrat 0.8.1
Expand Down
6 changes: 3 additions & 3 deletions R/available-updates.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ gitlabUpdates <- function(lib.loc = .libPaths()) {
do.call(rbind, enumerate(DESCRIPTIONS, function(x) {
url <- file.path("https://gitlab.com/",
"api/v4/projects/",
paste0(x[, "RemoteUsername"],
"%2F",
x[, "RemoteRepo"]),
URLencode(paste0(x[, "RemoteUsername"],
"/",
x[, "RemoteRepo"]), reserved = TRUE),
"repository",
"archive.tar.gz")
response <- httr::GET(url)
Expand Down
6 changes: 3 additions & 3 deletions R/gitlab.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# - Equivalent to other git provider download functions.
# - Called by `getSourceForPkgRecord` (which manages the lifecycle of
# `destfile`). Responsible for dispatching different download implementations
Expand Down Expand Up @@ -67,11 +68,10 @@ gitlabArchiveUrl <- function(pkgRecord) {
pkgRecord$remote_host <- "gitlab.com"
}

fmt <- "%s/api/v4/projects/%s%%2F%s/repository/archive?sha=%s"
fmt <- "%s/api/v4/projects/%s/repository/archive?sha=%s"
archiveUrl <- sprintf(fmt,
pkgRecord$remote_host,
pkgRecord$remote_username,
pkgRecord$remote_repo,
URLencode(paste0(pkgRecord$remote_username, "/", pkgRecord$remote_repo), reserved = TRUE),
pkgRecord$remote_sha)

protocol <- if (identical(method, "internal")) "http" else "https"
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,29 @@ gitlab_pkg_record <- list(
depends = list()
)

gitlab_subgroup_pkg_record <- list(
name = "museli",
source = "gitlab",
version = "0.1.0",
hash = "abc123",
remote_repo = "museli/strawberries",
remote_username = "breakfaster",
remote_ref = "HEAD",
remote_sha = "abcde12345",
remote_host = "gitlab.com",
depends = list()
)

test_that("gitlabArchiveUrl returns the correct URL", {
mockery::stub(gitlabArchiveUrl, "secureDownloadMethod", "curl")
expect_equal(
gitlabArchiveUrl(gitlab_pkg_record),
"https://gitlab.com/api/v4/projects/breakfaster%2Fmuseli/repository/archive?sha=abcde12345"
)
expect_equal(
gitlabArchiveUrl(gitlab_subgroup_pkg_record),
"https://gitlab.com/api/v4/projects/breakfaster%2Fmuseli%2Fstrawberries/repository/archive?sha=abcde12345"
)
})

test_that("gitlabDownload calls renvDownload in the expected context", {
Expand Down

0 comments on commit dcf7fff

Please sign in to comment.