From ca04c6beae9101983e631bb29deb502213a4a896 Mon Sep 17 00:00:00 2001 From: catalamarti Date: Thu, 15 Aug 2024 12:59:52 -0700 Subject: [PATCH] allow BugReports to be an email fixes #2275 --- R/build-home-index.R | 5 ++++- tests/testthat/test-build-home-index.R | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/R/build-home-index.R b/R/build-home-index.R index d589970b4..7cc61d5b0 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -158,10 +158,13 @@ data_home_sidebar_links <- function(pkg = ".") { repo <- cran_link(pkg$package) links <- config_pluck(pkg, "home.links") + bug_reports <- pkg$desc$get_field("BugReports", default = NULL) + if (grepl("@", bug_reports)) bug_reports <- paste0("mailto:", bug_reports) + links <- c( link_url(sprintf(tr_("View on %s"), repo$repo), repo$url), link_url(tr_("Browse source code"), repo_home(pkg)), - link_url(tr_("Report a bug"), pkg$desc$get_field("BugReports", default = NULL)), + link_url(tr_("Report a bug"), bug_reports), purrr::map_chr(links, ~ link_url(.$text, .$href)) ) diff --git a/tests/testthat/test-build-home-index.R b/tests/testthat/test-build-home-index.R index 283b39126..0f65b0efa 100644 --- a/tests/testthat/test-build-home-index.R +++ b/tests/testthat/test-build-home-index.R @@ -153,3 +153,10 @@ test_that("cran_unquote works", { "Quoting is CRAN's thing." ) }) + +test_that("allow email in BugReports", { + # currently desc throws a warning if BugReports is an email + pkg <- local_pkgdown_site(desc = list(BugReports = "me@tidyverse.com")) + html <- xml2::read_html(data_home_sidebar(pkg)) + expect_snapshot(xpath_xml(html, ".//li/a")) +})