Go-github: How to add query in `func (s *SearchService) Issues`?

Created on 1 Dec 2017  路  2Comments  路  Source: google/go-github

Hi, All,

I met an issue when I was using this package.

Here is my scene: I need to search merged pr in the last week, I can make it to call url like:
https://api.github.com/search/issues?q=is:merged+type:pr+repo:moby/moby+merged:%3E=2017-11-23

I think in url query is is:merged+type:pr+repo:moby/moby+merged:%3E=2017-11-23. Then how to function

func (s *SearchService) Issues(ctx context.Context, query string, opt *SearchOptions) (*IssuesSearchResult, *Response, error) {

How to specify query in this case?

I have tested that when query is is:merged, this function works.
However when query is is:merged+type:pr+repo:moby/moby+merged:%3E=2017-11-23, this function will return no items in Issues which is defined below.

type IssuesSearchResult struct {
    Total             *int    `json:"total_count,omitempty"`
    IncompleteResults *bool   `json:"incomplete_results,omitempty"`
    Issues            []Issue `json:"items,omitempty"`
}

Then How to specify query in my case?

Thanks in advance.

Allen Sun

question

Most helpful comment

See godoc for https://godoc.org/github.com/google/go-github/github#SearchService, it says:

Each method takes a query string defining the search keywords and any search qualifiers. For example, when searching issues, the query "gopher is:issue language:go" will search for issues containing the word "gopher" in Go repositories. The method call

opts :=  &github.SearchOptions{Sort: "created", Order: "asc"}
cl.Search.Issues(ctx, "gopher is:issue language:go", opts)

will search for such issues, sorting by creation date in ascending order (i.e., oldest first).

I think the issue is that you're URL-escaping the search query. No need to do that, you should just provide the original unescaped query:

is:merged type:pr repo:moby/moby merged:>=2017-11-23

All 2 comments

See godoc for https://godoc.org/github.com/google/go-github/github#SearchService, it says:

Each method takes a query string defining the search keywords and any search qualifiers. For example, when searching issues, the query "gopher is:issue language:go" will search for issues containing the word "gopher" in Go repositories. The method call

opts :=  &github.SearchOptions{Sort: "created", Order: "asc"}
cl.Search.Issues(ctx, "gopher is:issue language:go", opts)

will search for such issues, sorting by creation date in ascending order (i.e., oldest first).

I think the issue is that you're URL-escaping the search query. No need to do that, you should just provide the original unescaped query:

is:merged type:pr repo:moby/moby merged:>=2017-11-23

Thanks a lot for explaination. I think I should be more careful with the comments there.

Was this page helpful?
0 / 5 - 0 ratings