go-github icon indicating copy to clipboard operation
go-github copied to clipboard

TextMatch doesn't work when use Search.Repositories

Open DarkMatterV opened this issue 2 years ago • 2 comments

when i use Search.Repositories, set TextMatch = true, but it doesn't work

this is my code:

repos, resp, err = client.Search.Repositories(ctx, query, &github.SearchOptions{
		Sort:      sort,
		Order:     order,
		TextMatch: true,
		ListOptions: github.ListOptions{
			Page:    page,
			PerPage: perPage,
		},
	})

I found it in go-github, in search function, use switch to add Accept to the req.Header, it lead to i can't get text_matches in reponse when i use commits topics repositories issues

I don't know why it's designed in this way, and i didn't found other accept values other than application/vnd.github.v3.text-match+json on the github restful api, such as application/vnd.github.mercy-preview+json . In fact, i don't know what application/vnd.github.mercy-preview+json will do even if i read the documentation

image image

DarkMatterV avatar Jun 16 '22 10:06 DarkMatterV

Hmmm... that does indeed look unusual. In the corresponding unit test, it shows TextMatch being used with client.Search.Code: https://github.com/google/go-github/blob/master/github/search_test.go#L408-L413

Although the official documentation shows an example using the issues endpoint:

curl -H 'Accept: application/vnd.github.v3.text-match+json' \
'https://api.github.com/search/issues?q=windows+label:bug+language:python+state:open&sort=created&order=asc'

which makes me think that this custom header should be added no matter what the value of searchType is.

Do you want to make a PR to change this behavior and test it out, @DarkMatterV ?

gmlewis avatar Jun 16 '22 11:06 gmlewis

Okay,I want to do it

DarkMatterV avatar Jun 17 '22 04:06 DarkMatterV