Skip to content

Commit

Permalink
Use a better solution for bools, and update all usage of them
Browse files Browse the repository at this point in the history
Signed-off-by: rtweed <[email protected]>
  • Loading branch information
RichardoC committed Feb 26, 2024
1 parent 520b63a commit 49194ca
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cloud/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Filter struct {

// GetMyFiltersQueryOptions specifies the optional parameters for the Get My Filters method
type GetMyFiltersQueryOptions struct {
IncludeFavourites bool `url:"includeFavourites,omitempty"`
IncludeFavourites *bool `url:"includeFavourites,omitempty"`
Expand string `url:"expand,omitempty"`
}

Expand Down
14 changes: 7 additions & 7 deletions cloud/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type IssueService service

// UpdateQueryOptions specifies the optional parameters to the Edit issue
type UpdateQueryOptions struct {
NotifyUsers bool `url:"notifyUsers"` // can't be omitted as this means it's omitted when false which isn't desired as this defaults to true
OverrideScreenSecurity bool `url:"overrideScreenSecurity,omitempty"`
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
NotifyUsers *bool `url:"notifyUsers,omitempty"`
OverrideScreenSecurity *bool `url:"overrideScreenSecurity,omitempty"`
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
}

// Issue represents a Jira issue.
Expand Down Expand Up @@ -545,8 +545,8 @@ type GetQueryOptions struct {
// Properties is the list of properties to return for the issue. By default no properties are returned.
Properties string `url:"properties,omitempty"`
// FieldsByKeys if true then fields in issues will be referenced by keys instead of ids
FieldsByKeys bool `url:"fieldsByKeys,omitempty"`
UpdateHistory bool `url:"updateHistory,omitempty"`
FieldsByKeys *bool `url:"fieldsByKeys,omitempty"`
UpdateHistory *bool `url:"updateHistory,omitempty"`
ProjectKeys string `url:"projectKeys,omitempty"`
}

Expand All @@ -559,12 +559,12 @@ type GetWorklogsQueryOptions struct {
}

type AddWorklogQueryOptions struct {
NotifyUsers bool `url:"notifyUsers"` // can't be omitted as this means it's omitted when false which isn't desired as this defaults to true
NotifyUsers *bool `url:"notifyUsers",omitempty`
AdjustEstimate string `url:"adjustEstimate,omitempty"`
NewEstimate string `url:"newEstimate,omitempty"`
ReduceBy string `url:"reduceBy,omitempty"`
Expand string `url:"expand,omitempty"`
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
}

// CustomFields represents custom fields of Jira
Expand Down
3 changes: 2 additions & 1 deletion cloud/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func TestIssueService_UpdateIssueWithOptions(t *testing.T) {
i := make(map[string]interface{})
fields := make(map[string]interface{})
i["fields"] = fields
resp, err := testClient.Issue.client.Issue.UpdateIssueWithOptions(context.Background(), jID, i, &UpdateQueryOptions{NotifyUsers: false})

resp, err := testClient.Issue.client.Issue.UpdateIssueWithOptions(context.Background(), jID, i, &UpdateQueryOptions{NotifyUsers: Bool(true)})
if resp == nil {
t.Error("Expected resp. resp is nil")
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func testRequestParams(t *testing.T, r *http.Request, want map[string]string) {
}

func Test_addOptions(t *testing.T) {
v, err := addOptions("rest/api/2/issue/123", &UpdateQueryOptions{NotifyUsers: false})
v, err := addOptions("rest/api/2/issue/123", &UpdateQueryOptions{NotifyUsers: Bool(false)})
if err != nil {
t.Errorf("Expected no error. Got: %+v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion onpremise/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Filter struct {

// GetMyFiltersQueryOptions specifies the optional parameters for the Get My Filters method
type GetMyFiltersQueryOptions struct {
IncludeFavourites bool `url:"includeFavourites,omitempty"`
IncludeFavourites *bool `url:"includeFavourites,omitempty"`
Expand string `url:"expand,omitempty"`
}

Expand Down
16 changes: 8 additions & 8 deletions onpremise/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type IssueService service

// UpdateQueryOptions specifies the optional parameters to the Edit issue
type UpdateQueryOptions struct {
NotifyUsers bool `url:"notifyUsers"` // can't be omitted as this means it's omitted when false which isn't desired as this defaults to true
OverrideScreenSecurity bool `url:"overrideScreenSecurity,omitempty"`
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
NotifyUsers *bool `url:"notifyUsers,omitempty"`
OverrideScreenSecurity *bool `url:"overrideScreenSecurity,omitempty"`
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
}

// Issue represents a Jira issue.
Expand Down Expand Up @@ -544,8 +544,8 @@ type GetQueryOptions struct {
// Properties is the list of properties to return for the issue. By default no properties are returned.
Properties string `url:"properties,omitempty"`
// FieldsByKeys if true then fields in issues will be referenced by keys instead of ids
FieldsByKeys bool `url:"fieldsByKeys,omitempty"`
UpdateHistory bool `url:"updateHistory,omitempty"`
FieldsByKeys *bool `url:"fieldsByKeys,omitempty"`
UpdateHistory *bool `url:"updateHistory,omitempty"`
ProjectKeys string `url:"projectKeys,omitempty"`
}

Expand All @@ -558,12 +558,12 @@ type GetWorklogsQueryOptions struct {
}

type AddWorklogQueryOptions struct {
NotifyUsers bool `url:"notifyUsers,omitempty"`
NotifyUsers *bool `url:"notifyUsers,omitempty"`
AdjustEstimate string `url:"adjustEstimate,omitempty"`
NewEstimate string `url:"newEstimate,omitempty"`
ReduceBy string `url:"reduceBy,omitempty"`
Expand string `url:"expand,omitempty"`
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
}

// CustomFields represents custom fields of Jira
Expand Down Expand Up @@ -839,7 +839,7 @@ func (s *IssueService) Create(ctx context.Context, issue *Issue) (*Issue, *Respo
// This double check effort is done for v2 - Remove this two lines if this is completed.
func (s *IssueService) Update(ctx context.Context, issue *Issue, opts *UpdateQueryOptions) (*Issue, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%v", issue.Key)
url, err := addOptions(apiEndpoint, *opts)
url, err := addOptions(apiEndpoint, opts)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions onpremise/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestIssueService_Update_with_false_opts(t *testing.T) {
Description: "example bug report",
},
}
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: false})
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: Bool(false)})
if issue == nil {
t.Error("Expected issue. Issue is nil")
}
Expand All @@ -199,7 +199,7 @@ func TestIssueService_Update_with_multiple_opts(t *testing.T) {
Description: "example bug report",
},
}
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: false, OverrideScreenSecurity: true})
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: Bool(false), OverrideScreenSecurity: Bool(true)})
if issue == nil {
t.Error("Expected issue. Issue is nil")
}
Expand Down

0 comments on commit 49194ca

Please sign in to comment.