From 5641802dca03434a188161a252c735de6c439119 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 11 Nov 2024 14:31:25 +0100 Subject: [PATCH] expand test-dl-repo to include sub-dirs for #64 --- DESCRIPTION | 2 +- R/dl_repo.R | 32 ++++++++++++++++++++------------ codemeta.json | 2 +- tests/testthat/test-dl-repo.R | 12 ++++++++++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 94a54b0..fc70746 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: roreviewapi Title: Plumber API to report package structure and function -Version: 0.1.0.065 +Version: 0.1.0.066 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/dl_repo.R b/R/dl_repo.R index 48fb82f..076eb02 100644 --- a/R/dl_repo.R +++ b/R/dl_repo.R @@ -7,18 +7,8 @@ #' @export dl_gh_repo <- function (u, branch = NULL) { - subdir <- get_subdir_from_url (u) - if (length (subdir) > 0L) { - domains <- strsplit (u, "\\/+") [[1]] [-1] # rm "https" - i <- which (domains == "tree") - if (length (i) == 0L) { - stop ("URL [", u, "] is improperly formatted.", call. = FALSE) - } - u <- paste0 ( - "https://", - paste0 (domains [seq_len (i - 1)], collapse = "/") - ) - } + u <- rm_subdir_from_url (u) + repo <- utils::tail (strsplit (u, "/") [[1]], 1) org <- utils::tail (strsplit (u, "/") [[1]], 2) [1] @@ -55,3 +45,21 @@ dl_gh_repo <- function (u, branch = NULL) { return (path) } + +rm_subdir_from_url <- function (u) { + + subdir <- get_subdir_from_url (u) + if (length (subdir) > 0L) { + domains <- strsplit (u, "\\/+") [[1]] [-1] # rm "https" + i <- which (domains == "tree") + if (length (i) == 0L) { + stop ("URL [", u, "] is improperly formatted.", call. = FALSE) + } + u <- paste0 ( + "https://", + paste0 (domains [seq_len (i - 1)], collapse = "/") + ) + } + + return (u) +} diff --git a/codemeta.json b/codemeta.json index 2594d49..620a45a 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/roreviewapi", "issueTracker": "https://github.com/ropensci-review-tools/roreviewapi/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.0.065", + "version": "0.1.0.066", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-dl-repo.R b/tests/testthat/test-dl-repo.R index 5bc06ee..b040e5d 100644 --- a/tests/testthat/test-dl-repo.R +++ b/tests/testthat/test-dl-repo.R @@ -12,3 +12,15 @@ test_that ("dl_repo function", { expect_type (path, "character") expect_true (fs::dir_exists (path)) }) + +test_that ("other path fns", { + repourl <- "https://github.com/ropensci-review-tools/issues-tests/tree/branch/subdir" + expect_equal (get_branch_from_url (repourl), "branch") + repourl <- "https://github.com/ropensci-review-tools/issues-tests/tree/main/subdir" + expect_null (get_branch_from_url (repourl)) + + expect_equal (get_subdir_from_url (repourl), "subdir") + + u <- rm_subdir_from_url (repourl) + expect_equal (u, gsub ("\\/tree.*$", "", repourl)) +})