From dc5a2c1764b1da3cfa85d8910338eb72cd4da96c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 4 Aug 2017 16:24:29 +0200 Subject: Simplify CurlDownloadStrategy. --- 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 1a781cee6..07eea4384 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, *args) + output, errors, status = curl_output(url.to_s, "--location", *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read -- cgit v1.2.3 From 986887b413897413266151c92d5071d0a82cf966 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Mon, 7 Aug 2017 14:31:56 -0700 Subject: Revert "Refactor SVN and cURL download strategies." --- 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 07eea4384..1a781cee6 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, "--location", *args) + output, errors, status = curl_output(url.to_s, *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read -- cgit v1.2.3 From ae4bafdb365cfa380d129b0a03bd99a1e4d960a4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 8 Aug 2017 18:10:13 +0200 Subject: Simplify CurlDownloadStrategy. --- 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 1a781cee6..07eea4384 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, *args) + output, errors, status = curl_output(url.to_s, "--location", *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read -- cgit v1.2.3 From e93ec12b32f3449f4669cf53469a4d5308b10cc3 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 13:10:38 -0400 Subject: Remove duplicate url generation logic in Github module --- Library/Homebrew/utils/github.rb | 57 +++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'Library/Homebrew/utils/github.rb') diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 07eea4384..6f56e505c 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -228,34 +228,15 @@ module GitHub end def issues_matching(query, qualifiers = {}) - uri = URI.parse("#{API_URL}/search/issues") - uri.query = build_query_string(query, qualifiers) - open(uri) { |json| json["items"] } + search("issues", query, **qualifiers) end def repository(user, repo) - open(URI.parse("#{API_URL}/repos/#{user}/#{repo}")) - 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) - s = "q=#{uri_escape(query)}+" - s << build_search_qualifier_string(qualifiers) - s << "&per_page=100" + open(path_to("repos", user, repo)) end - def build_search_qualifier_string(qualifiers) - { - repo: "Homebrew/homebrew-core", - in: "title", - }.update(qualifiers).map do |qualifier, value| - "#{qualifier}:#{value}" - end.join("+") + def search_code(**params) + search("code", **params) end def uri_escape(query) @@ -292,7 +273,35 @@ module GitHub end def private_repo?(full_name) - uri = URI.parse("#{API_URL}/repos/#{full_name}") + uri = path_to "repos", full_name open(uri) { |json| json["private"] } end + + def query_string(*main_params, **qualifiers) + params_list = main_params + + qualifiers.each do |key, value| + if value.is_a? Array + value.each { |v| params_list << format_parameter(key, v) } + else + params_list << format_parameter(key, v) + end + end + + "q=#{uri_escape(params_list.join(" "))}&per_page=100" + end + + def format_paramater(key, value) + "#{key}:#{value}" + end + + def path_to(*subroutes) + URI.parse(File.join(API_URL, *subroutes)) + end + + def search(entity, *queries, **qualifiers) + uri = path_to "search", entity + uri.query = query_string(*queries, **qualifiers) + open(uri) { |json| json["items"] } + end end -- cgit v1.2.3 From acf46fce5f08712084dc9454fee66637796055c6 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 15:01:37 -0400 Subject: Rename path_to -> url_to since it returns a url --- Library/Homebrew/utils/github.rb | 8 ++++---- 1 file changed, 4 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 6f56e505c..c10a8ed0d 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -232,7 +232,7 @@ module GitHub end def repository(user, repo) - open(path_to("repos", user, repo)) + open(url_to("repos", user, repo)) end def search_code(**params) @@ -273,7 +273,7 @@ module GitHub end def private_repo?(full_name) - uri = path_to "repos", full_name + uri = url_to "repos", full_name open(uri) { |json| json["private"] } end @@ -295,12 +295,12 @@ module GitHub "#{key}:#{value}" end - def path_to(*subroutes) + def url_to(*subroutes) URI.parse(File.join(API_URL, *subroutes)) end def search(entity, *queries, **qualifiers) - uri = path_to "search", entity + uri = url_to "search", entity uri.query = query_string(*queries, **qualifiers) open(uri) { |json| json["items"] } end -- cgit v1.2.3 From 91b139aca293bea1aa926c5301754e8603c9275e Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 16:15:26 -0400 Subject: Fix syntax error --- 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 c10a8ed0d..59c7d7ac8 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -284,7 +284,7 @@ module GitHub if value.is_a? Array value.each { |v| params_list << format_parameter(key, v) } else - params_list << format_parameter(key, v) + params_list << format_parameter(key, value) end end -- cgit v1.2.3 From d052f503f90ad08f6f889891e3fb72e97988a80e Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 16:41:18 -0400 Subject: fix typo --- 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 59c7d7ac8..05ef7e3c8 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -291,7 +291,7 @@ module GitHub "q=#{uri_escape(params_list.join(" "))}&per_page=100" end - def format_paramater(key, value) + def format_parameter(key, value) "#{key}:#{value}" end -- cgit v1.2.3 From 603bdd01a81e62d6b97a5da26d75d409e839a8fa Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Mon, 14 Aug 2017 11:08:56 -0400 Subject: Implement PR feedback --- Library/Homebrew/utils/github.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/utils/github.rb') diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 05ef7e3c8..960b563d9 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -296,12 +296,12 @@ module GitHub end def url_to(*subroutes) - URI.parse(File.join(API_URL, *subroutes)) + URI.parse([API_URL, *subroutes].join("/")) end def search(entity, *queries, **qualifiers) uri = url_to "search", entity uri.query = query_string(*queries, **qualifiers) - open(uri) { |json| json["items"] } + open(uri) { |json| Array(json["items"]) } end end -- cgit v1.2.3 From 68cdb550f7b90318a136e4dd484249ab678f5fbc Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Mon, 14 Aug 2017 11:41:29 -0400 Subject: Spec for issues search --- 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 960b563d9..8096c7b9c 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -266,7 +266,7 @@ module GitHub puts "Closed pull requests:" prs = open_or_closed_prs else - return + return [] end prs.each { |i| puts "#{i["title"]} (#{i["html_url"]})" } -- cgit v1.2.3 From 5f8d212ccccb8172985da9f71945fea6a8ea1b1a Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Mon, 14 Aug 2017 12:51:32 -0400 Subject: Unify vocabulary in github module, remove unnecessary logic Fix duplication bug --- Library/Homebrew/utils/github.rb | 43 +++++++++++----------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'Library/Homebrew/utils/github.rb') diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 8096c7b9c..cff292598 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -227,7 +227,7 @@ module GitHub end end - def issues_matching(query, qualifiers = {}) + def search_issues(query, **qualifiers) search("issues", query, **qualifiers) end @@ -235,38 +235,27 @@ module GitHub open(url_to("repos", user, repo)) end - def search_code(**params) - search("code", **params) - end - - def uri_escape(query) - if URI.respond_to?(:encode_www_form_component) - URI.encode_www_form_component(query) - else - require "erb" - ERB::Util.url_encode(query) - end + def search_code(**qualifiers) + search("code", **qualifiers) end def issues_for_formula(name, options = {}) tap = options[:tap] || CoreTap.instance - issues_matching(name, state: "open", repo: "#{tap.user}/homebrew-#{tap.repo}") + search_issues(name, state: "open", repo: "#{tap.user}/homebrew-#{tap.repo}") end def print_pull_requests_matching(query) return [] if ENV["HOMEBREW_NO_GITHUB_API"] - open_or_closed_prs = issues_matching(query, type: "pr") + open_or_closed_prs = search_issues(query, type: "pr") open_prs = open_or_closed_prs.select { |i| i["state"] == "open" } - if !open_prs.empty? + prs = if !open_prs.empty? puts "Open pull requests:" - prs = open_prs - elsif !open_or_closed_prs.empty? - puts "Closed pull requests:" - prs = open_or_closed_prs + open_prs else - return [] + puts "Closed pull requests:" unless open_or_closed_prs.empty? + open_or_closed_prs end prs.each { |i| puts "#{i["title"]} (#{i["html_url"]})" } @@ -280,19 +269,11 @@ module GitHub def query_string(*main_params, **qualifiers) params_list = main_params - qualifiers.each do |key, value| - if value.is_a? Array - value.each { |v| params_list << format_parameter(key, v) } - else - params_list << format_parameter(key, value) - end + params_list += qualifiers.flat_map do |key, value| + Array(value).map { |v| "#{key}:#{v}" } end - "q=#{uri_escape(params_list.join(" "))}&per_page=100" - end - - def format_parameter(key, value) - "#{key}:#{value}" + "q=#{URI.encode_www_form_component(params_list.join(" "))}&per_page=100" end def url_to(*subroutes) -- cgit v1.2.3 From ca05c7f010ed952b316fe541f94a8fc2a83446ec Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Thu, 17 Aug 2017 14:38:50 -0400 Subject: Change var name --- Library/Homebrew/utils/github.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Library/Homebrew/utils/github.rb') diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index cff292598..578d967a4 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -267,13 +267,13 @@ module GitHub end def query_string(*main_params, **qualifiers) - params_list = main_params + params = main_params - params_list += qualifiers.flat_map do |key, value| + params += qualifiers.flat_map do |key, value| Array(value).map { |v| "#{key}:#{v}" } end - "q=#{URI.encode_www_form_component(params_list.join(" "))}&per_page=100" + "q=#{URI.encode_www_form_component(params.join(" "))}&per_page=100" end def url_to(*subroutes) -- cgit v1.2.3 From 56ef168e7088962ba7b1cdc3da89d30842a8eb69 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 20 Aug 2017 16:23:15 +0200 Subject: Move fix from #3070 inside `GitHub` module. --- Library/Homebrew/utils/github.rb | 6 ++---- 1 file changed, 2 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 578d967a4..a1cf5fbba 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -133,7 +133,7 @@ module GitHub def open(url, data: nil, scopes: [].freeze) # This is a no-op if the user is opting out of using the GitHub API. - return if ENV["HOMEBREW_NO_GITHUB_API"] + return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"] args = %W[--header application/vnd.github.v3+json --write-out \n%{http_code}] args += curl_args @@ -245,8 +245,6 @@ module GitHub end def print_pull_requests_matching(query) - return [] if ENV["HOMEBREW_NO_GITHUB_API"] - open_or_closed_prs = search_issues(query, type: "pr") open_prs = open_or_closed_prs.select { |i| i["state"] == "open" } @@ -283,6 +281,6 @@ module GitHub def search(entity, *queries, **qualifiers) uri = url_to "search", entity uri.query = query_string(*queries, **qualifiers) - open(uri) { |json| Array(json["items"]) } + open(uri) { |json| json.fetch("items", []) } end end -- cgit v1.2.3 From 0ea4da4ef6bca28e2225f79cd0c6c9210eee8f7f Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Thu, 31 Aug 2017 03:59:33 +0100 Subject: github: limit PR search to Homebrew Not sure whether this is the way you want to handle this problem but it's really darn irritating so here's a PR that handles it one way. Fixes: https://github.com/Homebrew/brew/pull/3086#issuecomment-324519156 --- 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 a1cf5fbba..a50d6d8e5 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -245,7 +245,7 @@ module GitHub end def print_pull_requests_matching(query) - open_or_closed_prs = search_issues(query, type: "pr") + open_or_closed_prs = search_issues(query, type: "pr", user: "Homebrew") open_prs = open_or_closed_prs.select { |i| i["state"] == "open" } prs = if !open_prs.empty? -- cgit v1.2.3 From cf5fdeef1d8e9fd053121145882835b87eec2a43 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 24 Sep 2017 20:12:58 +0100 Subject: Rubocop: manual rule fixes. --- Library/Homebrew/utils/github.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'Library/Homebrew/utils/github.rb') diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index a50d6d8e5..df0811e95 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -86,15 +86,9 @@ module GitHub def api_credentials_type token, username = api_credentials - if token && !token.empty? - if username && !username.empty? - :keychain - else - :environment - end - else - :none - end + return :none if !token || token.empty? + return :keychain if !username || username.empty? + :environment end def api_credentials_error_message(response_headers, needed_scopes) -- cgit v1.2.3