Skip to content

Commit 3959138

Browse files
authored
fix: Remove custom Accept headers from search endpoints (#3820)
1 parent 1b4b8cc commit 3959138

File tree

3 files changed

+3
-33
lines changed

3 files changed

+3
-33
lines changed

github/github.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ const (
9191
// https://developer.github.com/changes/2016-09-14-projects-api/
9292
mediaTypeProjectsPreview = "application/vnd.github.inertia-preview+json"
9393

94-
// https://developer.github.com/changes/2017-01-05-commit-search-api/
95-
mediaTypeCommitSearchPreview = "application/vnd.github.cloak-preview+json"
96-
9794
// https://developer.github.com/changes/2017-02-28-user-blocking-apis-and-webhook/
9895
mediaTypeBlockUsersPreview = "application/vnd.github.giant-sentry-fist-preview+json"
9996

github/search.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"context"
1010
"fmt"
1111
"strconv"
12-
"strings"
1312

1413
qs "github.com/google/go-querystring/query"
1514
)
@@ -317,32 +316,12 @@ func (s *SearchService) search(ctx context.Context, searchType string, parameter
317316
if err != nil {
318317
return nil, err
319318
}
320-
var acceptHeaders []string
321-
switch searchType {
322-
case "commits":
323-
// Accept header for search commits preview endpoint
324-
// TODO: remove custom Accept header when this API fully launches.
325-
acceptHeaders = append(acceptHeaders, mediaTypeCommitSearchPreview)
326-
case "topics":
327-
// Accept header for search repositories based on topics preview endpoint
328-
// TODO: remove custom Accept header when this API fully launches.
329-
acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview)
330-
case "repositories":
331-
// Accept header for search repositories based on topics preview endpoint
332-
// TODO: remove custom Accept header when this API fully launches.
333-
acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview)
334-
case "issues":
335-
// Accept header for search issues based on reactions preview endpoint
336-
// TODO: remove custom Accept header when this API fully launches.
337-
acceptHeaders = append(acceptHeaders, mediaTypeReactionsPreview)
338-
}
339-
// https://docs.github.com/rest/search#search-repositories
319+
// https://docs.github.com/en/rest/search/search#text-match-metadata
340320
// Accept header defaults to "application/vnd.github.v3+json"
341321
// We change it here to fetch back text-match metadata
342322
if opts != nil && opts.TextMatch {
343-
acceptHeaders = append(acceptHeaders, "application/vnd.github.v3.text-match+json")
323+
req.Header.Set("Accept", "application/vnd.github.v3.text-match+json")
344324
}
345-
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
346325

347326
return s.client.Do(ctx, req, result)
348327
}

github/search_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package github
88
import (
99
"fmt"
1010
"net/http"
11-
"strings"
1211
"testing"
1312

1413
"github.com/google/go-cmp/cmp"
@@ -78,12 +77,7 @@ func TestSearchService_RepositoriesTextMatch(t *testing.T) {
7877
]
7978
}
8079
`
81-
list := strings.Split(r.Header.Get("Accept"), ",")
82-
aMap := make(map[string]struct{})
83-
for _, s := range list {
84-
aMap[strings.TrimSpace(s)] = struct{}{}
85-
}
86-
if _, ok := aMap["application/vnd.github.v3.text-match+json"]; ok {
80+
if r.Header.Get("Accept") == "application/vnd.github.v3.text-match+json" {
8781
textMatchResponse = `
8882
{
8983
"total_count": 1,

0 commit comments

Comments
 (0)