-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a markdown output function #519
Comments
I doubt you want to add {knitr} as a dependency for just this, but x <- covr::package_coverage()
coverages <- covr:::per_line(x)
overall <- covr::percent_coverage(x)
full <- lapply(coverages, function(coverage) {
lines <- coverage$file$file_lines
values <- coverage$coverage
values[is.na(values)] <- ""
data.frame(line = seq_along(lines), source = lines, coverage = values,
stringsAsFactors = FALSE)
})
file_stats <- covr:::compute_file_stats(full)
file_stats$File <- row.names(file_stats)
row.names(file_stats) <- NULL
cov_table <- rbind(data.frame(File = "total", Coverage = sprintf("%.2f%%", overall)), file_stats[, c("File", "Coverage")])
knitr::kable(cov_table, align = "lr") |
this exists in covrpage already |
Let's get this added; it seems really valuable for github actions! If a PR is requested, let me know! |
Here are two very simplistic versions of this. The diff version would probably have to deal with different size reports (number of files) to be broadly useful. @jimhester are you still interested in doing this? coverage_to_markdown <- function(x = package_coverage()) {
x <- coverage_to_list(x = x)
paste0(
"|file|percent|\n| :-- | --: |\n",
paste0("|Total Coverage|", x$totalcoverage, "%|", collapse = "\n"),
paste0("|", names(x$filecoverage), "|", x$filecoverage, "%|", collapse = "\n"),
collapse = "\n"
)
} coverage_diff_to_markdown <- function(head, main) {
x <- coverage_to_list(x = head)
x <- c(x$totalcoverage, x$filecoverage)
y <- coverage_to_list(x = main)
y <- c(y$totalcoverage, y$filecoverage)
diff <- x - y
diff <- ifelse(diff < 0, ":warning: ", diff)
paste0(
paste0("|file|head|main|diff|\n| :-- | --: | --: | --: |\n"),
paste0("|Total Coverage|", x[[1L]], "%|", y[[1L]], "%|", diff[[1L]], "%|", collapse = "\n"),
paste0("|", names(x[-1L]), "|", x[-1L], "%|", y[-1L], "%|", diff[-1L], "%|", collapse = "\n"),
collapse = "\n"
)
} |
an exported function like
cover::markdown_output()
to print a coverage report in markdown, which could then easily be used to add either a Job Summary for a GH Action, or potentially to add a comment to a PR thread with a coverage report.I played around making a more sophisticated
markdown()
function than what @jimhester suggested here. In my GH Action, I ran a coverage test on both HEAD and on MAIN and generated a markdown coverage report comparing the diff. (This is quick and dirty, but maybe of interest for ideas.)I've experimented with this a bit, and I have been successful with both.
job summary looked like this:
PR thread comment looks like:
example markdown table for a PR thread comment:
renders as:
Coverage Report
Originally posted by @jimhester in #207 (comment)
The text was updated successfully, but these errors were encountered: