| Title: | Test Coverage Summary on 'GitHub' |
|---|---|
| Description: | Calculate test coverage data with 'covr', extract insights, and post them as comments on 'GitHub' pull requests. |
| Authors: | Dragoș Moldovan-Grünfeld [aut, cre] |
| Maintainer: | Dragoș Moldovan-Grünfeld <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9039 |
| Built: | 2026-05-18 21:12:11 UTC |
| Source: | https://github.com/dragosmg/covr2gh |
Compose a coverage comment
compose_comment( head_coverage, base_coverage, repo, pr_number, diff_cov_target = NULL )compose_comment( head_coverage, base_coverage, repo, pr_number, diff_cov_target = NULL )
head_coverage |
(coverage) active / current branch ( |
base_coverage |
(coverage) base / target branch coverage (coverage for
the branch merging into). The output of |
repo |
(character) the repository name in the GitHub format
( |
pr_number |
(integer) the PR number |
diff_cov_target |
(numeric) minimum accepted diff coverage. Defaults to
|
a character scalar with the content of the GitHub comment
## Not run: coverage_head <- covr::package_coverage() system("git checkout main") coverage_main <- covr::package_coverage() compose_comment( head_coverage = coverage_head, base_coverage = coverage_main, repo = "<owner>/<repo>", pr_number = 3 ) ## End(Not run)## Not run: coverage_head <- covr::package_coverage() system("git checkout main") coverage_main <- covr::package_coverage() compose_comment( head_coverage = coverage_head, base_coverage = coverage_main, repo = "<owner>/<repo>", pr_number = 3 ) ## End(Not run)
Generate a coverage badge
generate_badge(value)generate_badge(value)
value |
(a numeric scalar) percentage coverage. |
a SVG string invisibly
generate_badge(5) generate_badge(48)generate_badge(5) generate_badge(48)
post_comment() first checks if a "known" covr2gh comment exists on the
target pull request. If it does, then it updates it, if it doesn't, then a
a new comment is posted.
post_comment(body, repo, pr_number, update = TRUE)post_comment(body, repo, pr_number, update = TRUE)
body |
(character scalar) the content of the body of the message. |
repo |
(character) the repository name in the GitHub format
( |
pr_number |
(integer) the PR number |
update |
(logical) update an existing comment or post a new one.
Defaults to |
Users can also choose to always post a new comment (this always deletes the previous one).
a gh_response object containing the API response
## Not run: post_comment( "this is amazing", repo = "<owner>/<repo>", pr_number = 3 ) ## End(Not run)## Not run: post_comment( "this is amazing", repo = "<owner>/<repo>", pr_number = 3 ) ## End(Not run)
Sets up a GitHub Actions workflow that calculates and reports test coverage:
uses covr::package_coverage().
on a pull request:
calculates test coverage for head.
builds a badge (for use in the commit message).
initialises or switches to the covr2gh-storage branch.
switches to base branch and calculates test coverage.
compares coverage for head and base and posts a comment with the main findings.
uploads base coverage and badge as artefacts.
posts a workflow summary.
on a push to main:
calculates test coverage for head and creates a badge.
switches to or creates the covr2gh-storage branch.
commits badge (referenced in the README).
use_covr2gh_action(badge = TRUE)use_covr2gh_action(badge = TRUE)
badge |
(logical) should a badge be added to README? Defaults to |
use_covr2gh_action() wraps usethis::use_github_action().
## Not run: use_covr2gh_action() ## End(Not run)## Not run: use_covr2gh_action() ## End(Not run)
Inserts the markdown text for a coverage badge in the usethis block (between
<!-- badges: start --> and <!-- badges: end -->). The src URL for the
badge SVG points to a storage branch in the repo(covr2gh-storage). The link
out points to the actions workflow page.
use_covr2gh_badge()use_covr2gh_badge()
## Not run: use_covr2gh_badge() ## End(Not run)## Not run: use_covr2gh_badge() ## End(Not run)