Skip to content

Commit

Permalink
expand test-dl-repo to include sub-dirs for #64
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Nov 11, 2024
1 parent 290a9a4 commit 5641802
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
32 changes: 20 additions & 12 deletions R/dl_repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)

Check warning on line 56 in R/dl_repo.R

View check run for this annotation

Codecov / codecov/patch

R/dl_repo.R#L56

Added line #L56 was not covered by tests
}
u <- paste0 (
"https://",
paste0 (domains [seq_len (i - 1)], collapse = "/")
)
}

return (u)
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-dl-repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

0 comments on commit 5641802

Please sign in to comment.