aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/github.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-04-24 19:31:21 +0200
committerMarkus Reiter2017-04-25 12:29:01 +0200
commit2bda194bd91c0767517fe11adafcaacb3150aff0 (patch)
treedea3630c20a546cc294fb0cb313321b51b4553cd /Library/Homebrew/utils/github.rb
parenta38133e5a116ac3e08a856e38ce76dc5453a963f (diff)
downloadbrew-2bda194bd91c0767517fe11adafcaacb3150aff0.tar.bz2
Add `GitHub::search_code` method.
Diffstat (limited to 'Library/Homebrew/utils/github.rb')
-rw-r--r--Library/Homebrew/utils/github.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb
index a5ed5394a..2daa23982 100644
--- a/Library/Homebrew/utils/github.rb
+++ b/Library/Homebrew/utils/github.rb
@@ -4,7 +4,7 @@ require "tempfile"
module GitHub
module_function
- ISSUES_URI = URI.parse("https://api.github.com/search/issues")
+ API_URL = "https://api.github.com".freeze
CREATE_GIST_SCOPES = ["gist"].freeze
CREATE_ISSUE_SCOPES = ["public_repo"].freeze
@@ -228,13 +228,19 @@ module GitHub
end
def issues_matching(query, qualifiers = {})
- uri = ISSUES_URI.dup
+ uri = URI.parse("#{API_URL}/search/issues")
uri.query = build_query_string(query, qualifiers)
open(uri) { |json| json["items"] }
end
def repository(user, repo)
- open(URI.parse("https://api.github.com/repos/#{user}/#{repo}")) { |j| j }
+ open(URI.parse("#{API_URL}/repos/#{user}/#{repo}")) { |j| j }
+ end
+
+ def search_code(*params)
+ uri = URI.parse("#{API_URL}/search/code")
+ uri.query = "q=#{uri_escape(params.join(" "))}"
+ open(uri) { |json| json["items"] }
end
def build_query_string(query, qualifiers)
@@ -286,7 +292,7 @@ module GitHub
end
def private_repo?(user, repo)
- uri = URI.parse("https://api.github.com/repos/#{user}/#{repo}")
+ uri = URI.parse("#{API_URL}/repos/#{user}/#{repo}")
open(uri) { |json| json["private"] }
end
end