diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 25052f3e4f..346b7beae1 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -51,7 +51,13 @@ module Homebrew "a name matching ." switch "--pull-request", description: "Search for GitHub pull requests containing ." - + switch "--open", + depends_on: "--pull-request", + description: "Search for only open GitHub pull requests" + switch "--closed", + depends_on: "--pull-request", + description: "Search for only closed GitHub pull requests" + conflicts "--open", "--closed" package_manager_switches = PACKAGE_MANAGERS.keys.map { |name| "--#{name}" } package_manager_switches.each do |s| switch s, @@ -91,7 +97,13 @@ module Homebrew if args.desc? search_descriptions(string_or_regex) elsif args.pull_request? - GitHub.print_pull_requests_matching(query) + only = if args.open? && !args.closed? + "open" + elsif args.closed? && !args.open? + "closed" + end + + GitHub.print_pull_requests_matching(query, only) else remote_results = search_taps(query, silent: true) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index ff0ae53d8a..cdeb22a30d 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -342,8 +342,8 @@ module GitHub open_api(url, data: data, request_method: :PUT, scopes: CREATE_ISSUE_FORK_OR_PR_SCOPES) end - def print_pull_requests_matching(query) - open_or_closed_prs = search_issues(query, type: "pr", user: "Homebrew") + def print_pull_requests_matching(query, only = nil) + open_or_closed_prs = search_issues(query, is: only, type: "pr", user: "Homebrew") open_prs, closed_prs = open_or_closed_prs.partition { |pr| pr["state"] == "open" } .map { |prs| prs.map { |pr| "#{pr["title"]} (#{pr["html_url"]})" } } diff --git a/docs/Manpage.md b/docs/Manpage.md index 7bc638a186..7dc4e9e596 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -486,6 +486,10 @@ No online search is performed. Search for formulae with a description matching *`text`* and casks with a name matching *`text`*. * `--pull-request`: Search for GitHub pull requests containing *`text`*. +* `--open`: + Search for only open GitHub pull requests +* `--closed`: + Search for only closed GitHub pull requests * `--macports`: Search for *`text`* in the given package manager's list. * `--fink`: diff --git a/manpages/brew.1 b/manpages/brew.1 index 5a8a4b8b13..b0a5ca5a2f 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -667,6 +667,14 @@ Search for formulae with a description matching \fItext\fR and casks with a name Search for GitHub pull requests containing \fItext\fR\. . .TP +\fB\-\-open\fR +Search for only open GitHub pull requests +. +.TP +\fB\-\-closed\fR +Search for only closed GitHub pull requests +. +.TP \fB\-\-macports\fR Search for \fItext\fR in the given package manager\'s list\. .