Skip to content
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

generate_badge_tables type functions now generate badges statically #117

Merged
merged 23 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/workflows/nightly-readme-build.yml

This file was deleted.

2 changes: 1 addition & 1 deletion DESCRIPTION
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"))
Expand Down
79 changes: 79 additions & 0 deletions R/format_badges.R
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the relevant repos use main not master, so this is not a problem?

)
)
}

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&amp;labelColor=%23444d56&amp;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&amp;query=codeownerInfo.ownersForFile&amp;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"
)
)
}
107 changes: 107 additions & 0 deletions R/generate_badge_tables.R
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(.)))
}
Loading
Loading