Skip to content

Commit

Permalink
Add back build_universe() guardrail
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Feb 29, 2024
1 parent 221e8de commit 42d3221
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
19 changes: 11 additions & 8 deletions R/build_universe.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ build_universe <- function(input = getwd(), output = "packages.json") {
assert_character_scalar(output, "invalid output")
assert_file(input)
packages <- list.files(input, all.files = FALSE, full.names = TRUE)
urls <- vapply(
X = packages,
FUN = readLines,
FUN.VALUE = character(1L),
USE.NAMES = FALSE,
warn = FALSE
)
contents <- lapply(X = packages, FUN = read_package_entry)
out <- data.frame(
package = trimws(basename(packages)),
url = trimws(urls),
url = trimws(unlist(contents, use.names = FALSE)),
branch = "*release"
)
if (!file.exists(dirname(output))) {
Expand All @@ -31,3 +25,12 @@ build_universe <- function(input = getwd(), output = "packages.json") {
jsonlite::write_json(x = out, path = output)
invisible()
}

read_package_entry <- function(package) {
out <- readLines(con = package, warn = FALSE)
message <- assert_package(name = basename(package), url = out)
if (!is.null(message)) {
stop(message, call. = FALSE)
}
out
}
16 changes: 16 additions & 0 deletions tests/test-build_universe.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ exp <- list(
stopifnot(identical(json, exp))
unlink(packages, recursive = TRUE)
unlink(universe)

packages <- tempfile()
dir.create(packages)
writeLines("https://github.com/r-lib/gh", file.path(packages, "gh"))
writeLines(
c("https://github.com/jeroen/jsonlite", "bad"),
file.path(packages, "jsonlite")
)
universe <- file.path(tempfile(), "out")
out <- try(
r.releases.utils::build_universe(input = packages, output = universe),
silent = TRUE
)
stopifnot(inherits(out, "try-error"))
unlink(packages, recursive = TRUE)
unlink(universe)

0 comments on commit 42d3221

Please sign in to comment.