aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils.rb
diff options
context:
space:
mode:
authorDaniel Lee Harple2013-05-07 14:07:25 -0400
committerJack Nagel2013-05-22 19:53:01 -0500
commit222f96d37b3c41b0538e96245ab37c6f01b872c2 (patch)
tree030dec328301b16090bd5486328b90fac6ad1ffc /Library/Homebrew/utils.rb
parent0bf35a05a9140cf5da59f236927a07cd689fd123 (diff)
downloadbrew-222f96d37b3c41b0538e96245ab37c6f01b872c2.tar.bz2
Pass a User-Agent when fetching data from the GitHub API
See <http://developer.github.com/v3/#user-agent-required>. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew/utils.rb')
-rw-r--r--Library/Homebrew/utils.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 81068e9ef..7506c87a4 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -257,6 +257,11 @@ def nostdout
end
module GitHub extend self
+ def open url, headers={}, &block
+ require 'open-uri'
+ Kernel.open(url, headers.merge('User-Agent' => HOMEBREW_USER_AGENT), &block)
+ end
+
def issues_for_formula name
# bit basic as depends on the issue at github having the exact name of the
# formula in it. Which for stuff like objective-caml is unlikely. So we
@@ -264,7 +269,6 @@ module GitHub extend self
name = f.name if Formula === name
- require 'open-uri'
require 'vendor/multi_json'
issues = []
@@ -284,13 +288,12 @@ module GitHub extend self
end
def find_pull_requests rx
- require 'open-uri'
require 'vendor/multi_json'
query = rx.source.delete('.*').gsub('\\', '')
uri = URI.parse("https://api.github.com/legacy/issues/search/mxcl/homebrew/open/#{query}")
- open uri do |f|
+ GitHub.open uri do |f|
MultiJson.decode(f.read)['issues'].each do |pull|
yield pull['pull_request_url'] if rx.match pull['title'] and pull['pull_request_url']
end