Skip to content

Commit 49194ca

Browse files
committed
Use a better solution for bools, and update all usage of them
Signed-off-by: rtweed <RichardoC@users.noreply.github.com>
1 parent 520b63a commit 49194ca

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed

cloud/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Filter struct {
3737

3838
// GetMyFiltersQueryOptions specifies the optional parameters for the Get My Filters method
3939
type GetMyFiltersQueryOptions struct {
40-
IncludeFavourites bool `url:"includeFavourites,omitempty"`
40+
IncludeFavourites *bool `url:"includeFavourites,omitempty"`
4141
Expand string `url:"expand,omitempty"`
4242
}
4343

cloud/issue.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type IssueService service
3131

3232
// UpdateQueryOptions specifies the optional parameters to the Edit issue
3333
type UpdateQueryOptions struct {
34-
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
35-
OverrideScreenSecurity bool `url:"overrideScreenSecurity,omitempty"`
36-
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
34+
NotifyUsers *bool `url:"notifyUsers,omitempty"`
35+
OverrideScreenSecurity *bool `url:"overrideScreenSecurity,omitempty"`
36+
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
3737
}
3838

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

@@ -559,12 +559,12 @@ type GetWorklogsQueryOptions struct {
559559
}
560560

561561
type AddWorklogQueryOptions struct {
562-
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
562+
NotifyUsers *bool `url:"notifyUsers",omitempty`
563563
AdjustEstimate string `url:"adjustEstimate,omitempty"`
564564
NewEstimate string `url:"newEstimate,omitempty"`
565565
ReduceBy string `url:"reduceBy,omitempty"`
566566
Expand string `url:"expand,omitempty"`
567-
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
567+
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
568568
}
569569

570570
// CustomFields represents custom fields of Jira

cloud/issue_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ func TestIssueService_UpdateIssueWithOptions(t *testing.T) {
192192
i := make(map[string]interface{})
193193
fields := make(map[string]interface{})
194194
i["fields"] = fields
195-
resp, err := testClient.Issue.client.Issue.UpdateIssueWithOptions(context.Background(), jID, i, &UpdateQueryOptions{NotifyUsers: false})
195+
196+
resp, err := testClient.Issue.client.Issue.UpdateIssueWithOptions(context.Background(), jID, i, &UpdateQueryOptions{NotifyUsers: Bool(true)})
196197
if resp == nil {
197198
t.Error("Expected resp. resp is nil")
198199
}

cloud/jira_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func testRequestParams(t *testing.T, r *http.Request, want map[string]string) {
7474
}
7575

7676
func Test_addOptions(t *testing.T) {
77-
v, err := addOptions("rest/api/2/issue/123", &UpdateQueryOptions{NotifyUsers: false})
77+
v, err := addOptions("rest/api/2/issue/123", &UpdateQueryOptions{NotifyUsers: Bool(false)})
7878
if err != nil {
7979
t.Errorf("Expected no error. Got: %+v", err)
8080
}

onpremise/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Filter struct {
3737

3838
// GetMyFiltersQueryOptions specifies the optional parameters for the Get My Filters method
3939
type GetMyFiltersQueryOptions struct {
40-
IncludeFavourites bool `url:"includeFavourites,omitempty"`
40+
IncludeFavourites *bool `url:"includeFavourites,omitempty"`
4141
Expand string `url:"expand,omitempty"`
4242
}
4343

onpremise/issue.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type IssueService service
3131

3232
// UpdateQueryOptions specifies the optional parameters to the Edit issue
3333
type UpdateQueryOptions struct {
34-
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
35-
OverrideScreenSecurity bool `url:"overrideScreenSecurity,omitempty"`
36-
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
34+
NotifyUsers *bool `url:"notifyUsers,omitempty"`
35+
OverrideScreenSecurity *bool `url:"overrideScreenSecurity,omitempty"`
36+
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
3737
}
3838

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

@@ -558,12 +558,12 @@ type GetWorklogsQueryOptions struct {
558558
}
559559

560560
type AddWorklogQueryOptions struct {
561-
NotifyUsers bool `url:"notifyUsers,omitempty"`
561+
NotifyUsers *bool `url:"notifyUsers,omitempty"`
562562
AdjustEstimate string `url:"adjustEstimate,omitempty"`
563563
NewEstimate string `url:"newEstimate,omitempty"`
564564
ReduceBy string `url:"reduceBy,omitempty"`
565565
Expand string `url:"expand,omitempty"`
566-
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
566+
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
567567
}
568568

569569
// CustomFields represents custom fields of Jira
@@ -839,7 +839,7 @@ func (s *IssueService) Create(ctx context.Context, issue *Issue) (*Issue, *Respo
839839
// This double check effort is done for v2 - Remove this two lines if this is completed.
840840
func (s *IssueService) Update(ctx context.Context, issue *Issue, opts *UpdateQueryOptions) (*Issue, *Response, error) {
841841
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%v", issue.Key)
842-
url, err := addOptions(apiEndpoint, *opts)
842+
url, err := addOptions(apiEndpoint, opts)
843843
if err != nil {
844844
return nil, nil, err
845845
}

onpremise/issue_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestIssueService_Update_with_false_opts(t *testing.T) {
172172
Description: "example bug report",
173173
},
174174
}
175-
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: false})
175+
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: Bool(false)})
176176
if issue == nil {
177177
t.Error("Expected issue. Issue is nil")
178178
}
@@ -199,7 +199,7 @@ func TestIssueService_Update_with_multiple_opts(t *testing.T) {
199199
Description: "example bug report",
200200
},
201201
}
202-
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: false, OverrideScreenSecurity: true})
202+
issue, _, err := testClient.Issue.Update(context.Background(), i, &UpdateQueryOptions{NotifyUsers: Bool(false), OverrideScreenSecurity: Bool(true)})
203203
if issue == nil {
204204
t.Error("Expected issue. Issue is nil")
205205
}

0 commit comments

Comments
 (0)