From 9f419fdd62d014f80087b8d1a198c22ee7ffc7b9 Mon Sep 17 00:00:00 2001 From: nfrerebeau Date: Thu, 23 Jan 2025 11:27:45 +0100 Subject: [PATCH 1/3] Support Codeberg repositories --- R/build.R | 4 ++-- R/navbar.R | 1 + R/repo.R | 7 +++++-- man/build_site.Rd | 4 ++-- tests/testthat/_snaps/navbar.md | 15 ++++++++++++++- tests/testthat/test-navbar.R | 5 ++++- tests/testthat/test-repo.R | 8 ++++++++ 7 files changed, 36 insertions(+), 8 deletions(-) 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..9296e544e 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 @@ -33,6 +33,19 @@ aria-label: GitLab +--- + + reference: + text: Reference + href: reference/index.html + search: + search: [] + github: + icon: fas fa-code fa-lg + href: https://codeberg.org/r-lib/pkgdown + aria-label: Codeberg + + # vignette with package name turns into getting started reference: diff --git a/tests/testthat/test-navbar.R b/tests/testthat/test-navbar.R index 4fb0aa28f..a9e623647 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)) @@ -7,6 +7,9 @@ test_that("adds github/gitlab link when available", { pkg <- pkg_navbar(github_url = "https://gitlab.com/r-lib/pkgdown") expect_snapshot_output(navbar_components(pkg)) + + pkg <- pkg_navbar(github_url = "https://codeberg.org/r-lib/pkgdown") + expect_snapshot_output(navbar_components(pkg)) }) test_that("vignette with package name turns into getting started", { 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") }) From da9808d85e2eea3f8f61b075edf0c18a8055fb39 Mon Sep 17 00:00:00 2001 From: nfrerebeau Date: Mon, 27 Jan 2025 11:49:14 +0100 Subject: [PATCH 2/3] Remove extra snapshot test --- tests/testthat/_snaps/navbar.md | 13 ------------- tests/testthat/test-navbar.R | 3 --- 2 files changed, 16 deletions(-) diff --git a/tests/testthat/_snaps/navbar.md b/tests/testthat/_snaps/navbar.md index 9296e544e..70dd45a4b 100644 --- a/tests/testthat/_snaps/navbar.md +++ b/tests/testthat/_snaps/navbar.md @@ -33,19 +33,6 @@ aria-label: GitLab ---- - - reference: - text: Reference - href: reference/index.html - search: - search: [] - github: - icon: fas fa-code fa-lg - href: https://codeberg.org/r-lib/pkgdown - aria-label: Codeberg - - # vignette with package name turns into getting started reference: diff --git a/tests/testthat/test-navbar.R b/tests/testthat/test-navbar.R index a9e623647..ac93fb775 100644 --- a/tests/testthat/test-navbar.R +++ b/tests/testthat/test-navbar.R @@ -7,9 +7,6 @@ test_that("adds github/gitlab/codeberg link when available", { pkg <- pkg_navbar(github_url = "https://gitlab.com/r-lib/pkgdown") expect_snapshot_output(navbar_components(pkg)) - - pkg <- pkg_navbar(github_url = "https://codeberg.org/r-lib/pkgdown") - expect_snapshot_output(navbar_components(pkg)) }) test_that("vignette with package name turns into getting started", { From d18b91f2775a70835ba46ee912de3e5c1486249b Mon Sep 17 00:00:00 2001 From: nfrerebeau Date: Mon, 27 Jan 2025 15:33:24 +0100 Subject: [PATCH 3/3] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) 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()`.