Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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()`.
Expand Down
4 changes: 2 additions & 2 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#'
Expand Down
1 change: 1 addition & 0 deletions R/navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
7 changes: 5 additions & 2 deletions R/repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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))
Expand All @@ -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, "/")
)
Expand Down
4 changes: 2 additions & 2 deletions man/build_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/navbar.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# adds github/gitlab link when available
# adds github/gitlab/codeberg link when available

reference:
text: Reference
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-navbar.R
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
})
Loading