diff --git a/NEWS.md b/NEWS.md index 9ff5b63ff..a40300dca 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* Code repositories hosted on Codeberg are now supported in the `BugReports` and `URL` fields (@nfrerebeau, #2843). * Articles (i.e., vignettes in `vignettes/articles`, created by `usethis::use_article()` and available on pkgdown sites but not included in a built package) have improved test cases (thanks to @venpopov and @ethanbass). * New `clean_site(force = TRUE)` for cleaning of `docs/` regardless of whether it was built by pkgdown (#2827). * Links to favicons in page headers were updated to reflect changes to https://realfavicongenerator.net/ (#2804). Favicons should be re-generated by manually removing the `pkgdown/favicon` directory and then running `pkgdown::build_favicons()`. diff --git a/R/build.R b/R/build.R index afd0ff511..eb5a4cb4e 100644 --- a/R/build.R +++ b/R/build.R @@ -222,8 +222,8 @@ #' of your source repository. This is used in the navbar, on the homepage, #' in articles and reference topics, and in the changelog (to link to issue #' numbers and user names). pkgdown can automatically figure out the necessary -#' URLs if you link to a GitHub or GitLab repo in your `BugReports` or `URL` -#' field. +#' URLs if you link to a GitHub, GitLab or Codeberg repo in your `BugReports` +#' or `URL` field. #' #' Otherwise, you can supply your own in the `repo` field: #' diff --git a/R/navbar.R b/R/navbar.R index 6e887a6cb..3f333c741 100644 --- a/R/navbar.R +++ b/R/navbar.R @@ -165,6 +165,7 @@ navbar_components <- function(pkg = ".") { repo_type(pkg), github = menu_icon("fab fa-github fa-lg", repo_home(pkg), "GitHub"), gitlab = menu_icon("fab fa-gitlab fa-lg", repo_home(pkg), "GitLab"), + codeberg = menu_icon("fas fa-code fa-lg", repo_home(pkg), "Codeberg"), NULL ) diff --git a/R/repo.R b/R/repo.R index cc9e2881c..af2195efa 100644 --- a/R/repo.R +++ b/R/repo.R @@ -5,6 +5,8 @@ repo_type <- function(pkg) { "github" } else if (grepl("^https?://gitlab\\..+/", home)) { "gitlab" + } else if (grepl("^https?://codeberg\\..+/", home)) { + "codeberg" } else { "other" } @@ -75,7 +77,7 @@ package_repo <- function(pkg) { pkg$desc$get_urls() ) - gh_links <- grep("^https?://git(hub|lab)\\..+/", urls, value = TRUE) + gh_links <- grep("^https?://(git(hub|lab)|codeberg)\\..+/", urls, value = TRUE) if (length(gh_links) > 0) { branch <- config_pluck_string(pkg, "repo.branch") return(repo_meta_gh_like(gh_links[[1]], branch)) @@ -98,10 +100,11 @@ repo_meta <- function(home = NULL, source = NULL, issue = NULL, user = NULL) { repo_meta_gh_like <- function(link, branch = NULL) { gh <- parse_github_like_url(link) branch <- branch %||% gha_current_branch() + blob <- if (grepl("^https?://codeberg\\.", link)) "/src/branch/" else "/blob/" repo_meta( paste0(gh$host, "/", gh$owner, "/", gh$repo, "/"), - paste0(gh$host, "/", gh$owner, "/", gh$repo, "/blob/", branch, "/"), + paste0(gh$host, "/", gh$owner, "/", gh$repo, blob, branch, "/"), paste0(gh$host, "/", gh$owner, "/", gh$repo, "/issues/"), paste0(gh$host, "/") ) diff --git a/man/build_site.Rd b/man/build_site.Rd index 602bfb530..f656c9834 100644 --- a/man/build_site.Rd +++ b/man/build_site.Rd @@ -272,8 +272,8 @@ Use the \code{repo} field to override pkgdown's automatically discovery of your source repository. This is used in the navbar, on the homepage, in articles and reference topics, and in the changelog (to link to issue numbers and user names). pkgdown can automatically figure out the necessary -URLs if you link to a GitHub or GitLab repo in your \code{BugReports} or \code{URL} -field. +URLs if you link to a GitHub, GitLab or Codeberg repo in your \code{BugReports} +or \code{URL} field. Otherwise, you can supply your own in the \code{repo} field: diff --git a/tests/testthat/_snaps/navbar.md b/tests/testthat/_snaps/navbar.md index 06b98d626..70dd45a4b 100644 --- a/tests/testthat/_snaps/navbar.md +++ b/tests/testthat/_snaps/navbar.md @@ -1,4 +1,4 @@ -# adds github/gitlab link when available +# adds github/gitlab/codeberg link when available reference: text: Reference diff --git a/tests/testthat/test-navbar.R b/tests/testthat/test-navbar.R index 4fb0aa28f..ac93fb775 100644 --- a/tests/testthat/test-navbar.R +++ b/tests/testthat/test-navbar.R @@ -1,4 +1,4 @@ -test_that("adds github/gitlab link when available", { +test_that("adds github/gitlab/codeberg link when available", { pkg <- pkg_navbar() expect_snapshot_output(navbar_components(pkg)) diff --git a/tests/testthat/test-repo.R b/tests/testthat/test-repo.R index 3ff8d30cd..c88104fd7 100644 --- a/tests/testthat/test-repo.R +++ b/tests/testthat/test-repo.R @@ -111,6 +111,13 @@ test_that("can find gitlab url", { expect_equal(package_repo(pkg), repo_meta_gh_like(url)) }) +test_that("can find codeberg url", { + withr::local_envvar(GITHUB_HEAD_REF = "HEAD") + url <- "https://codeberg.org/msberends/AMR" + pkg <- local_pkgdown_site(desc = list(URL = url)) + expect_equal(package_repo(pkg), repo_meta_gh_like(url)) +}) + test_that("uses GITHUB env vars if set", { withr::local_envvar(GITHUB_HEAD_REF = NA, GITHUB_REF_NAME = "abc") expect_equal( @@ -172,5 +179,6 @@ test_that("repo_type detects repo type", { expect_equal(repo_type2("https://github.r-lib.com/pkgdown"), "github") expect_equal(repo_type2("https://gitlab.com/r-lib/pkgdown"), "gitlab") expect_equal(repo_type2("https://gitlab.r-lib.com/pkgdown"), "gitlab") + expect_equal(repo_type2("https://codeberg.org/r-lib/pkgdown"), "codeberg") expect_equal(repo_type2(NULL), "other") })