New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add query in `func (s *SearchService) Issues`? #801

Closed
allencloud opened this Issue Dec 1, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@allencloud
Contributor

allencloud commented Dec 1, 2017

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

@dmitshur dmitshur added the question label Dec 1, 2017

@dmitshur

This comment has been minimized.

Show comment
Hide comment
@dmitshur

dmitshur Dec 1, 2017

Member

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
Member

dmitshur commented Dec 1, 2017

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
@allencloud

This comment has been minimized.

Show comment
Hide comment
@allencloud

allencloud Dec 1, 2017

Contributor

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

Contributor

allencloud commented Dec 1, 2017

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

@allencloud allencloud closed this Dec 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment