From b6f823f8a254bef69fd5bfc9eea6a933b7b10e9e Mon Sep 17 00:00:00 2001 From: adrhill Date: Tue, 22 Oct 2024 00:18:37 +0200 Subject: [PATCH] Support GitLab and Sourcehut --- src/MethodURL.jl | 13 ++++++++++++- test/Project.toml | 3 +++ test/runtests.jl | 48 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/MethodURL.jl b/src/MethodURL.jl index e3f7bc0..861320a 100644 --- a/src/MethodURL.jl +++ b/src/MethodURL.jl @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/test/Project.toml b/test/Project.toml index 16e03fe..ace07c4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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" diff --git a/test/runtests.jl b/test/runtests.jl index e90a7e7..2921900 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using MethodURL +# Linting tests using Test using JuliaFormatter: JuliaFormatter using Aqua: Aqua @@ -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 @@ -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