Skip to content

Commit

Permalink
Support GitLab and Sourcehut
Browse files Browse the repository at this point in the history
  • Loading branch information
adrhill committed Oct 21, 2024
1 parent 7ee279f commit b6f823f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/MethodURL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ function repo_and_path_to_url(repo, version, path, line)
repo = chopsuffix(repo, ".git")
# TODO: Handle more git forges
if startswith(repo, "https://github.com")
# https://github.com/owner/Package.jl/blob/v0.1.0/src/foo.jl#L42
return join([repo, "blob", "v" * version, path * "#L$line"], "/")
elseif startswith(repo, "https://gitlab.com")
# https://gitlab.com/owner/Package.jl/-/blob/v0.1.0/src/foo.jl#L42
return join([repo, "-", "blob", "v" * version, path * "#L$line"], "/")
elseif startswith(repo, "https://git.sr.ht")
# https://git.sr.ht/~owner/Package.jl/tree/v0.1.0/item/src/foo.jl#L42
return join([repo, "tree", "v" * version, "item", path * "#L$line"], "/")
else
error("Failed to construct URL for repository $repo.")
end
Expand All @@ -28,6 +35,9 @@ function repos_package(uuid::UUID)
push!(repos, info.repo)
end
end
if isempty(repos)
error("Failed to find reachable repository matching UUID $uuid.")
end
return repos
end

Expand All @@ -47,6 +57,7 @@ end

# TODO: If package is devved use local path
# TODO: If package is added by URL, use that
# TODO: Support monorepos
function url(m::Method)
M = parentmodule(m)
file = String(m.file)
Expand All @@ -71,13 +82,13 @@ function url(m::Method)
popfirst!(file_splitpath)
end
local_dir = join(file_splitpath, "/")
# @info M file uuid _pkgdir(M) local_dir

v = string(pkgversion(M))
for repo in repos_package(uuid)
url = repo_and_path_to_url(repo, v, local_dir, line)
push!(urls, url)
end
@info M file uuid _pkgdir(M) first(repos_package(uuid)) local_dir v
end
return urls
end
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Arxiv = "95bf46a4-16f0-449f-8b01-023b953c38f0"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
GPMaxlik = "988d40dc-a58a-4803-bd2c-6d7438fe27fe"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
48 changes: 36 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MethodURL

# Linting tests
using Test
using JuliaFormatter: JuliaFormatter
using Aqua: Aqua
Expand All @@ -13,9 +14,15 @@ using ExplicitImports:
check_all_qualified_accesses_via_owners,
check_all_qualified_accesses_are_public

# Packages used for testing
using HTTP: request
using InteractiveUtils: @which

# Package to test URLs on
using Plots: Plots # has sub-repositories
using Arxiv: @arXiv_str # hosted on GitLab
using GPMaxlik: gnll # hosted on sourcehut

function url_exists(url)
response = request("GET", url; status_exception=false, redirect=true, retry=true)
if 200 response.status < 400
Expand Down Expand Up @@ -64,25 +71,42 @@ end
end
@testset verbose = true "URL" begin
@testset "Base" begin
m1 = @which sqrt(1.0)
u1 = first(@inferred url(m1))
# @test url_exists(u1)
m = @which sqrt(0.0)
u = first(@inferred url(m))
# @test url_exists(u)
end
# @testset "Stdlib" begin
# m2 = @which @test true
# u2 = first(@inferred url(m2))
# # @test url_exists(u2)
# m = @which @test true
# u = first(@inferred url(m))
# # @test url_exists(u)
# end
# @testset "Local" begin
# _m = @which sqrt(1.0)
# m3 = @which url(_m)
# u3 = first(@inferred url(m3))
# # @test url_exists(u3)
# m = @which url(_m)
# u = first(@inferred url(m))
# # @test url_exists(u)
# end
@testset "External" begin
m4 = @which Aqua.test_all(MethodURL)
u4 = first(@inferred url(m4))
# @test url_exists(u4)
@testset "GitHub" begin
m = @which Aqua.test_all(MethodURL)
u = first(@inferred url(m))
# @test url_exists(u)
end
@testset "GitHub monorepo" begin
m = first(methods(Plots.RecipesBase.create_kw_body))
u = first(@inferred url(m))
# @test url_exists(u)
end
@testset "GitLab" begin
m = @which arXiv"1234.5678"
u = first(@inferred url(m))
# @test url_exists(u) # no tags in Arxiv.jl
end
@testset "Sourcehut" begin
m = first(methods(gnll))
u = first(@inferred url(m))
# @test url_exists(u) # no tags in GPMaxlik.jl
end
end
end
end

0 comments on commit b6f823f

Please sign in to comment.