Add HOMEBREW_NO_GITHUB_API env var.

This patch allows users to "opt out" of using the GitHub API altogether
by setting the HOMEBREW_NO_GITHUB_API environment variable. The
value of the environment variable does not matter (it can even be
empty!).

For Bash/ZSH: export HOMEBREW_NO_GITHUB_API=1

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
David MacMahon 2013-10-22 16:18:31 -07:00 committed by Mike McQuaid
parent 5b433bb05a
commit a999ddc002
4 changed files with 16 additions and 2 deletions

View File

@ -524,6 +524,10 @@ can take several different forms:
*Note:* Homebrew will only try to print emoji on Lion or newer. *Note:* Homebrew will only try to print emoji on Lion or newer.
* HOMEBREW\_NO\_GITHUB\_API:
If set, Homebrew will not use the GitHub API for e.g searches or
fetching relevant issues on a failed install.
* HOMEBREW\_SOURCEFORGE\_MIRROR: * HOMEBREW\_SOURCEFORGE\_MIRROR:
If set, Homebrew will use the value of `HOMEBREW_SOURCEFORGE_MIRROR` to If set, Homebrew will use the value of `HOMEBREW_SOURCEFORGE_MIRROR` to
select a SourceForge mirror for downloading bottles. select a SourceForge mirror for downloading bottles.

View File

@ -61,7 +61,7 @@ module Homebrew extend self
count = local_results.length + tap_results.length count = local_results.length + tap_results.length
if count == 0 and not blacklisted? query if count == 0 and not blacklisted? query
puts "No formula found for #{query.inspect}. Searching open pull requests..." puts "No formula found for #{query.inspect}."
begin begin
GitHub.find_pull_requests(rx) { |pull| puts pull } GitHub.find_pull_requests(rx) { |pull| puts pull }
rescue GitHub::Error => e rescue GitHub::Error => e

View File

@ -254,6 +254,9 @@ module GitHub extend self
Error = Class.new(StandardError) Error = Class.new(StandardError)
def open url, headers={}, &block def open url, headers={}, &block
# This is a no-op if the user is opting out of using the GitHub API.
return if ENV['HOMEBREW_NO_GITHUB_API']
require 'net/https' # for exception classes below require 'net/https' # for exception classes below
default_headers = {'User-Agent' => HOMEBREW_USER_AGENT} default_headers = {'User-Agent' => HOMEBREW_USER_AGENT}
@ -296,6 +299,9 @@ module GitHub extend self
end end
def find_pull_requests rx def find_pull_requests rx
return if ENV['HOMEBREW_NO_GITHUB_API']
puts "Searching open pull requests..."
query = rx.source.delete('.*').gsub('\\', '') query = rx.source.delete('.*').gsub('\\', '')
each_issue_matching(query) do |issue| each_issue_matching(query) do |issue|

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "BREW" "1" "September 2013" "Homebrew" "brew" .TH "BREW" "1" "October 2013" "Homebrew" "brew"
. .
.SH "NAME" .SH "NAME"
\fBbrew\fR \- The missing package manager for OS X \fBbrew\fR \- The missing package manager for OS X
@ -557,6 +557,10 @@ If set, Homebrew will not print the beer emoji on a successful build\.
\fINote:\fR Homebrew will only try to print emoji on Lion or newer\. \fINote:\fR Homebrew will only try to print emoji on Lion or newer\.
. .
.TP .TP
HOMEBREW_NO_GITHUB_API
If set, Homebrew will not use the GitHub API for e\.g searches or fetching relevant issues on a failed install\.
.
.TP
HOMEBREW_SOURCEFORGE_MIRROR HOMEBREW_SOURCEFORGE_MIRROR
If set, Homebrew will use the value of \fBHOMEBREW_SOURCEFORGE_MIRROR\fR to select a SourceForge mirror for downloading bottles\. If set, Homebrew will use the value of \fBHOMEBREW_SOURCEFORGE_MIRROR\fR to select a SourceForge mirror for downloading bottles\.
. .