Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ const (
// https://developer.github.com/changes/2016-09-14-projects-api/
mediaTypeProjectsPreview = "application/vnd.github.inertia-preview+json"

// https://developer.github.com/changes/2017-01-05-commit-search-api/
mediaTypeCommitSearchPreview = "application/vnd.github.cloak-preview+json"

// https://developer.github.com/changes/2017-02-28-user-blocking-apis-and-webhook/
mediaTypeBlockUsersPreview = "application/vnd.github.giant-sentry-fist-preview+json"

Expand Down
25 changes: 2 additions & 23 deletions github/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"fmt"
"strconv"
"strings"

qs "github.com/google/go-querystring/query"
)
Expand Down Expand Up @@ -317,32 +316,12 @@ func (s *SearchService) search(ctx context.Context, searchType string, parameter
if err != nil {
return nil, err
}
var acceptHeaders []string
switch searchType {
case "commits":
// Accept header for search commits preview endpoint
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders = append(acceptHeaders, mediaTypeCommitSearchPreview)
case "topics":
// Accept header for search repositories based on topics preview endpoint
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview)
case "repositories":
// Accept header for search repositories based on topics preview endpoint
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview)
case "issues":
// Accept header for search issues based on reactions preview endpoint
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders = append(acceptHeaders, mediaTypeReactionsPreview)
}
// https://docs.github.com/rest/search#search-repositories
// https://docs.github.com/en/rest/search/search#text-match-metadata
// Accept header defaults to "application/vnd.github.v3+json"
// We change it here to fetch back text-match metadata
if opts != nil && opts.TextMatch {
acceptHeaders = append(acceptHeaders, "application/vnd.github.v3.text-match+json")
req.Header.Set("Accept", "application/vnd.github.v3.text-match+json")
}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))

return s.client.Do(ctx, req, result)
}
8 changes: 1 addition & 7 deletions github/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package github
import (
"fmt"
"net/http"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -78,12 +77,7 @@ func TestSearchService_RepositoriesTextMatch(t *testing.T) {
]
}
`
list := strings.Split(r.Header.Get("Accept"), ",")
aMap := make(map[string]struct{})
for _, s := range list {
aMap[strings.TrimSpace(s)] = struct{}{}
}
if _, ok := aMap["application/vnd.github.v3.text-match+json"]; ok {
if r.Header.Get("Accept") == "application/vnd.github.v3.text-match+json" {
textMatchResponse = `
{
"total_count": 1,
Expand Down
Loading