Skip to content

Commit 74fda8c

Browse files
authored
Support Codeberg repositories (#2843)
Fixes #2842.
1 parent 6615322 commit 74fda8c

File tree

8 files changed

+21
-8
lines changed

8 files changed

+21
-8
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pkgdown (development version)
22

3+
* Code repositories hosted on Codeberg are now supported in the `BugReports` and `URL` fields (@nfrerebeau, #2843).
34
* 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).
45
* New `clean_site(force = TRUE)` for cleaning of `docs/` regardless of whether it was built by pkgdown (#2827).
56
* 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()`.

R/build.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@
222222
#' of your source repository. This is used in the navbar, on the homepage,
223223
#' in articles and reference topics, and in the changelog (to link to issue
224224
#' numbers and user names). pkgdown can automatically figure out the necessary
225-
#' URLs if you link to a GitHub or GitLab repo in your `BugReports` or `URL`
226-
#' field.
225+
#' URLs if you link to a GitHub, GitLab or Codeberg repo in your `BugReports`
226+
#' or `URL` field.
227227
#'
228228
#' Otherwise, you can supply your own in the `repo` field:
229229
#'

R/navbar.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ navbar_components <- function(pkg = ".") {
165165
repo_type(pkg),
166166
github = menu_icon("fab fa-github fa-lg", repo_home(pkg), "GitHub"),
167167
gitlab = menu_icon("fab fa-gitlab fa-lg", repo_home(pkg), "GitLab"),
168+
codeberg = menu_icon("fas fa-code fa-lg", repo_home(pkg), "Codeberg"),
168169
NULL
169170
)
170171

R/repo.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ repo_type <- function(pkg) {
55
"github"
66
} else if (grepl("^https?://gitlab\\..+/", home)) {
77
"gitlab"
8+
} else if (grepl("^https?://codeberg\\..+/", home)) {
9+
"codeberg"
810
} else {
911
"other"
1012
}
@@ -75,7 +77,7 @@ package_repo <- function(pkg) {
7577
pkg$desc$get_urls()
7678
)
7779

78-
gh_links <- grep("^https?://git(hub|lab)\\..+/", urls, value = TRUE)
80+
gh_links <- grep("^https?://(git(hub|lab)|codeberg)\\..+/", urls, value = TRUE)
7981
if (length(gh_links) > 0) {
8082
branch <- config_pluck_string(pkg, "repo.branch")
8183
return(repo_meta_gh_like(gh_links[[1]], branch))
@@ -98,10 +100,11 @@ repo_meta <- function(home = NULL, source = NULL, issue = NULL, user = NULL) {
98100
repo_meta_gh_like <- function(link, branch = NULL) {
99101
gh <- parse_github_like_url(link)
100102
branch <- branch %||% gha_current_branch()
103+
blob <- if (grepl("^https?://codeberg\\.", link)) "/src/branch/" else "/blob/"
101104

102105
repo_meta(
103106
paste0(gh$host, "/", gh$owner, "/", gh$repo, "/"),
104-
paste0(gh$host, "/", gh$owner, "/", gh$repo, "/blob/", branch, "/"),
107+
paste0(gh$host, "/", gh$owner, "/", gh$repo, blob, branch, "/"),
105108
paste0(gh$host, "/", gh$owner, "/", gh$repo, "/issues/"),
106109
paste0(gh$host, "/")
107110
)

man/build_site.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/navbar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# adds github/gitlab link when available
1+
# adds github/gitlab/codeberg link when available
22

33
reference:
44
text: Reference

tests/testthat/test-navbar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("adds github/gitlab link when available", {
1+
test_that("adds github/gitlab/codeberg link when available", {
22
pkg <- pkg_navbar()
33
expect_snapshot_output(navbar_components(pkg))
44

tests/testthat/test-repo.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ test_that("can find gitlab url", {
111111
expect_equal(package_repo(pkg), repo_meta_gh_like(url))
112112
})
113113

114+
test_that("can find codeberg url", {
115+
withr::local_envvar(GITHUB_HEAD_REF = "HEAD")
116+
url <- "https://codeberg.org/msberends/AMR"
117+
pkg <- local_pkgdown_site(desc = list(URL = url))
118+
expect_equal(package_repo(pkg), repo_meta_gh_like(url))
119+
})
120+
114121
test_that("uses GITHUB env vars if set", {
115122
withr::local_envvar(GITHUB_HEAD_REF = NA, GITHUB_REF_NAME = "abc")
116123
expect_equal(
@@ -172,5 +179,6 @@ test_that("repo_type detects repo type", {
172179
expect_equal(repo_type2("https://github.r-lib.com/pkgdown"), "github")
173180
expect_equal(repo_type2("https://gitlab.com/r-lib/pkgdown"), "gitlab")
174181
expect_equal(repo_type2("https://gitlab.r-lib.com/pkgdown"), "gitlab")
182+
expect_equal(repo_type2("https://codeberg.org/r-lib/pkgdown"), "codeberg")
175183
expect_equal(repo_type2(NULL), "other")
176184
})

0 commit comments

Comments
 (0)