Skip to content

Commit

Permalink
summary: guard against external scores
Browse files Browse the repository at this point in the history
render_scorecard_summary() and summarize_package_results() have not
been reworked to support external scores.  We use these functions for
MPN.  For non-R packages, we don't yet have a need for these
functions.

Document that these functions don't accept external scores, and add a
custom guard so that a more informative error is given if any results
directory with external scores is passed.
  • Loading branch information
kyleam committed Aug 8, 2024
1 parent a24d8bb commit 79113d7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
13 changes: 11 additions & 2 deletions R/render-scorecard-summary.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

#' Render PDF summary of scorecards
#'
#' @param result_dirs A vector of output directories
#' @param result_dirs A vector of output directories, each one produced by
#' [score_pkg()]. [external_scores] are not supported.
#' @param snapshot A report subtitle indicating the grouping of these packages, such as an MPN snapshot. See details.
#' @param out_dir Output directory for saving scorecard summary. If `NULL`, assumes all `result_dirs` point to the same output directory
#' @inheritParams render_scorecard
Expand All @@ -23,6 +24,8 @@ render_scorecard_summary <- function(result_dirs,
snapshot <- paste('MPN Snapshot', snapshot)
}

assert_no_external(result_dirs)

# Format overall scores and risk
overall_risk_summary <- build_risk_summary(result_dirs, risk_breaks, out_dir)

Expand Down Expand Up @@ -142,7 +145,7 @@ build_risk_summary <- function(result_dirs,
#' @returns a dataframe
#' @export
summarize_package_results <- function(result_dirs){

assert_no_external(result_dirs)
json_paths <- get_result_path(result_dirs, "scorecard.json")

risk_summary_df <- tibble::tibble(
Expand Down Expand Up @@ -170,3 +173,9 @@ summarize_package_results <- function(result_dirs){

return(risk_summary_df)
}

assert_no_external <- function(result_dirs, call = rlang::caller_env()) {
if (any(fs::file_exists(get_result_path(result_dirs, "pkg.json")))) {
abort("External scores are not supported.", call = call)
}
}
3 changes: 2 additions & 1 deletion man/build_risk_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/render_scorecard_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/summarize_package_results.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-summarize-package-results.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ describe("summarize_package_results", {
)
})

it("aborts on external scores", {
rdir <- local_create_external_results()
expect_error(render_scorecard_summary(rdir), "not supported")
})
})

0 comments on commit 79113d7

Please sign in to comment.