Use GitHub wrapper for private tap check
This commit is contained in:
parent
3b818a19f9
commit
25c4e336f4
@ -31,20 +31,14 @@ module Homebrew extend self
|
||||
link_tap_formula(files)
|
||||
puts "Tapped #{files.length} formula"
|
||||
|
||||
# Figure out if this repo is private
|
||||
# curl will throw an exception if the repo is private (Github returns a 404)
|
||||
begin
|
||||
curl('-Ifso', '/dev/null', "https://api.github.com/repos/#{repouser}/homebrew-#{repo}")
|
||||
rescue
|
||||
puts
|
||||
puts "It looks like you tapped a private repository"
|
||||
puts "In order to not input your credentials every time"
|
||||
puts "you can use git HTTP credential caching or issue the"
|
||||
puts "following command:"
|
||||
puts
|
||||
puts " cd #{tapd}"
|
||||
puts " git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git"
|
||||
puts
|
||||
if private_tap?(repouser, repo) then puts <<-EOS.undent
|
||||
It looks like you tapped a private repository. To avoid entering your
|
||||
credentials each time you update, you can use git HTTP credential caching
|
||||
or issue the following command:
|
||||
|
||||
cd #{tapd}
|
||||
git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git
|
||||
EOS
|
||||
end
|
||||
|
||||
true
|
||||
@ -114,6 +108,13 @@ module Homebrew extend self
|
||||
[$1, $3]
|
||||
end
|
||||
|
||||
def private_tap?(user, repo)
|
||||
GitHub.private_repo?(user, "homebrew-#{repo}")
|
||||
rescue GitHub::HTTPNotFoundError => e
|
||||
true
|
||||
rescue GitHub::Error
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -253,6 +253,7 @@ module GitHub extend self
|
||||
|
||||
Error = Class.new(StandardError)
|
||||
RateLimitExceededError = Class.new(Error)
|
||||
HTTPNotFoundError = Class.new(Error)
|
||||
|
||||
def open url, headers={}, &block
|
||||
# This is a no-op if the user is opting out of using the GitHub API.
|
||||
@ -276,6 +277,8 @@ module GitHub extend self
|
||||
You may want to create an API token: https://github.com/settings/applications
|
||||
and then set HOMEBREW_GITHUB_API_TOKEN.
|
||||
EOS
|
||||
elsif e.io.status.first == "404"
|
||||
raise HTTPNotFoundError, e.message, e.backtrace
|
||||
else
|
||||
raise Error, e.message, e.backtrace
|
||||
end
|
||||
@ -334,4 +337,9 @@ module GitHub extend self
|
||||
|
||||
prs.each {|i| yield "#{i["title"]} (#{i["pull_request"]["html_url"]})" }
|
||||
end
|
||||
|
||||
def private_repo?(user, repo)
|
||||
uri = URI.parse("https://api.github.com/repos/#{user}/#{repo}")
|
||||
open(uri) { |json| json["private"] }
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user