Allow passing arbitrary qualifiers to issue search
This commit is contained in:
parent
0b2c6e87f1
commit
f5ceae9f94
@ -288,12 +288,27 @@ module GitHub extend self
|
|||||||
raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
|
raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
|
||||||
end
|
end
|
||||||
|
|
||||||
def issues_matching(query)
|
def issues_matching(query, qualifiers={})
|
||||||
uri = ISSUES_URI.dup
|
uri = ISSUES_URI.dup
|
||||||
uri.query = "q=#{uri_escape(query)}+repo:Homebrew/homebrew+in:title&per_page=100"
|
uri.query = build_query_string(query, qualifiers)
|
||||||
open(uri) { |json| json["items"] }
|
open(uri) { |json| json["items"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_query_string(query, qualifiers)
|
||||||
|
s = "q=#{uri_escape(query)}+"
|
||||||
|
s << build_search_qualifier_string(qualifiers)
|
||||||
|
s << "&per_page=100"
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_search_qualifier_string(qualifiers)
|
||||||
|
{
|
||||||
|
:repo => "Homebrew/homebrew",
|
||||||
|
:in => "title",
|
||||||
|
}.update(qualifiers).map { |qualifier, value|
|
||||||
|
"#{qualifier}:#{value}"
|
||||||
|
}.join("+")
|
||||||
|
end
|
||||||
|
|
||||||
def uri_escape(query)
|
def uri_escape(query)
|
||||||
if URI.respond_to?(:encode_www_form_component)
|
if URI.respond_to?(:encode_www_form_component)
|
||||||
URI.encode_www_form_component(query)
|
URI.encode_www_form_component(query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user