From f19a833900d8f0ad6a87162f7e55ff76d5e1c449 Mon Sep 17 00:00:00 2001 From: olivroy Date: Sat, 18 May 2024 11:03:09 -0400 Subject: [PATCH 1/5] Add use_r_universe_badge() function! --- NAMESPACE | 1 + NEWS.md | 2 ++ R/badge.R | 33 +++++++++++++++++++++++++++++++++ man/badges.Rd | 12 ++++++++++++ tests/testthat/_snaps/badge.md | 10 ++++++++++ tests/testthat/test-badge.R | 10 ++++++++++ 6 files changed, 68 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 3648d5db7..6f72b7215 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -168,6 +168,7 @@ export(use_pkgdown_travis) export(use_posit_cloud_badge) export(use_proprietary_license) export(use_r) +export(use_r_universe_badge) export(use_rcpp) export(use_rcpp_armadillo) export(use_rcpp_eigen) diff --git a/NEWS.md b/NEWS.md index d7f3a70a0..d696594e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* New `use_r_universe_badge()` to indicate which version of your package is available on [R-universe](https://r-universe.dev) (@olivroy, #1883). + * The `ui_*()` functions have been marked as [superseded](https://lifecycle.r-lib.org/articles/stages.html#superseded). External users of these functions are encouraged to use the diff --git a/R/badge.R b/R/badge.R index 23868bc3c..07bde1846 100644 --- a/R/badge.R +++ b/R/badge.R @@ -16,6 +16,8 @@ #' available on CRAN, powered by #' * `use_lifecycle_badge()`: badge declares the developmental stage of a #' package according to . +#' * `use_r_universe_badge()` indicates what version of your package is available +#' on R-universe `r lifecycle::badge("experimental")`. #' * `use_binder_badge()`: badge indicates that your repository can be launched #' in an executable environment on #' * `use_posit_cloud_badge()`: badge indicates that your repository can be launched @@ -35,6 +37,13 @@ #' \dontrun{ #' use_cran_badge() #' use_lifecycle_badge("stable") +#' # If you don't have a GitHub repo, or needs something extra +#' # you can create the r-universe badge +#' use_badge( +#' "R-universe", +#' "https://{organization}.r-universe.dev/badges/{package})", +#' "https://{organization}.r-universe.dev/{package}" +#' ) #' } NULL @@ -138,7 +147,31 @@ use_binder_badge <- function(ref = git_default_branch(), urlpath = NULL) { invisible(TRUE) } +#' @rdname badges +#' @export +use_r_universe_badge <- function() { + check_is_package("use_r_universe_badge()") + # The r-universe link needs the package name + organization. + pkg <- project_name() + url <- tryCatch(github_url(pkg), error = function(e) NULL) + # in order to get organization + desc <- proj_desc() + urls <- desc$get_urls() + dat <- parse_github_remotes(c(urls, url)) + gh_org <- unique(dat$repo_owner[!is.na(dat$repo_owner)]) + if (length(gh_org) == 0L) { + ui_abort(c( + "{.pkg {pkg}} must have a repo URL in DESCRITPION to create a badge.", + "Use {.fn usethis::use_badge} if you have a different configuration.", + "If {.pkg {pkg}} is on CRAN, you can also see {.url cran.dev/{pkg}} + for a redirect to the r-universe homepage." + )) + } + src <- glue("https://{gh_org}.r-universe.dev/badges/{pkg}") + href <- glue("https://{gh_org}.r-universe.dev/{pkg}") + use_badge("R-universe", href, src) +} #' @rdname badges #' @param url A link to an existing [Posit Cloud](https://posit.cloud) #' project. See the [Posit Cloud diff --git a/man/badges.Rd b/man/badges.Rd index 831a574c1..d2d5ec851 100644 --- a/man/badges.Rd +++ b/man/badges.Rd @@ -7,6 +7,7 @@ \alias{use_bioc_badge} \alias{use_lifecycle_badge} \alias{use_binder_badge} +\alias{use_r_universe_badge} \alias{use_posit_cloud_badge} \alias{use_rscloud_badge} \title{README badges} @@ -21,6 +22,8 @@ use_lifecycle_badge(stage) use_binder_badge(ref = git_default_branch(), urlpath = NULL) +use_r_universe_badge() + use_posit_cloud_badge(url) use_rscloud_badge(url) @@ -60,6 +63,8 @@ ensure your badge block starts with a line containing only available on CRAN, powered by \url{https://www.r-pkg.org} \item \code{use_lifecycle_badge()}: badge declares the developmental stage of a package according to \url{https://lifecycle.r-lib.org/articles/stages.html}. +\item \code{use_r_universe_badge()} indicates what version of your package is available +on R-universe \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}. \item \code{use_binder_badge()}: badge indicates that your repository can be launched in an executable environment on \url{https://mybinder.org/} \item \code{use_posit_cloud_badge()}: badge indicates that your repository can be launched @@ -72,6 +77,13 @@ in a \href{https://posit.cloud}{Posit Cloud} project \dontrun{ use_cran_badge() use_lifecycle_badge("stable") +# If you don't have a GitHub repo, or needs something extra +# you can create the r-universe badge +use_badge( + "R-universe", + "https://{organization}.r-universe.dev/badges/{package})", + "https://{organization}.r-universe.dev/{package}" +) } } \seealso{ diff --git a/tests/testthat/_snaps/badge.md b/tests/testthat/_snaps/badge.md index a212bab6b..211a15fd0 100644 --- a/tests/testthat/_snaps/badge.md +++ b/tests/testthat/_snaps/badge.md @@ -7,6 +7,16 @@ ! `stage` must be one of "experimental", "stable", "superseded", or "deprecated", not "eperimental". i Did you mean "experimental"? +# use_r_universe_badge() needs a repository + + Code + use_r_universe_badge() + Condition + Error in `use_r_universe_badge()`: + x {TESTPKG} must have a repo URL in DESCRITPION to create a badge. + i Use `usethis::use_badge()` if you have a different configuration. + i If {TESTPKG} is on CRAN, you can also see for a redirect to the r-universe homepage. + # use_rscloud_badge() handles bad and good input Code diff --git a/tests/testthat/test-badge.R b/tests/testthat/test-badge.R index e90d05f56..22038c00d 100644 --- a/tests/testthat/test-badge.R +++ b/tests/testthat/test-badge.R @@ -21,6 +21,16 @@ test_that("use_binder_badge() needs a github repository", { expect_error(use_binder_badge(), class = "usethis_error_bad_github_remote_config") }) +test_that("use_r_universe_badge() needs a repository", { + skip_if_no_git_user() + create_local_package() + use_git() + expect_snapshot(error = TRUE, + use_r_universe_badge(), + transform = scrub_testpkg + ) +}) + test_that("use_rscloud_badge() handles bad and good input", { create_local_project() expect_snapshot(use_posit_cloud_badge(), error = TRUE) From 9e97e351dc06a310782344eadd1e9524c9b5af8d Mon Sep 17 00:00:00 2001 From: olivroy Date: Sat, 18 May 2024 11:03:31 -0400 Subject: [PATCH 2/5] Avoid mention `use_github_actions()` deprecated. --- R/badge.R | 2 +- man/badges.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/badge.R b/R/badge.R index 07bde1846..d2750c687 100644 --- a/R/badge.R +++ b/R/badge.R @@ -30,7 +30,7 @@ #' @param stage Stage of the package lifecycle. One of "experimental", #' "stable", "superseded", or "deprecated". #' @seealso Functions that configure continuous integration, such as -#' [use_github_actions()], also create badges. +#' [use_github_action("check-standard")][use_github_action()], also create badges. #' #' @name badges #' @examples diff --git a/man/badges.Rd b/man/badges.Rd index d2d5ec851..91befb3fe 100644 --- a/man/badges.Rd +++ b/man/badges.Rd @@ -88,5 +88,5 @@ use_badge( } \seealso{ Functions that configure continuous integration, such as -\code{\link[=use_github_actions]{use_github_actions()}}, also create badges. +\link[=use_github_action]{use_github_action("check-standard")}, also create badges. } From fbca4c8eb64ccb97455ee7eccaf73bccfb9ffad0 Mon Sep 17 00:00:00 2001 From: olivroy Date: Sat, 18 May 2024 11:21:13 -0400 Subject: [PATCH 3/5] Tweak man --- R/badge.R | 5 +++-- man/badges.Rd | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/R/badge.R b/R/badge.R index d2750c687..740e057d1 100644 --- a/R/badge.R +++ b/R/badge.R @@ -16,8 +16,9 @@ #' available on CRAN, powered by #' * `use_lifecycle_badge()`: badge declares the developmental stage of a #' package according to . -#' * `use_r_universe_badge()` indicates what version of your package is available -#' on R-universe `r lifecycle::badge("experimental")`. +#' * `use_r_universe_badge()`: `r lifecycle::badge("experimental")`: badge +#' indicates what version of your package is available on [R-universe +#' ](https://r-universe.dev/search/). #' * `use_binder_badge()`: badge indicates that your repository can be launched #' in an executable environment on #' * `use_posit_cloud_badge()`: badge indicates that your repository can be launched diff --git a/man/badges.Rd b/man/badges.Rd index 91befb3fe..ece65b13b 100644 --- a/man/badges.Rd +++ b/man/badges.Rd @@ -63,8 +63,8 @@ ensure your badge block starts with a line containing only available on CRAN, powered by \url{https://www.r-pkg.org} \item \code{use_lifecycle_badge()}: badge declares the developmental stage of a package according to \url{https://lifecycle.r-lib.org/articles/stages.html}. -\item \code{use_r_universe_badge()} indicates what version of your package is available -on R-universe \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}. +\item \code{use_r_universe_badge()}: \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}: badge +indicates what version of your package is available on \href{https://r-universe.dev/search/}{R-universe }. \item \code{use_binder_badge()}: badge indicates that your repository can be launched in an executable environment on \url{https://mybinder.org/} \item \code{use_posit_cloud_badge()}: badge indicates that your repository can be launched From a47ba4aa868c83240c4e4fb736dcb4d38677f597 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Thu, 21 Nov 2024 16:48:52 -0500 Subject: [PATCH 4/5] adjustments to use `target_repo_spec()` --- R/badge.R | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/R/badge.R b/R/badge.R index 0966b36a9..2cd506de4 100644 --- a/R/badge.R +++ b/R/badge.R @@ -155,12 +155,9 @@ use_r_universe_badge <- function() { # The r-universe link needs the package name + organization. pkg <- project_name() - url <- tryCatch(github_url(pkg), error = function(e) NULL) - # in order to get organization - desc <- proj_desc() - urls <- desc$get_urls() - dat <- parse_github_remotes(c(urls, url)) - gh_org <- unique(dat$repo_owner[!is.na(dat$repo_owner)]) + # Get organization to construct R-universe link + repo_owner <- tryCatch(target_repo()$repo_owner, error = function(e) NA) + gh_org <- unique(repo_owner[!is.na(repo_owner)]) if (length(gh_org) == 0L) { ui_abort(c( "{.pkg {pkg}} must have a repo URL in DESCRITPION to create a badge.", From efbf7ff0a7d7d9b44967dd8ba2f9d9715b611639 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Thu, 21 Nov 2024 17:00:21 -0500 Subject: [PATCH 5/5] fix link + logic --- R/badge.R | 6 +++--- tests/testthat/_snaps/badge.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/badge.R b/R/badge.R index 2cd506de4..d08364708 100644 --- a/R/badge.R +++ b/R/badge.R @@ -157,12 +157,12 @@ use_r_universe_badge <- function() { pkg <- project_name() # Get organization to construct R-universe link repo_owner <- tryCatch(target_repo()$repo_owner, error = function(e) NA) - gh_org <- unique(repo_owner[!is.na(repo_owner)]) - if (length(gh_org) == 0L) { + gh_org <- repo_owner[!is.na(repo_owner)] + if (length(gh_org) != 1L ) { ui_abort(c( "{.pkg {pkg}} must have a repo URL in DESCRITPION to create a badge.", "Use {.fn usethis::use_badge} if you have a different configuration.", - "If {.pkg {pkg}} is on CRAN, you can also see {.url cran.dev/{pkg}} + "If {.pkg {pkg}} is on CRAN, you can also see {.url https://cran.dev/{pkg}} for a redirect to the r-universe homepage." )) } diff --git a/tests/testthat/_snaps/badge.md b/tests/testthat/_snaps/badge.md index bf98c54ff..3eca7e800 100644 --- a/tests/testthat/_snaps/badge.md +++ b/tests/testthat/_snaps/badge.md @@ -15,7 +15,7 @@ Error in `use_r_universe_badge()`: x {TESTPKG} must have a repo URL in DESCRITPION to create a badge. i Use `usethis::use_badge()` if you have a different configuration. - i If {TESTPKG} is on CRAN, you can also see for a redirect to the r-universe homepage. + i If {TESTPKG} is on CRAN, you can also see for a redirect to the r-universe homepage. # use_posit_cloud_badge() handles bad and good input