Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.0'
Expand Down
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ name = "DocStringExtensions"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"

[deps]
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"

[compat]
julia = "1"

[extras]
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Markdown", "Pkg", "Test"]
test = ["LibGit2", "Markdown", "Pkg", "REPL", "Test"]
4 changes: 0 additions & 4 deletions src/DocStringExtensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ $(IMPORTS)
"""
module DocStringExtensions

# Imports.

import LibGit2

# Exports.

export @template, FIELDS, TYPEDFIELDS, EXPORTS, METHODLIST, IMPORTS
Expand Down
53 changes: 16 additions & 37 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,6 @@ end
#
# Source URLs.
#
# Based on code from https://github.com/JuliaLang/julia/blob/master/base/methodshow.jl.
#
# Customised to handle URLs on travis since the directory is not a Git repo and we must
# instead rely on `TRAVIS_REPO_SLUG` to get the remote repo.
#
Expand All @@ -522,45 +520,26 @@ Get the URL (file and line number) where a method `m` is defined.
Note that this is based on the implementation of `Base.url`, but handles URLs correctly
on TravisCI as well.
"""
url(m::Method) = url(m.module, string(m.file), m.line)
function url(m::Method)
if haskey(ENV, "TRAVIS_REPO_SLUG")
repo = ENV["TRAVIS_REPO_SLUG"]

function url(mod::Module, file::AbstractString, line::Integer)
file = Sys.iswindows() ? replace(file, '\\' => '/') : file
if Base.inbase(mod) && !isabspath(file)
local base = "https://github.com/JuliaLang/julia/tree"
if isempty(Base.GIT_VERSION_INFO.commit)
return "$base/v$VERSION/base/$file#L$line"
else
local commit = Base.GIT_VERSION_INFO.commit
return "$base/$commit/base/$file#L$line"
end
else
if isfile(file)
local d = dirname(file)
try # might not be in a git repo
LibGit2.with(LibGit2.GitRepoExt(d)) do repo
LibGit2.with(LibGit2.GitConfig(repo)) do cfg
local u = LibGit2.get(cfg, "remote.origin.url", "")
local m = match(LibGit2.GITHUB_REGEX, u)
u = m === nothing ? get(ENV, "TRAVIS_REPO_SLUG", "") : m.captures[1]
local commit = string(LibGit2.head_oid(repo))
local root = LibGit2.path(repo)
if startswith(file, root) || startswith(realpath(file), root)
local base = "https://github.com/$u/tree"
local filename = file[(length(root) + 1):end]
return "$base/$commit/$filename#L$line"
else
return ""
end
end
end
catch err
isa(err, LibGit2.GitError) || rethrow()
return ""
end
commit = get(ENV, "TRAVIS_COMMIT", nothing)
commit === nothing && return ""

root = get(ENV, "TRAVIS_BUILD_DIR", nothing)
root === nothing && return ""

file = realpath(string(m.file))
if startswith(file, root)
filename = join(split(relpath(file, root), @static Sys.iswindows() ? '\\' : '/'), '/')
base = "https://github.com/$repo/tree"
return "$base/$commit/$filename#L$(m.line)"
else
return ""
end
else
return Base.url(m)
end
end

Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ using DocStringExtensions
using Test
import Markdown
import LibGit2
import REPL

include("tests.jl")
7 changes: 7 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,13 @@ end
@test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.f))))
@test occursin("github.com/JuliaDocs/NonExistent", DSE.url(first(methods(M.K))))
end
withenv(
"TRAVIS_REPO_SLUG" => "JuliaDocs/NonExistent",
"TRAVIS_COMMIT" => "<commit>",
"TRAVIS_BUILD_DIR" => dirname(@__DIR__)
) do
@test occursin("github.com/JuliaDocs/NonExistent/tree/<commit>/test/TestModule/M.jl", DSE.url(first(methods(M.f))))
end
end
@testset "comparemethods" begin
let f = first(methods(M.f)),
Expand Down
Loading