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

Make showing the URL for a method work for code not hosted on Github #30140

Open
oxinabox opened this issue Nov 24, 2018 · 1 comment
Open

Make showing the URL for a method work for code not hosted on Github #30140

oxinabox opened this issue Nov 24, 2018 · 1 comment

Comments

@oxinabox
Copy link
Contributor

The code that finds the URL for the source for a method doesn't work for code that is not hosted on GitHub.
We should make it work for other major providers at least,
like gitlab and bitbucket.

julia/base/methodshow.jl

Lines 200 to 238 in f4c7779

function url(m::Method)
M = m.module
(m.file == :null || m.file == :string) && return ""
file = string(m.file)
line = m.line
line <= 0 || occursin(r"In\[[0-9]+\]", file) && return ""
Sys.iswindows() && (file = replace(file, '\\' => '/'))
libgit2_id = PkgId(UUID((0x76f85450_5226_5b5a,0x8eaa_529ad045b433)), "LibGit2")
if inbase(M)
if isempty(Base.GIT_VERSION_INFO.commit)
# this url will only work if we're on a tagged release
return "https://github.com/JuliaLang/julia/tree/v$VERSION/base/$file#L$line"
else
return "https://github.com/JuliaLang/julia/tree/$(Base.GIT_VERSION_INFO.commit)/base/$file#L$line"
end
elseif root_module_exists(libgit2_id)
LibGit2 = root_module(libgit2_id)
try
d = dirname(file)
return LibGit2.with(LibGit2.GitRepoExt(d)) do repo
LibGit2.with(LibGit2.GitConfig(repo)) do cfg
u = LibGit2.get(cfg, "remote.origin.url", "")
u = match(LibGit2.GITHUB_REGEX,u).captures[1]
commit = string(LibGit2.head_oid(repo))
root = LibGit2.path(repo)
if startswith(file, root) || startswith(realpath(file), root)
"https://github.com/$u/tree/$commit/"*file[length(root)+1:end]*"#L$line"
else
fileurl(file)
end
end
end
catch
return fileurl(file)
end
else
return fileurl(file)
end
end

The fix isn't too hard,
LibGit2 already contains a Regex that parses URLs.
And so one just needs to use that, to get the hostname rather than hard-coding to Github.
GitLab at least uses that exact same URL pattern as Github,
in terms of

https://$(host)/$(user)/tree/$(branch)/$(path)#L$(line)"

Cross-ref: #30139

@oxinabox
Copy link
Contributor Author

oxinabox commented Jan 2, 2019

CF: JuliaLang/Pkg.jl#960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant