Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Rodrigues committed Sep 12, 2024
2 parents 00b9a74 + 73deb3a commit 479fa65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions R/nix_hash.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Return the sri hash of a path using `nix hash path --sri path` if Nix is
#' available locally
#' @param repo_url URL to Github repository
#' @param repo_url URL to Git repository
#' @param commit Commit hash (SHA-1)
#' @return list with following elements:
#' - `sri_hash`: string with SRI hash of the NAR serialization of a Github repo
#' at a given deterministic git commit ID (SHA-1)
#' - `deps`: string with R package dependencies separarated by space.
#' @noRd
nix_hash <- function(repo_url, commit) {
if (grepl("github", repo_url)) {
if (grepl("(github)|(gitlab)", repo_url)) {
hash_git(repo_url = repo_url, commit)
} else if (grepl("cran.*Archive.*", repo_url)) {
hash_cran(repo_url = repo_url)
Expand Down Expand Up @@ -180,7 +180,12 @@ hash_git <- function(repo_url, commit) {
} else {
slash <- "/"
}
url <- paste0(repo_url, slash, "archive/", commit, ".tar.gz")

if(grepl("github", repo_url)){
url <- paste0(repo_url, slash, "archive/", commit, ".tar.gz")
} else if(grepl("gitlab", repo_url)){
url <- paste0(repo_url, slash, "-/archive/", commit, ".tar.gz")
}

# list contains `sri_hash` and `deps` elements
list_sri_hash_deps <- hash_url(url)
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-fetchers.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ testthat::test_that("Test fetchgit fails gracefully", {
)
})

testthat::test_that("Test fetchgit works with gitlab packages", {
testthat::expect_equal(
fetchgit(
list(
package_name = "housing",
repo_url = "https://gitlab.com/b-rodrigues/housing/",
commit = "9442aa63d352d3c900f1c6f5a06f7930cdf702c4"
)
),
"\n (pkgs.rPackages.buildRPackage {\n name = \"housing\";\n src = pkgs.fetchgit {\n url = \"https://gitlab.com/b-rodrigues/housing/\";\n rev = \"9442aa63d352d3c900f1c6f5a06f7930cdf702c4\";\n sha256 = \"sha256-3V9XbNbq/YpbgnzkEu3XH7QKSDY8yNNd1vpOeR9ER0w=\";\n };\n propagatedBuildInputs = builtins.attrValues {\n inherit (pkgs.rPackages) \n dplyr\n ggplot2\n janitor\n purrr\n readxl\n rlang\n rvest\n stringr\n tidyr;\n };\n })\n"
)
})



testthat::test_that("Test fetchzip works", {
Expand Down

0 comments on commit 479fa65

Please sign in to comment.