-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
|
||
format_lifecycle <- function(lifecycle_badge) { | ||
if (is.na(lifecycle_badge)) { | ||
return("No lifecycle badge found.") | ||
} | ||
|
||
desc <- "![Lifecycle]" | ||
link <- "https://lifecycle.r-lib.org/articles/stages.html" | ||
|
||
glue::glue("[{desc}({lifecycle_badge})]({link})") | ||
} | ||
|
||
table_lifecycle <- function(repo_path) { | ||
readme <- get_gh_text_file(repo_path, file_path = "README.md") | ||
|
||
if (is.null(readme)) { | ||
return(NA_character_) | ||
} | ||
|
||
pattern <- "https://img.shields.io/badge/lifecycle-\\S+.svg" | ||
|
||
lifecycle_badge <- readme[grepl(pattern, readme)][[1L]] # nolint: regex_subset_linter | ||
lifecycle_badge <- gsub(".*(https[^)]*\\.svg).*", "\\1", lifecycle_badge) | ||
|
||
if (length(lifecycle_badge) == 0L) { | ||
return(NA_character_) | ||
} | ||
|
||
return(lifecycle_badge) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer:
These changes have very little to do with this PR.
All I have done is copy and paste two functions from the generate_package_table.R
file (which I deleted).
Those were the only two functions that were used anywhere in the package, and since they were used by this function, I felt they should live here.
banks_repos <- list( | ||
c( | ||
path = "RMI-PACTA/r2dii.data", | ||
lifecycle = "stable", | ||
ci_check = "R.yml" | ||
), | ||
c( | ||
path = "RMI-PACTA/r2dii.match", | ||
lifecycle = "stable", | ||
ci_check = "R.yml" | ||
), | ||
c( | ||
path = "RMI-PACTA/r2dii.analysis", | ||
lifecycle = "stable", | ||
ci_check = "R.yml" | ||
), | ||
c( | ||
path = "RMI-PACTA/r2dii.plot", | ||
lifecycle = "experimental", | ||
ci_check = "R.yml" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generate_package_table
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: doesn't table_lifecycle()
aim to scrape the lifecycle status from the repo's README, in which case (assuming it works reliably) in wouldn't be necessary to maintain the lifecycle here?
|
||
test_that("handles empty input", { | ||
empty_input <- character(0) | ||
result <- generate_package_table(empty_input) | ||
|
||
expect_true(tibble::is_tibble(result) && nrow(result) == 0) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the function to handle empty input...
Supersedes #119 |
R/format_badges.R
Outdated
format_badge_url <- function(display, path) { | ||
glue::glue("[{display}]({path})") | ||
} | ||
|
||
format_name_badge <- function(repo_path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the naming convention used is confusing to me. I kinda expected format_badge_url()
to return a "formatted" badge URL (whatever that would be 🤣), but it returns markdown for a linked badge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it build_markdown_link
"![](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 |
There was a problem hiding this comment.
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?
Note to reviewer
Sorry in advance, I know this is a big PR. I am overhauling how most of these functions work entirely.
The simplest way to review that the behavior of this PR functions as expected would be to inspect the rendered README.md
Before
A nightly knit action would reknit the
README.Rmd
and dynamically scrape different files (e.g.DESCRIPTION
,CODEOWNERS
, etc.) within each GitHub repo, and re-render theREADME.md
with the latest badges.This was an over-engineered solution (and the GH action was a pain in the ass to approve)
After this PR
Now, we leverage the dynamic updating of the badge itself at it's source link, and simply use the functions here to format the relevant
.md
URL.latest_sha
column entirely, this added very little actual valuelifecycle
andci_check
argument inputs need to manually be kept up to date with whatever they should point to in the source repo, there is not automated way to check if these are valid (now).nightly_build
action entirely (finally).✅ While I was there, I added some missing repos to the situation report, and updated relevant
lifecycle
andci_check
values as appropriate.Closes #51 #47 #35 #34 #10
Supersedes #33