diff --git a/src/utilities/Remotes.jl b/src/utilities/Remotes.jl index 1a3add0f50..997d6732f6 100644 --- a/src/utilities/Remotes.jl +++ b/src/utilities/Remotes.jl @@ -150,6 +150,9 @@ makedocs( ) ``` +The `host` may include a scheme. If the host does not define a scheme, it +defaults to `https`. + The single argument constructor assumes that the end user and repository parts are separated by a slash (e.g., `JuliaDocs/Documenter.jl`). @@ -164,7 +167,17 @@ function GitLab(remote::AbstractString) user, repo = split(remote, '/') GitLab(user, repo) end -repourl(remote::GitLab) = "https://$(remote.host)/$(remote.user)/$(remote.repo)" +function host_with_scheme(remote::GitLab) + # A scheme in a URI consists of a letter followed by zero or more letters, + # digits, pluses, dashes or periods followed by a colon. They should be + # matched case insensitively + # + # See https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 + scheme_matcher = r"^\p{L}[\p{L}\d+-.]*:" + scheme_from_host = match(scheme_matcher, remote.host) + return isnothing(scheme_from_host) ? "https://$(remote.host)" : remote.host +end +repourl(remote::GitLab) = "$(host_with_scheme(remote))/$(remote.user)/$(remote.repo)" function fileurl(remote::GitLab, ref::AbstractString, filename::AbstractString, linerange) url = "$(repourl(remote))/-/tree/$(ref)/$(filename)" isnothing(linerange) && return url diff --git a/test/remotes.jl b/test/remotes.jl index c3ee9fa30f..2ebafa58c4 100644 --- a/test/remotes.jl +++ b/test/remotes.jl @@ -87,6 +87,15 @@ using .Remotes: repofile, repourl, issueurl, URL, GitHub, GitLab @test issueurl(r, "123") == "https://my-gitlab.com/JuliaDocs/Documenter.jl/-/issues/123" end + let r = GitLab("http://my-gitlab.com", "JuliaDocs", "Documenter.jl") + @test repourl(r) == "http://my-gitlab.com/JuliaDocs/Documenter.jl" + @test repofile(r, "mybranch", "src/foo.jl") == "http://my-gitlab.com/JuliaDocs/Documenter.jl/-/tree/mybranch/src/foo.jl" + @test repofile(r, "mybranch", "src/foo.jl", 5) == "http://my-gitlab.com/JuliaDocs/Documenter.jl/-/tree/mybranch/src/foo.jl#L5" + @test repofile(r, "mybranch", "src/foo.jl", 5:5) == "http://my-gitlab.com/JuliaDocs/Documenter.jl/-/tree/mybranch/src/foo.jl#L5" + @test repofile(r, "mybranch", "src/foo.jl", 5:8) == "http://my-gitlab.com/JuliaDocs/Documenter.jl/-/tree/mybranch/src/foo.jl#L5-L8" + @test issueurl(r, "123") == "http://my-gitlab.com/JuliaDocs/Documenter.jl/-/issues/123" + end + let r = GitLab("JuliaDocs/Documenter.jl") @test repourl(r) == "https://gitlab.com/JuliaDocs/Documenter.jl" @test repofile(r, "mybranch", "src/foo.jl") == "https://gitlab.com/JuliaDocs/Documenter.jl/-/tree/mybranch/src/foo.jl"