Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scheme definition for GitLab remotes #2392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion src/utilities/Remotes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
)
```

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`).
Expand All @@ -164,7 +167,17 @@
user, repo = split(remote, '/')
GitLab(user, repo)
end
repourl(remote::GitLab) = "https://$(remote.host)/$(remote.user)/$(remote.repo)"
function host_with_scheme(remote::GitLab)

Check warning on line 170 in src/utilities/Remotes.jl

View check run for this annotation

Codecov / codecov/patch

src/utilities/Remotes.jl#L170

Added line #L170 was not covered by tests
# 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

Check warning on line 178 in src/utilities/Remotes.jl

View check run for this annotation

Codecov / codecov/patch

src/utilities/Remotes.jl#L176-L178

Added lines #L176 - L178 were not covered by tests
end
repourl(remote::GitLab) = "$(host_with_scheme(remote))/$(remote.user)/$(remote.repo)"

Check warning on line 180 in src/utilities/Remotes.jl

View check run for this annotation

Codecov / codecov/patch

src/utilities/Remotes.jl#L180

Added line #L180 was not covered by tests
function fileurl(remote::GitLab, ref::AbstractString, filename::AbstractString, linerange)
url = "$(repourl(remote))/-/tree/$(ref)/$(filename)"
isnothing(linerange) && return url
Expand Down
9 changes: 9 additions & 0 deletions test/remotes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading