search: add two options

This commit is contained in:
hyuraku 2020-12-23 23:06:02 +09:00
parent 993bf95877
commit 0b574eff90
4 changed files with 28 additions and 4 deletions

View File

@ -51,7 +51,13 @@ module Homebrew
"a name matching <text>." "a name matching <text>."
switch "--pull-request", switch "--pull-request",
description: "Search for GitHub pull requests containing <text>." description: "Search for GitHub pull requests containing <text>."
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 = PACKAGE_MANAGERS.keys.map { |name| "--#{name}" }
package_manager_switches.each do |s| package_manager_switches.each do |s|
switch s, switch s,
@ -91,7 +97,13 @@ module Homebrew
if args.desc? if args.desc?
search_descriptions(string_or_regex) search_descriptions(string_or_regex)
elsif args.pull_request? 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 else
remote_results = search_taps(query, silent: true) remote_results = search_taps(query, silent: true)

View File

@ -342,8 +342,8 @@ module GitHub
open_api(url, data: data, request_method: :PUT, scopes: CREATE_ISSUE_FORK_OR_PR_SCOPES) open_api(url, data: data, request_method: :PUT, scopes: CREATE_ISSUE_FORK_OR_PR_SCOPES)
end end
def print_pull_requests_matching(query) def print_pull_requests_matching(query, only = nil)
open_or_closed_prs = search_issues(query, type: "pr", user: "Homebrew") 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" } open_prs, closed_prs = open_or_closed_prs.partition { |pr| pr["state"] == "open" }
.map { |prs| prs.map { |pr| "#{pr["title"]} (#{pr["html_url"]})" } } .map { |prs| prs.map { |pr| "#{pr["title"]} (#{pr["html_url"]})" } }

View File

@ -486,6 +486,10 @@ No online search is performed.
Search for formulae with a description matching *`text`* and casks with a name matching *`text`*. Search for formulae with a description matching *`text`* and casks with a name matching *`text`*.
* `--pull-request`: * `--pull-request`:
Search for GitHub pull requests containing *`text`*. Search for GitHub pull requests containing *`text`*.
* `--open`:
Search for only open GitHub pull requests
* `--closed`:
Search for only closed GitHub pull requests
* `--macports`: * `--macports`:
Search for *`text`* in the given package manager's list. Search for *`text`* in the given package manager's list.
* `--fink`: * `--fink`:

View File

@ -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\. Search for GitHub pull requests containing \fItext\fR\.
. .
.TP .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 \fB\-\-macports\fR
Search for \fItext\fR in the given package manager\'s list\. Search for \fItext\fR in the given package manager\'s list\.
. .