diff options
| author | Daniel Lee Harple | 2013-05-07 14:07:25 -0400 |
|---|---|---|
| committer | Jack Nagel | 2013-05-22 19:53:01 -0500 |
| commit | 222f96d37b3c41b0538e96245ab37c6f01b872c2 (patch) | |
| tree | 030dec328301b16090bd5486328b90fac6ad1ffc /Library | |
| parent | 0bf35a05a9140cf5da59f236927a07cd689fd123 (diff) | |
| download | brew-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')
| -rwxr-xr-x | Library/Contributions/cmd/brew-ls-taps.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/search.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 9 |
3 files changed, 9 insertions, 8 deletions
diff --git a/Library/Contributions/cmd/brew-ls-taps.rb b/Library/Contributions/cmd/brew-ls-taps.rb index f6c92ebc0..c3741656b 100755 --- a/Library/Contributions/cmd/brew-ls-taps.rb +++ b/Library/Contributions/cmd/brew-ls-taps.rb @@ -1,8 +1,7 @@ -require 'open-uri' require 'vendor/multi_json' begin - open "https://api.github.com/legacy/repos/search/homebrew" do |f| + GitHub.open "https://api.github.com/legacy/repos/search/homebrew" do |f| MultiJson.decode(f.read)["repositories"].each do |repo| if repo['name'] =~ /^homebrew-(\S+)$/ puts tap = if repo['username'] == "Homebrew" diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index f64bb5405..4ae2f314a 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -1,5 +1,6 @@ require "formula" require "blacklist" +require "utils" module Homebrew extend self def search @@ -59,12 +60,10 @@ module Homebrew extend self def search_tap user, repo, rx return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}-#{repo.downcase}").directory? - - require 'open-uri' require 'vendor/multi_json' results = [] - open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |f| + GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |f| user.downcase! if user == "Homebrew" # special handling for the Homebrew organization MultiJson.decode(f.read)["tree"].map{ |hash| hash['path'] }.compact.each do |file| name = File.basename(file, '.rb') 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 |
