andygrunwald / go-jira

Go client library for Atlassian Jira
https://pkg.go.dev/github.com/andygrunwald/go-jira?tab=doc
MIT License
1.48k stars 471 forks source link

SearchOptions {MaxResults: 0} doesn't work #299

Open timwata opened 4 years ago

timwata commented 4 years ago

Describe the bug

SearchOptions{ MaxResults:0 } doesn't work. The API actually allows it and it's useful to get just the metadata.

Expected behavior

No Issue returned if queried with SearchOptions{ MaxResults:0 }

// a piece of sample code
opts := jira.SearchOptions{ MaxResults: 0 }
issues, resp, _ := jiraCli.Issue.Search(`project=foo`, &opts)
fmt.Printf("NumIssues: %d, MaxResults: %d, Total: %d\n", len(issues), resp.MaxResults, resp.Total) 

// expected output
NumIssues: 0, MaxResults: 0, Total: 12345

// actual output
NumIssues: 50, MaxResults: 50, Total: 12345

Possible Solution

Remove omitempty from MaxResults

https://github.com/andygrunwald/go-jira/blob/f50cb07b297d79138b13e5ab49ea33965d32f5c1/issue.go#L500-L510

and tweak if conditions.

https://github.com/andygrunwald/go-jira/blob/f50cb07b297d79138b13e5ab49ea33965d32f5c1/issue.go#L1049-L1051

https://github.com/andygrunwald/go-jira/blob/f50cb07b297d79138b13e5ab49ea33965d32f5c1/issue.go#L1094-L1096

Your Environment

ghostsquad commented 4 years ago

another example of why using structs for options doesn't work. related to #294 and #200

I think it's valid to remove "omitEmpty". It seems that is it's set to 0, it gets reset to 50 anyways.

ghostsquad commented 4 years ago

Though just removing omitEmpty won't fix this problem. Currently, it doesn't seem like we have a way to set a default other than the "zero value" for the integer (0).

ghostsquad commented 4 years ago

@andygrunwald prior to version 2.0, I think we can just start implementing "Functional Options" variants of all methods, and mark the old methods as deprecated.

andygrunwald commented 4 years ago

@ghostsquad Could be an idea. Or we just start with v2 and see if we can skip adjusting v1.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity in the last 60 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

andygrunwald commented 2 years ago

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in https://github.com/andygrunwald/go-jira/issues/489

The development will take some time; however, I hope you can benefit from the changes. If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly. This means that during the development phase, we aim to tackle it. Maybe in a different way like it is currently handled. Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library. If there is anything else you would like to tell us, let us know!