diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 1bd005c8ef..beaa14edad 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -46,6 +46,8 @@ module Homebrew switch "--desc", description: "Search for formulae with a description matching and casks with "\ "a name matching ." + switch "--pull-request", + description: "Search for GitHub pull requests for ." package_manager_switches = PACKAGE_MANAGERS.keys.map { |name| "--#{name}" } package_manager_switches.each do |s| @@ -53,6 +55,7 @@ module Homebrew description: "Search for in the given package manager's list." end + conflicts("--desc", "--pull-request") conflicts(*package_manager_switches) end end @@ -83,6 +86,8 @@ module Homebrew if args.desc? search_descriptions(string_or_regex) + elsif args.pull_request? + GitHub.print_pull_requests_matching(query) else remote_results = search_taps(query, silent: true) @@ -108,20 +113,17 @@ module Homebrew puts Formatter.columns(all_casks) end - if $stdout.tty? - count = all_formulae.count + all_casks.count + count = all_formulae.count + all_casks.count - if (reason = MissingFormula.reason(query, silent: true)) && !local_casks.include?(query) - if count.positive? - puts - puts "If you meant #{query.inspect} specifically:" - end - puts reason - elsif count.zero? - puts "No formula or cask found for #{query.inspect}." - GitHub.print_pull_requests_matching(query) + if $stdout.tty? && (reason = MissingFormula.reason(query, silent: true)) && !local_casks.include?(query) + if count.positive? + puts + puts "If you meant #{query.inspect} specifically:" end + puts reason end + + raise "No formulae or casks found for #{query.inspect}." if count.zero? end return unless $stdout.tty? diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index b18a203d11..2e12875b74 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -352,16 +352,24 @@ module GitHub def print_pull_requests_matching(query) 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? - puts "Open pull requests:" - open_prs - else - puts "Closed pull requests:" unless open_or_closed_prs.empty? - open_or_closed_prs.take(20) + open_prs, closed_prs = open_or_closed_prs.partition { |pr| pr["state"] == "open" } + .map { |prs| prs.map { |pr| "#{pr["title"]} (#{pr["html_url"]})" } } + + if open_prs.present? + ohai "Open pull requests" + open_prs.each { |pr| puts pr } end - prs.each { |i| puts "#{i["title"]} (#{i["html_url"]})" } + if closed_prs.present? + puts if open_prs.present? + + ohai "Closed pull requests" + closed_prs.take(20).each { |pr| puts pr } + + puts "..." if closed_prs.count > 20 + end + + puts "No pull requests found for #{query.inspect}" if open_prs.blank? && closed_prs.blank? end def create_fork(repo) diff --git a/docs/Manpage.md b/docs/Manpage.md index 3d2d523253..e2e645e32a 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -515,6 +515,8 @@ No online search is performed. Without *`text`*, list all locally available casks (including tapped ones, no online search is performed). With *`text`*, search online and locally for casks. * `--desc`: Search for formulae with a description matching *`text`* and casks with a name matching *`text`*. +* `--pull-request`: + Search for GitHub pull requests for *`text`*. * `--macports`: Search for *`text`* in the given package manager's list. * `--fink`: diff --git a/manpages/brew.1 b/manpages/brew.1 index 6d57c7068e..186b784c4f 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -740,6 +740,10 @@ Without \fItext\fR, list all locally available casks (including tapped ones, no Search for formulae with a description matching \fItext\fR and casks with a name matching \fItext\fR\. . .TP +\fB\-\-pull\-request\fR +Search for GitHub pull requests for \fItext\fR\. +. +.TP \fB\-\-macports\fR Search for \fItext\fR in the given package manager\'s list\. .