Skip to content
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

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

Open
timwata opened this issue May 28, 2020 · 6 comments
Open

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

timwata opened this issue May 28, 2020 · 6 comments
Labels
needs triage Ticket that needs triage (a proper look for classification)

Comments

@timwata
Copy link

timwata commented May 28, 2020

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

go-jira/issue.go

Lines 500 to 510 in f50cb07

type SearchOptions struct {
// StartAt: The starting index of the returned projects. Base index: 0.
StartAt int `url:"startAt,omitempty"`
// MaxResults: The maximum number of projects to return per page. Default: 50.
MaxResults int `url:"maxResults,omitempty"`
// Expand: Expand specific sections in the returned issues
Expand string `url:"expand,omitempty"`
Fields []string
// ValidateQuery: The validateQuery param offers control over whether to validate and how strictly to treat the validation. Default: strict.
ValidateQuery string `url:"validateQuery,omitempty"`
}

and tweak if conditions.

go-jira/issue.go

Lines 1049 to 1051 in f50cb07

if options.MaxResults != 0 {
uv.Add("maxResults", strconv.Itoa(options.MaxResults))
}

go-jira/issue.go

Lines 1094 to 1096 in f50cb07

if options.MaxResults == 0 {
options.MaxResults = 50
}

Your Environment

  • go-jira version (git tag or sha): v1.12.0
  • Go version (go version): 1.14.2
  • Jira type (cloud or on-premise): cloud
  • Operating System and version: CentOS 8.1.1911
@ghostsquad
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Owner

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

@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Jul 30, 2020
@andygrunwald andygrunwald added the needs triage Ticket that needs triage (a proper look for classification) label Aug 20, 2022
@andygrunwald
Copy link
Owner

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 #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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Ticket that needs triage (a proper look for classification)
Projects
None yet
Development

No branches or pull requests

3 participants