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

Support for GitLab subgroups #308

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions R/install-gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ gitlab_remote <- function(repo,
remote_download.gitlab_remote <- function(x, quiet = FALSE) {
dest <- tempfile(fileext = paste0(".tar.gz"))

src_root <- build_url(x$host, x$username, x$repo)
src_root <- build_url(x$host, x$username, x$repo, x$subdir)
src <- paste0(src_root, "/repository/archive.tar.gz?ref=", utils::URLencode(x$ref, reserved = TRUE))

if (!quiet) {
message("Downloading GitLab repo ", x$username, "/", x$repo, "@", x$ref,
"\nfrom URL ", src)
message("Downloading GitLab repo ", gsub("/$", "", x$username, "/", x$repo, "/", x$subdir),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you actually getting a trailing slash in the subdirectory or just being cautious? In general I would consider specs with a trailing slash to be invalid input, and actually it seems parse_git_repo() strips them anyway, so you can remove the gsub here and below I think.

> parse_git_repo("foo/bar/baz/")
$username
[1] "foo"

$repo
[1] "bar"

$subdir
[1] "baz"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh now that I look at this again this handles the case when subdir is empty. I think a better approach is to use paste0(c(x$username, x$repo, x$subdir), collapse = "/")

"@", x$ref, "\nfrom URL ", src)
}

download(dest, src, auth_token = x$auth_token, auth_phrase = "private_token=")
Expand Down Expand Up @@ -107,8 +107,8 @@ remote_package_name.gitlab_remote <- function(remote, ...) {

tmp <- tempfile()
src <- build_url(
remote$host, remote$username, remote$repo, "raw",
remote$ref, remote$subdir, "DESCRIPTION")
remote$host, remote$username, remote$repo, remote$subdir,
"raw", remote$ref, "DESCRIPTION")

dest <- tempfile()
res <- download(dest, src, auth_token = remote$auth_token, auth_phrase = "private_token=")
Expand All @@ -120,7 +120,7 @@ remote_package_name.gitlab_remote <- function(remote, ...) {

#' @export
remote_sha.gitlab_remote <- function(remote, ...) {
gitlab_commit(username = remote$username, repo = remote$repo,
gitlab_commit(username = remote$username, subdir = remote$subdir, repo = remote$repo,
host = remote$host, ref = remote$ref, pat = remote$auth_token)
}

Expand All @@ -129,10 +129,13 @@ format.gitlab_remote <- function(x, ...) {
"GitLab"
}

gitlab_commit <- function(username, repo, ref = "master",
gitlab_commit <- function(username, subdir, repo, ref = "master",
host = "gitlab.com", pat = gitlab_pat()) {

url <- build_url(host, "api", "v4", "projects", utils::URLencode(paste0(username, "/", repo), reserved = TRUE), "repository", "commits", ref)
url <- build_url(
host, "api", "v4", "projects",
utils::URLencode(gsub("/$", "", paste(username, repo, subdir, sep = "/")), reserved = TRUE),
"repository", "commits", ref)

tmp <- tempfile()
download(tmp, url, auth_token = pat, auth_phrase = "private_token=")
Expand Down
3 changes: 2 additions & 1 deletion R/install-remote.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ install_remote <- function(remote,
bundle <- remote_download(remote, quiet = quiet)
on.exit(unlink(bundle), add = TRUE)

source <- source_pkg(bundle, subdir = remote$subdir)
if(inherits(remote, "gitlab_remote")) subdir <- NULL else subdir <- remote$subdir
source <- source_pkg(bundle, subdir = subdir)
on.exit(unlink(source, recursive = TRUE), add = TRUE)

update_submodules(source, quiet)
Expand Down