-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨
generate_badge_tables
type functions now generate badges statical…
…ly (#117)
- Loading branch information
Showing
12 changed files
with
413 additions
and
373 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: pacta.sit.rep | ||
Title: What the Package Does (One Line, Title Case) | ||
Version: 0.0.0.9008 | ||
Version: 0.0.0.9009 | ||
Authors@R: | ||
person("Jackson", "Hoffart", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0002-8600-5042")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
build_markdown_link <- function(display, path) { | ||
glue::glue("[{display}]({path})") | ||
} | ||
|
||
format_name_badge <- function(repo_path) { | ||
repo_org <- strsplit(repo_path, "/", fixed = TRUE)[[1L]][[1L]] | ||
repo_name <- strsplit(repo_path, "/", fixed = TRUE)[[1L]][[2L]] | ||
|
||
build_markdown_link( | ||
display = repo_name, | ||
path = glue::glue("https://{tolower(repo_org)}.github.io/{repo_name}/") | ||
) | ||
} | ||
|
||
format_lifecycle_badge <- function(lifecycle) { | ||
stopifnot( | ||
lifecycle %in% c("experimental", "stable", "deprecated", "superseded") | ||
) | ||
|
||
lifecycle_badge_url <- switch( | ||
lifecycle, | ||
experimental = "https://lifecycle.r-lib.org/reference/figures/lifecycle-experimental.svg", # nolint: line_length_linter | ||
stable = "https://lifecycle.r-lib.org/reference/figures/lifecycle-stable.svg", # nolint: line_length_linter | ||
deprecated = "https://lifecycle.r-lib.org/reference/figures/lifecycle-deprecated.svg", # nolint: line_length_linter | ||
superseded = "https://lifecycle.r-lib.org/reference/figures/lifecycle-superseded.svg" # nolint: line_length_linter | ||
) | ||
|
||
build_markdown_link( | ||
display = glue::glue( | ||
"![]({lifecycle_badge_url})" | ||
), | ||
path = glue::glue( | ||
"https://lifecycle.r-lib.org/articles/stages.html#{lifecycle}" | ||
) | ||
) | ||
} | ||
|
||
format_status_badge <- function(repo_path, ci_check) { | ||
build_markdown_link( | ||
display = glue::glue( | ||
"![](https://github.com/{repo_path}/actions/workflows/{ci_check}/badge.svg?branch=main)" # nolint: line_length_linter | ||
), | ||
path = glue::glue( | ||
"https://github.com/{repo_path}/actions/workflows/{ci_check}?query=branch%3Amain" # nolint: line_length_linter | ||
) | ||
) | ||
} | ||
|
||
format_coverage_badge <- function(repo_path) { | ||
build_markdown_link( | ||
display = glue::glue( | ||
"![](https://img.shields.io/codecov/c/github/{tolower(repo_path)}/main)" | ||
), | ||
path = glue::glue("https://app.codecov.io/gh/{repo_path}?branch=main") | ||
) | ||
} | ||
|
||
format_version_badge <- function(repo_path) { | ||
build_markdown_link( | ||
display = glue::glue( | ||
"![](https://img.shields.io/github/r-package/v/{tolower(repo_path)}/main?label=version&labelColor=%23444d56&color=%2334d058)" # nolint: line_length_linter | ||
), | ||
path = glue::glue("https://github.com/{repo_path}/blob/main/DESCRIPTION") | ||
) | ||
} | ||
|
||
format_maintainer_badge <- function(repo_path) { | ||
repo_org <- strsplit(repo_path, "/", fixed = TRUE)[[1L]][[1L]] | ||
repo_name <- strsplit(repo_path, "/", fixed = TRUE)[[1L]][[2L]] | ||
|
||
build_markdown_link( | ||
display = glue::glue( | ||
"![](https://img.shields.io/badge/dynamic/json?label=codeowner&query=codeownerInfo.ownersForFile&url=https%3A%2F%2Fgithub.com%2F{tolower(repo_org)}%2F{tolower(repo_name)}%2Fdeferred-metadata%2Fmain%2F.github%2FCODEOWNERS)" # nolint: line_length_linter | ||
), | ||
path = glue::glue( | ||
"https://github.com/{repo_path}/blob/main/.github/CODEOWNERS" | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#' Generate a table with R package information | ||
#' | ||
#' @param repo_vectors A list of named character vectors. Each character vector | ||
#' should contain: | ||
#' * path - the shortpath to the GitHub repository, including organization | ||
#' (e.g. "RMI-PACTA/r2dii.data") | ||
#' * lifecycle - the lifecycle badge status (e.g. "stable", "experimental") | ||
#' * ci_check - the name of the CI check file (e.g. "R-CMD-check.yaml") | ||
# | ||
#' @return A formatted sitrep tibble. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' | ||
#' repos <- list( | ||
#' c( | ||
#' path = "RMI-PACTA/r2dii.data", | ||
#' lifecycle = "stable", | ||
#' ci_check = "R-CMD-check.yaml" | ||
#' ), | ||
#' c( | ||
#' path = "RMI-PACTA/r2dii.plot", | ||
#' lifecycle = "stable", | ||
#' ci_check = "R.yml" | ||
#' ) | ||
#' ) | ||
#' | ||
#' generate_package_table(repos) | ||
generate_package_table <- function(repo_vectors) { | ||
out <- parse_inputs(repo_vectors) | ||
|
||
out <- dplyr::rowwise(out) | ||
out <- dplyr::transmute( | ||
out, | ||
name = format_name_badge(.data[["path"]]), | ||
lifecycle = format_lifecycle_badge(.data[["lifecycle"]]), | ||
status = format_status_badge(.data[["path"]], .data[["ci_check"]]), | ||
coverage = format_coverage_badge(.data[["path"]]), | ||
version = format_version_badge(.data[["path"]]), | ||
maintainer = format_maintainer_badge(.data[["path"]]) | ||
) | ||
dplyr::ungroup(out) | ||
} | ||
|
||
#' Generate a table with workflow information | ||
#' | ||
#' @param repo_vectors A list of named character vectors. Each character vector | ||
#' should contain: | ||
#' * path - the shortpath to the GitHub repository, including organization | ||
#' (e.g. "RMI-PACTA/workflow.transition.monitor") | ||
#' * lifecycle - the lifecycle badge status (e.g. "stable", "experimental") | ||
#' * ci_check - the name of the CI check file | ||
#' (e.g. "build-Docker-image-triggers.yml") | ||
#' | ||
#' @return A formatted sitrep tibble. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' | ||
#' repos <- list( | ||
#' c( | ||
#' path = "RMI-PACTA/workflow.transition.monitor", | ||
#' lifecycle = "stable", | ||
#' ci_check = "build-Docker-image-triggers.yml" | ||
#' ), | ||
#' c( | ||
#' path = "RMI-PACTA/workflow.data.preparation", | ||
#' lifecycle = "stable", | ||
#' ci_check = "docker.yml" | ||
#' ) | ||
#' ) | ||
#' | ||
#' generate_workflow_table(repos) | ||
generate_workflow_table <- function(repo_vectors) { | ||
out <- parse_inputs(repo_vectors) | ||
|
||
out <- dplyr::rowwise(out) | ||
out <- dplyr::transmute( | ||
out, | ||
name = format_name_badge(.data[["path"]]), | ||
lifecycle = format_lifecycle_badge(.data[["lifecycle"]]), | ||
status = format_status_badge(.data[["path"]], .data[["ci_check"]]), | ||
maintainer = format_maintainer_badge(.data[["path"]]) | ||
) | ||
dplyr::ungroup(out) | ||
} | ||
|
||
check_inputs <- function(repo_vectors) { | ||
stopifnot( | ||
is.list(repo_vectors), | ||
all(purrr::map_lgl(repo_vectors, is.character)), | ||
all(purrr::map_lgl(repo_vectors, ~ length(.x) == 3L)), | ||
all( | ||
purrr::map_lgl( | ||
repo_vectors, | ||
~ all(names(.x) %in% c("path", "lifecycle", "ci_check")) | ||
) | ||
) | ||
) | ||
} | ||
|
||
parse_inputs <- function(repo_vectors) { | ||
check_inputs(repo_vectors) | ||
purrr::map_dfr(repo_vectors, ~ tibble::as_tibble(as.list(.))) | ||
} |
Oops, something went wrong.