From 833444a646b7cfa2fb2fd1193704c5f0a061e138 Mon Sep 17 00:00:00 2001 From: Patrick R Date: Mon, 18 Aug 2025 14:10:00 +0200 Subject: [PATCH] Adds basic to_simple_codecov and write_simple_codecov functions --- R/codecov.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/R/codecov.R b/R/codecov.R index a242331d..69ef7837 100644 --- a/R/codecov.R +++ b/R/codecov.R @@ -270,3 +270,21 @@ to_codecov <- function(x) { jsonlite::toJSON(na = "null", list("files" = res, "uploader" = jsonlite::unbox("R"))) } + +#' @export +to_simple_codecov <- function(coverage) { + fullLineCoverage <- per_line(coverage) + + data <- Map(function(fileCoverage) { + resultCoverage <- lapply(fileCoverage$coverage, jsonlite::unbox) + names(resultCoverage) <- seq_along(resultCoverage) + return(resultCoverage) + }, fullLineCoverage) + + return(jsonlite::toJSON(list("coverage" = data), na = "null")) +} + +#' @export +write_simple_codecov <- function(coverage, file_name = "simple-codecov.json") { + writeLines(to_simple_codecov(coverage), file_name) +} \ No newline at end of file