info: improve github_info
* use Homebrew.git_origin * Handle the case git is unavailable or `.git` doesn't exist * Handle the case origin isn't github repo
This commit is contained in:
parent
c8efb05826
commit
2b835551d7
@ -58,23 +58,31 @@ module Homebrew
|
|||||||
puts Utils::JSON.dump(json)
|
puts Utils::JSON.dump(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_fork
|
def github_remote_path(remote, path)
|
||||||
if (HOMEBREW_REPOSITORY/".git").directory?
|
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
|
||||||
if `git remote -v` =~ %r{origin\s+(https?://|git(?:@|://))github.com[:/](.+)/homebrew}
|
"https://github.com/#{$1}/#{$2}/blob/master/#{path}"
|
||||||
$2
|
else
|
||||||
end
|
"#{remote}/#{path}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_info(f)
|
def github_info(f)
|
||||||
if f.tap?
|
if f.tap?
|
||||||
user, repo = f.tap.split("/", 2)
|
user, repo = f.tap.split("/", 2)
|
||||||
path = f.path.relative_path_from(HOMEBREW_LIBRARY.join("Taps", f.tap))
|
tap = Tap.new user, repo.gsub(/^homebrew-/, "")
|
||||||
"https://github.com/#{user}/#{repo}/blob/master/#{path}"
|
if remote = tap.remote
|
||||||
|
path = f.path.relative_path_from(tap.path)
|
||||||
|
github_remote_path(remote, path)
|
||||||
|
else
|
||||||
|
f.path
|
||||||
|
end
|
||||||
elsif f.core_formula?
|
elsif f.core_formula?
|
||||||
user = f.path.parent.cd { github_fork }
|
if remote = git_origin
|
||||||
path = f.path.relative_path_from(HOMEBREW_REPOSITORY)
|
path = f.path.relative_path_from(HOMEBREW_REPOSITORY)
|
||||||
"https://github.com/#{user}/homebrew/blob/master/#{path}"
|
github_remote_path(remote, path)
|
||||||
|
else
|
||||||
|
f.path
|
||||||
|
end
|
||||||
else
|
else
|
||||||
f.path
|
f.path
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user