Skip to content

Commit

Permalink
Use new orderly2 parse format, improve error message if 0 orderly scr…
Browse files Browse the repository at this point in the history
…ipts found
  • Loading branch information
r-ash committed Mar 5, 2024
1 parent 00dfba4 commit 8a8ade4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions R/reports.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
get_report_parameters <- function(name, ref, root) {
path <- get_orderly_script_path(name, ref, root)
sha <- git_ref_to_sha(ref, repo = root, check = TRUE)
sha <- gert::git_commit_id(ref, repo = root)
contents <- git_run(
c("show", sprintf("%s:%s", sha, path)), repo = root, check = TRUE
)$output
exprs <- parse(text = contents)
orderly2::orderly_parse(exprs = exprs, filename = basename(path))$parameters
orderly2::orderly_parse_expr(exprs, filename = basename(path))$parameters
}


get_orderly_script_path <- function(name, ref, root) {
contents <- gert::git_ls(root, ref = ref)
re <- sprintf("^src/%s/(%s|orderly)\\.R$", name, name)
matches <- grep(re, contents$path, value = TRUE, perl = TRUE)
if (length(matches) > 1) {
if (length(matches) != 1) {
num <- length(matches)
cli::cli_abort(
c("Found {num} valid orderly script{?s}. There must only be one.",
c("Found {num} valid orderly script{?s}. There must be one and only one.",
setNames(matches, rep("*", length(matches)))))
}
matches
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-reports.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ test_that("can get orderly script name", {
file.path(root, "src", "data", "orderly.R"))
git_add_and_commit(root)

expect_error(get_orderly_script_path("data", "HEAD", root),
"Found 2 valid orderly scripts. There must only be one.")
expect_error(
get_orderly_script_path("data", "HEAD", root),
"Found 2 valid orderly scripts. There must be one and only one.")
})


Expand Down

0 comments on commit 8a8ade4

Please sign in to comment.