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

Conversation

jdhoffa
Copy link
Member

@jdhoffa jdhoffa commented Dec 11, 2024

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 the README.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.

⚠️ I removed the latest_sha column entirely, this added very little actual value
⚠️ the lifecycle and ci_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).
⚠️ I removed the nightly_build action entirely (finally).

✅ While I was there, I added some missing repos to the situation report, and updated relevant lifecycle and ci_check values as appropriate.

Closes #51 #47 #35 #34 #10
Supersedes #33

@jdhoffa jdhoffa added feature a feature request or enhancement breaking change ☠️ API change likely to affect existing code labels Dec 11, 2024
@jdhoffa jdhoffa requested a review from cjyetman December 11, 2024 23:24
@jdhoffa jdhoffa marked this pull request as draft December 11, 2024 23:30
@jdhoffa
Copy link
Member Author

jdhoffa commented Dec 11, 2024

Seems like some linting is failing, unrelated to this PR, addressed in #118.

Marked as draft until #118 is merged

Comment on lines +54 to +83

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)
}
Copy link
Member Author

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.

Comment on lines +31 to +51
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"
)
Copy link
Member Author

Choose a reason for hiding this comment

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

⚠️ Breaking change: I updated the expected input format of datasets to the generate_package_table function.

Copy link
Member

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?

Comment on lines -14 to -20

test_that("handles empty input", {
empty_input <- character(0)
result <- generate_package_table(empty_input)

expect_true(tibble::is_tibble(result) && nrow(result) == 0)
})
Copy link
Member Author

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...

@jdhoffa jdhoffa marked this pull request as ready for review December 12, 2024 00:24
@jdhoffa jdhoffa linked an issue Dec 12, 2024 that may be closed by this pull request
@jdhoffa
Copy link
Member Author

jdhoffa commented Dec 12, 2024

Supersedes #119

Comment on lines 1 to 5
format_badge_url <- function(display, path) {
glue::glue("[{display}]({path})")
}

format_name_badge <- function(repo_path) {
Copy link
Member

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.

Copy link
Member Author

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
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?

@jdhoffa jdhoffa merged commit 704e514 into main Dec 12, 2024
18 checks passed
@jdhoffa jdhoffa deleted the make_sitrep_static branch December 12, 2024 09:40
@jdhoffa jdhoffa mentioned this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ☠️ API change likely to affect existing code feature a feature request or enhancement
Projects
None yet
2 participants