Skip to content

Commit 5ad1c98

Browse files
authored
Add Remotes.Remote for Forgejo (#2857)
1 parent 931fd40 commit 5ad1c98

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## Unreleased
7+
8+
### Added
9+
10+
* Added `Remotes.Forgejo` for specifying a `Remote` hosted on a Forgejo instance (such as codeberg.org). ([#2857])
11+
612
## Version [v1.16.1] - 2025-11-21
713

814
### Fixed

docs/src/lib/remote-links.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Note that enabling this option can cause documentation builds to fail due to net
5353

5454
!!! note
5555

56-
The [`Remotes` API](@ref remotes-api) can be used to implement the methods to compute the remote URLs (for now, Documenter only supports [GitHub](@ref Remotes.GitHub) and [GitLab](@ref Remotes.GitLab) natively).
56+
The [`Remotes` API](@ref remotes-api) can be used to implement the methods to compute the remote URLs (for now, Documenter supports [GitHub](@ref Remotes.GitHub), [GitLab](@ref Remotes.GitLab) and [Forgejo](@ref Remotes.Forgejo) natively).
5757

5858
[^1]: There is an exception to this: links to Julia `Base` module source files.
5959
But Documenter already known how to handle those correctly, and they are really only relevant to the Julia main manual build.
@@ -84,6 +84,7 @@ The rules are as follows:
8484
Documenter.Remotes
8585
Documenter.Remotes.GitHub
8686
Documenter.Remotes.GitLab
87+
Documenter.Remotes.Forgejo
8788
```
8889

8990
The following types and functions and relevant when creating custom

src/utilities/Remotes.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,53 @@ function fileurl(remote::GitLab, ref::AbstractString, filename::AbstractString,
173173
end
174174
issueurl(remote::GitLab, issuenumber) = "$(repourl(remote))/-/issues/$issuenumber"
175175

176+
"""
177+
Forgejo(host, user, repo)
178+
Forgejo(remote)
179+
180+
Represents a remote Git repository hosted on Forgejo (for example,
181+
[Codeberg](https://codeberg.org)). The repository is
182+
identified by the host, name of the user (or organization), and the
183+
repository. For example:
184+
185+
```julia
186+
makedocs(
187+
repo = Forgejo("codeberg.org", "JuliaDocs", "Documenter.jl")
188+
)
189+
```
190+
191+
The single argument constructor assumes that the host, end user and
192+
repository parts are separated by a slash (e.g.,
193+
`codeberg.org/JuliaDocs/Documenter.jl`).
194+
"""
195+
struct Forgejo <: Remotes.Remote
196+
host::String
197+
user::String
198+
repo::String
199+
end
200+
function Forgejo(remote::AbstractString)
201+
host, user, repo = split(remote, '/')
202+
return Forgejo(host, user, repo)
203+
end
204+
repourl(
205+
remote::Forgejo,
206+
) = "https://$(remote.host)/$(remote.user)/$(remote.repo)"
207+
function fileurl(
208+
remote::Forgejo,
209+
ref::AbstractString,
210+
filename::AbstractString,
211+
linerange,
212+
)
213+
url = "$(repourl(remote))/src/commit/$(ref)/$(filename)"
214+
isnothing(linerange) && return url
215+
lstart, lend = first(linerange), last(linerange)
216+
return (lstart == lend) ? "$(url)#L$(lstart)" : "$(url)#L$(lstart)-L$(lend)"
217+
end
218+
issueurl(
219+
remote::Forgejo,
220+
issuenumber,
221+
) = "$(repourl(remote))/issues/$issuenumber"
222+
176223
############################################################################
177224
# Handling of URL string templates (deprecated, for backwards compatibility)
178225
#

test/remotes.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module RemoteTests
22
using Test
33
using Documenter
4-
using .Remotes: repofile, repourl, issueurl, URL, GitHub, GitLab
4+
using .Remotes: repofile, repourl, issueurl, URL, GitHub, GitLab, Forgejo
55

66
@testset "RepositoryRemote" begin
77
let r = URL("https://github.com/FOO/BAR/blob/{commit}{path}#{line}")
@@ -95,6 +95,25 @@ using .Remotes: repofile, repourl, issueurl, URL, GitHub, GitLab
9595
@test repofile(r, "mybranch", "src/foo.jl", 5:8) == "https://gitlab.com/JuliaDocs/Documenter.jl/-/tree/mybranch/src/foo.jl#L5-L8"
9696
@test issueurl(r, "123") == "https://gitlab.com/JuliaDocs/Documenter.jl/-/issues/123"
9797
end
98+
99+
# Forgejo remote
100+
let r = Forgejo("git.mydomain.tld", "JuliaDocs", "Documenter.jl")
101+
@test repourl(r) == "https://git.mydomain.tld/JuliaDocs/Documenter.jl"
102+
@test repofile(r, "mybranch", "src/foo.jl") == "https://git.mydomain.tld/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl"
103+
@test repofile(r, "mybranch", "src/foo.jl", 5) == "https://git.mydomain.tld/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl#L5"
104+
@test repofile(r, "mybranch", "src/foo.jl", 5:5) == "https://git.mydomain.tld/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl#L5"
105+
@test repofile(r, "mybranch", "src/foo.jl", 5:8) == "https://git.mydomain.tld/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl#L5-L8"
106+
@test issueurl(r, "123") == "https://git.mydomain.tld/JuliaDocs/Documenter.jl/issues/123"
107+
end
108+
109+
let r = Forgejo("codeberg.org/JuliaDocs/Documenter.jl")
110+
@test repourl(r) == "https://codeberg.org/JuliaDocs/Documenter.jl"
111+
@test repofile(r, "mybranch", "src/foo.jl") == "https://codeberg.org/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl"
112+
@test repofile(r, "mybranch", "src/foo.jl", 5) == "https://codeberg.org/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl#L5"
113+
@test repofile(r, "mybranch", "src/foo.jl", 5:5) == "https://codeberg.org/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl#L5"
114+
@test repofile(r, "mybranch", "src/foo.jl", 5:8) == "https://codeberg.org/JuliaDocs/Documenter.jl/src/commit/mybranch/src/foo.jl#L5-L8"
115+
@test issueurl(r, "123") == "https://codeberg.org/JuliaDocs/Documenter.jl/issues/123"
116+
end
98117
end
99118

100119
end # module

0 commit comments

Comments
 (0)