Skip to content

Commit 25d7416

Browse files
authored
feat: Allow skipping notification on edit (#855)
1 parent 8ae1875 commit 25d7416

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

internal/cmd/epic/add/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func add(cmd *cobra.Command, args []string) {
8181
// There is no way to send bulk update requests as of now, so we need to send these requests
8282
// in a loop. We will print failed requests with exit code 1 at the end if there are any.
8383
for _, iss := range params.issues {
84-
if err := client.Edit(iss, &jira.EditRequest{ParentIssueKey: params.epicKey}); err != nil {
84+
if err := client.Edit(iss, &jira.EditRequest{ParentIssueKey: params.epicKey, SkipNotify: true}); err != nil {
8585
msg := fmt.Sprintf("\n - %s: %s", iss, cmdutil.NormalizeJiraError(err.Error()))
8686
failed.WriteString(msg)
8787
} else {

internal/cmd/epic/remove/remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func remove(cmd *cobra.Command, args []string) {
7272
}
7373

7474
for _, iss := range params.issues {
75-
if err := client.Edit(iss, &jira.EditRequest{ParentIssueKey: jira.AssigneeNone}); err != nil {
75+
if err := client.Edit(iss, &jira.EditRequest{ParentIssueKey: jira.AssigneeNone, SkipNotify: true}); err != nil {
7676
msg := fmt.Sprintf("\n - %s: %s", iss, cmdutil.NormalizeJiraError(err.Error()))
7777
failed.WriteString(msg)
7878
} else {

internal/cmd/issue/edit/edit.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func edit(cmd *cobra.Command, args []string) {
157157
FixVersions: fixVersions,
158158
AffectsVersions: affectsVersions,
159159
CustomFields: params.customFields,
160+
SkipNotify: params.skipNotify,
160161
}
161162
if configuredCustomFields, err := cmdcommon.GetConfiguredCustomFields(); err == nil {
162163
cmdcommon.ValidateCustomFields(edr.CustomFields, configuredCustomFields)
@@ -311,6 +312,7 @@ type editParams struct {
311312
fixVersions []string
312313
affectsVersions []string
313314
customFields map[string]string
315+
skipNotify bool
314316
noInput bool
315317
debug bool
316318
}
@@ -346,6 +348,9 @@ func parseArgsAndFlags(flags query.FlagParser, args []string, project string) *e
346348
custom, err := flags.GetStringToString("custom")
347349
cmdutil.ExitIfError(err)
348350

351+
skipNotify, err := flags.GetBool("skip-notify")
352+
cmdutil.ExitIfError(err)
353+
349354
noInput, err := flags.GetBool("no-input")
350355
cmdutil.ExitIfError(err)
351356

@@ -364,6 +369,7 @@ func parseArgsAndFlags(flags query.FlagParser, args []string, project string) *e
364369
fixVersions: fixVersions,
365370
affectsVersions: affectsVersions,
366371
customFields: custom,
372+
skipNotify: skipNotify,
367373
noInput: noInput,
368374
debug: debug,
369375
}
@@ -445,6 +451,7 @@ func setFlags(cmd *cobra.Command) {
445451
cmd.Flags().StringArray("fix-version", []string{}, "Add/Append release info (fixVersions)")
446452
cmd.Flags().StringArray("affects-version", []string{}, "Add/Append release info (affectsVersions)")
447453
cmd.Flags().StringToString("custom", custom, "Edit custom fields")
454+
cmd.Flags().Bool("skip-notify", false, "Do not notify watchers about the issue update")
448455
cmd.Flags().Bool("web", false, "Open in web browser after successful update")
449456
cmd.Flags().Bool("no-input", false, "Disable prompt for non-required fields")
450457
}

pkg/jira/edit.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package jira
33
import (
44
"context"
55
"encoding/json"
6+
"maps"
67
"net/http"
8+
"slices"
79
"strconv"
810
"strings"
911
)
@@ -31,6 +33,7 @@ type EditRequest struct {
3133
// CustomFields holds all custom fields passed
3234
// while editing the issue.
3335
CustomFields map[string]string
36+
SkipNotify bool
3437

3538
configuredCustomFields []IssueTypeField
3639
}
@@ -49,7 +52,12 @@ func (c *Client) Edit(key string, req *EditRequest) error {
4952
return err
5053
}
5154

52-
res, err := c.PutV2(context.Background(), "/issue/"+key, body, Header{
55+
endpoint := "/issue/" + key
56+
if req.SkipNotify {
57+
endpoint += "?notifyUsers=false"
58+
}
59+
60+
res, err := c.PutV2(context.Background(), endpoint, body, Header{
5361
"Accept": "application/json",
5462
"Content-Type": "application/json",
5563
})
@@ -78,7 +86,7 @@ type editFields struct {
7886
Priority []struct {
7987
Set struct {
8088
Name string `json:"name,omitempty"`
81-
} `json:"set,omitempty"`
89+
} `json:"set"`
8290
} `json:"priority,omitempty"`
8391
Labels []struct {
8492
Add string `json:"add,omitempty"`
@@ -139,16 +147,13 @@ func (cfm *editFieldsMarshaler) MarshalJSON() ([]byte, error) {
139147
return m, err
140148
}
141149

142-
var temp interface{}
150+
var temp any
143151
if err := json.Unmarshal(m, &temp); err != nil {
144152
return nil, err
145153
}
146-
dm := temp.(map[string]interface{})
147-
148-
for key, val := range cfm.M.customFields {
149-
dm[key] = val
150-
}
154+
dm := temp.(map[string]any)
151155

156+
maps.Copy(dm, cfm.M.customFields)
152157
return json.Marshal(dm)
153158
}
154159

@@ -177,7 +182,7 @@ func getRequestDataForEdit(req *EditRequest) *editRequest {
177182
Priority: []struct {
178183
Set struct {
179184
Name string `json:"name,omitempty"`
180-
} `json:"set,omitempty"`
185+
} `json:"set"`
181186
}{{Set: struct {
182187
Name string `json:"name,omitempty"`
183188
}{Name: req.Priority}}},
@@ -412,19 +417,10 @@ func splitAddAndRemove(input []string) ([]string, []string) {
412417
}
413418
}
414419
for _, inp := range input {
415-
if !strings.HasPrefix(inp, separatorMinus) && !inArray(sub, inp) {
420+
if !strings.HasPrefix(inp, separatorMinus) && !slices.Contains(sub, inp) {
416421
add = append(add, inp)
417422
}
418423
}
419424

420425
return add, sub
421426
}
422-
423-
func inArray(array []string, item string) bool {
424-
for _, i := range array {
425-
if i == item {
426-
return true
427-
}
428-
}
429-
return false
430-
}

0 commit comments

Comments
 (0)