Browse Source

Adding missing field to search results

Added the field incomplete_results. It is docummented on https://developer.github.com/v3/search/#timeouts-and-incomplete-results
Juan Basso 9 years ago
parent
commit
b969816466
No known key found for this signature in database GPG Key ID: 609DC24D13F096C
2 changed files with 32 additions and 22 deletions
  1. +12
    -8
      github/search.go
  2. +20
    -14
      github/search_test.go

+ 12
- 8
github/search.go View File

@ -40,8 +40,9 @@ type SearchOptions struct {
// RepositoriesSearchResult represents the result of a repositories search. // RepositoriesSearchResult represents the result of a repositories search.
type RepositoriesSearchResult struct { type RepositoriesSearchResult struct {
Total *int `json:"total_count,omitempty"`
Repositories []Repository `json:"items,omitempty"`
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Repositories []Repository `json:"items,omitempty"`
} }
// Repositories searches repositories via various criteria. // Repositories searches repositories via various criteria.
@ -55,8 +56,9 @@ func (s *SearchService) Repositories(query string, opt *SearchOptions) (*Reposit
// IssuesSearchResult represents the result of an issues search. // IssuesSearchResult represents the result of an issues search.
type IssuesSearchResult struct { type IssuesSearchResult struct {
Total *int `json:"total_count,omitempty"`
Issues []Issue `json:"items,omitempty"`
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Issues []Issue `json:"items,omitempty"`
} }
// Issues searches issues via various criteria. // Issues searches issues via various criteria.
@ -70,8 +72,9 @@ func (s *SearchService) Issues(query string, opt *SearchOptions) (*IssuesSearchR
// UsersSearchResult represents the result of an issues search. // UsersSearchResult represents the result of an issues search.
type UsersSearchResult struct { type UsersSearchResult struct {
Total *int `json:"total_count,omitempty"`
Users []User `json:"items,omitempty"`
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Users []User `json:"items,omitempty"`
} }
// Users searches users via various criteria. // Users searches users via various criteria.
@ -104,8 +107,9 @@ func (tm TextMatch) String() string {
// CodeSearchResult represents the result of an code search. // CodeSearchResult represents the result of an code search.
type CodeSearchResult struct { type CodeSearchResult struct {
Total *int `json:"total_count,omitempty"`
CodeResults []CodeResult `json:"items,omitempty"`
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
CodeResults []CodeResult `json:"items,omitempty"`
} }
// CodeResult represents a single search result. // CodeResult represents a single search result.


+ 20
- 14
github/search_test.go View File

@ -27,7 +27,7 @@ func TestSearchService_Repositories(t *testing.T) {
"per_page": "2", "per_page": "2",
}) })
fmt.Fprint(w, `{"total_count": 4, "items": [{"id":1},{"id":2}]}`)
fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"id":1},{"id":2}]}`)
}) })
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}} opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
@ -37,8 +37,9 @@ func TestSearchService_Repositories(t *testing.T) {
} }
want := &RepositoriesSearchResult{ want := &RepositoriesSearchResult{
Total: Int(4),
Repositories: []Repository{{ID: Int(1)}, {ID: Int(2)}},
Total: Int(4),
IncompleteResults: Bool(false),
Repositories: []Repository{{ID: Int(1)}, {ID: Int(2)}},
} }
if !reflect.DeepEqual(result, want) { if !reflect.DeepEqual(result, want) {
t.Errorf("Search.Repositories returned %+v, want %+v", result, want) t.Errorf("Search.Repositories returned %+v, want %+v", result, want)
@ -59,7 +60,7 @@ func TestSearchService_Issues(t *testing.T) {
"per_page": "2", "per_page": "2",
}) })
fmt.Fprint(w, `{"total_count": 4, "items": [{"number":1},{"number":2}]}`)
fmt.Fprint(w, `{"total_count": 4, "incomplete_results": true, "items": [{"number":1},{"number":2}]}`)
}) })
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}} opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
@ -69,8 +70,9 @@ func TestSearchService_Issues(t *testing.T) {
} }
want := &IssuesSearchResult{ want := &IssuesSearchResult{
Total: Int(4),
Issues: []Issue{{Number: Int(1)}, {Number: Int(2)}},
Total: Int(4),
IncompleteResults: Bool(true),
Issues: []Issue{{Number: Int(1)}, {Number: Int(2)}},
} }
if !reflect.DeepEqual(result, want) { if !reflect.DeepEqual(result, want) {
t.Errorf("Search.Issues returned %+v, want %+v", result, want) t.Errorf("Search.Issues returned %+v, want %+v", result, want)
@ -91,7 +93,7 @@ func TestSearchService_Users(t *testing.T) {
"per_page": "2", "per_page": "2",
}) })
fmt.Fprint(w, `{"total_count": 4, "items": [{"id":1},{"id":2}]}`)
fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"id":1},{"id":2}]}`)
}) })
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}} opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
@ -101,8 +103,9 @@ func TestSearchService_Users(t *testing.T) {
} }
want := &UsersSearchResult{ want := &UsersSearchResult{
Total: Int(4),
Users: []User{{ID: Int(1)}, {ID: Int(2)}},
Total: Int(4),
IncompleteResults: Bool(false),
Users: []User{{ID: Int(1)}, {ID: Int(2)}},
} }
if !reflect.DeepEqual(result, want) { if !reflect.DeepEqual(result, want) {
t.Errorf("Search.Users returned %+v, want %+v", result, want) t.Errorf("Search.Users returned %+v, want %+v", result, want)
@ -123,7 +126,7 @@ func TestSearchService_Code(t *testing.T) {
"per_page": "2", "per_page": "2",
}) })
fmt.Fprint(w, `{"total_count": 4, "items": [{"name":"1"},{"name":"2"}]}`)
fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"name":"1"},{"name":"2"}]}`)
}) })
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}} opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
@ -133,8 +136,9 @@ func TestSearchService_Code(t *testing.T) {
} }
want := &CodeSearchResult{ want := &CodeSearchResult{
Total: Int(4),
CodeResults: []CodeResult{{Name: String("1")}, {Name: String("2")}},
Total: Int(4),
IncompleteResults: Bool(false),
CodeResults: []CodeResult{{Name: String("1")}, {Name: String("2")}},
} }
if !reflect.DeepEqual(result, want) { if !reflect.DeepEqual(result, want) {
t.Errorf("Search.Code returned %+v, want %+v", result, want) t.Errorf("Search.Code returned %+v, want %+v", result, want)
@ -151,6 +155,7 @@ func TestSearchService_CodeTextMatch(t *testing.T) {
textMatchResponse := ` textMatchResponse := `
{ {
"total_count": 1, "total_count": 1,
"incomplete_results": false,
"items": [ "items": [
{ {
"name":"gopher1", "name":"gopher1",
@ -192,8 +197,9 @@ func TestSearchService_CodeTextMatch(t *testing.T) {
} }
want := &CodeSearchResult{ want := &CodeSearchResult{
Total: Int(1),
CodeResults: []CodeResult{wantedCodeResult},
Total: Int(1),
IncompleteResults: Bool(false),
CodeResults: []CodeResult{wantedCodeResult},
} }
if !reflect.DeepEqual(result, want) { if !reflect.DeepEqual(result, want) {
t.Errorf("Search.Code returned %+v, want %+v", result, want) t.Errorf("Search.Code returned %+v, want %+v", result, want)


Loading…
Cancel
Save