Skip to content
Snippets Groups Projects
Commit a65f649c authored by Mike McQuaid's avatar Mike McQuaid
Browse files

utils: improve issue searching.

* issues_matching now returns an array
* prints issues titles and URLs
* find_pull_requests shows closed PRs if no matching PRs are open

Closes Homebrew/homebrew#26032.
parent 28143fb6
No related branches found
No related tags found
No related merge requests found
......@@ -211,7 +211,7 @@ class BuildError < Homebrew::InstallationError
puts
unless RUBY_VERSION < "1.8.6" || issues.empty?
puts "These open issues may also help:"
puts issues.map{ |s| " #{s}" }.join("\n")
puts issues.map{ |i| "#{i['title']} (#{i['html_url']})" }.join("\n")
end
end
end
......
......@@ -276,9 +276,9 @@ module GitHub extend self
raise Error, "Failed to connect to: #{url}\n#{e.message}"
end
def each_issue_matching(query, &block)
def issues_matching(query)
uri = ISSUES_URI + uri_escape(query)
open(uri) { |f| Utils::JSON.load(f.read)['issues'].each(&block) }
open(uri) { |f| Utils::JSON.load(f.read)['issues'] }
end
def uri_escape(query)
......@@ -297,26 +297,30 @@ module GitHub extend self
name = f.name if Formula === name
issues = []
each_issue_matching(name) do |issue|
# don't include issues that just refer to the tool in their body
issues << issue['html_url'] if issue['title'].include? name
end
issues
# don't include issues that just refer to the tool in their body
issues_matching(name).select {|issue| issue['title'].include? name }
end
def find_pull_requests rx
return if ENV['HOMEBREW_NO_GITHUB_API']
puts "Searching open pull requests..."
puts "Searching pull requests..."
query = rx.source.delete('.*').gsub('\\', '')
each_issue_matching(query) do |issue|
if rx === issue['title'] && issue.has_key?('pull_request_url') && issue['state'] != 'closed'
yield issue['pull_request_url']
end
open_or_closed_prs = issues_matching(query).select do |issue|
rx === issue['title'] && issue.has_key?('pull_request_url')
end
open_prs = open_or_closed_prs.select {|i| i['state'] != 'closed' }
if open_prs.any?
puts "Open pull requests:"
prs = open_prs
elsif open_or_closed_prs.any?
puts "Closed pull requests:"
prs = open_or_closed_prs
else
return
end
prs.each {|i| yield "#{i['title']} (#{i['pull_request_url']})" }
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment