Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Commit Search API preview #959

Merged
merged 9 commits into from
Mar 6, 2018
15 changes: 15 additions & 0 deletions lib/octokit/client/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ def search_code(query, options = {})
search "search/code", query, options
end

# Search commits
#
# @param query [String] Search terms and qualifiers
# @param options [Hash] Sort and pagination options
# @option options [String] :sort Sort field

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Field to sort by instead of Sort field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was matching the language of the other option descriptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the rest of the codebase uses Sort field. Some endpoints also mention what the available sort options are, but many do not.

# @option options [String] :order Sort order (asc or desc)
# @option options [Integer] :page Page of paginated results
# @option options [Integer] :per_page Number of items per page
# @return [Sawyer::Resource] Search results object
# @see https://developer.github.com/v3/search/#search-commits
def search_commits(query, options = {})
options = ensure_api_media_type(:commit_search, options)
search "search/commits", query, options
end

# Search issues
#
# @param query [String] Search term and qualifiers
Expand Down
1 change: 1 addition & 0 deletions lib/octokit/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Preview

PREVIEW_TYPES = {
:branch_protection => 'application/vnd.github.loki-preview+json'.freeze,
:commit_search => 'application/vnd.github.cloak-preview+json'.freeze,
:migrations => 'application/vnd.github.wyandotte-preview+json'.freeze,
:licenses => 'application/vnd.github.drax-preview+json'.freeze,
:source_imports => 'application/vnd.github.barred-rock-preview'.freeze,
Expand Down
16 changes: 16 additions & 0 deletions spec/octokit/client/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
end
end # .search_code

describe ".search_commits" do
it "searches commits", :vcr do
results = @client.search_commits 'repo:octokit/octokit.rb author:jasonrudolph', \
:sort => 'author-date',
:order => 'asc',
:accept => preview_header

assert_requested :get, github_url('/search/commits?q=repo:octokit/octokit.rb%20author:jasonrudolph&sort=author-date&order=asc')
expect(results.total_count).to be_kind_of Integer
expect(results.items).to be_kind_of Array
end
end # .search_commits

describe ".search_issues" do
it "searches issues", :vcr do
results = @client.search_issues 'http author:jasonrudolph', \
Expand Down Expand Up @@ -63,5 +76,8 @@
end
end # .search_users

def preview_header
Octokit::Preview::PREVIEW_TYPES[:commit_search]
end
end