From 2bda194bd91c0767517fe11adafcaacb3150aff0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Apr 2017 19:31:21 +0200 Subject: Add `GitHub::search_code` method. --- Library/Homebrew/utils/github.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Library/Homebrew/utils/github.rb') 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 -- cgit v1.2.3 From 133e5ddf6ad1b7c931f4686922ba4d61ea450f3a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Apr 2017 19:44:03 +0200 Subject: Remove unnecessary block. --- Library/Homebrew/utils/github.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/utils/github.rb') diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 2daa23982..88c5199c2 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -234,7 +234,7 @@ module GitHub end def repository(user, repo) - open(URI.parse("#{API_URL}/repos/#{user}/#{repo}")) { |j| j } + open(URI.parse("#{API_URL}/repos/#{user}/#{repo}")) end def search_code(*params) -- cgit v1.2.3