Skip to content

Commit b184646

Browse files
committed
Add ability to comment with group visibility set
This allows to make non public comments that are not only meant for internal eyes only but also only for a specific group.
1 parent 79067e2 commit b184646

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

internal/cmd/issue/comment/add/add.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func NewCmdCommentAdd() *cobra.Command {
5555

5656
cmd.Flags().Bool("web", false, "Open issue in web browser after adding comment")
5757
cmd.Flags().StringP("template", "T", "", "Path to a file to read comment body from")
58+
cmd.Flags().StringP("visibility-group",
59+
"V",
60+
"",
61+
"The name of the group that visibility of this comment is restricted to.")
5862
cmd.Flags().Bool("no-input", false, "Disable prompt for non-required fields")
5963
cmd.Flags().Bool("internal", false, "Make comment internal")
6064

@@ -103,7 +107,7 @@ func add(cmd *cobra.Command, args []string) {
103107
s := cmdutil.Info("Adding comment")
104108
defer s.Stop()
105109

106-
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal)
110+
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal, ac.params.visibilityGroup)
107111
}()
108112
cmdutil.ExitIfError(err)
109113

@@ -119,12 +123,13 @@ func add(cmd *cobra.Command, args []string) {
119123
}
120124

121125
type addParams struct {
122-
issueKey string
123-
body string
124-
template string
125-
noInput bool
126-
internal bool
127-
debug bool
126+
issueKey string
127+
body string
128+
template string
129+
visibilityGroup string
130+
noInput bool
131+
internal bool
132+
debug bool
128133
}
129134

130135
func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
@@ -144,19 +149,23 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
144149
template, err := flags.GetString("template")
145150
cmdutil.ExitIfError(err)
146151

152+
visibilityGroup, err := flags.GetString("visibility-group")
153+
cmdutil.ExitIfError(err)
154+
147155
noInput, err := flags.GetBool("no-input")
148156
cmdutil.ExitIfError(err)
149157

150158
internal, err := flags.GetBool("internal")
151159
cmdutil.ExitIfError(err)
152160

153161
return &addParams{
154-
issueKey: issueKey,
155-
body: body,
156-
template: template,
157-
noInput: noInput,
158-
internal: internal,
159-
debug: debug,
162+
issueKey: issueKey,
163+
body: body,
164+
template: template,
165+
visibilityGroup: visibilityGroup,
166+
noInput: noInput,
167+
internal: internal,
168+
debug: debug,
160169
}
161170
}
162171

pkg/jira/issue.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,30 @@ type issueCommentProperty struct {
304304
Key string `json:"key"`
305305
Value issueCommentPropertyValue `json:"value"`
306306
}
307+
308+
type issueCommentVisibility struct {
309+
Type string `json:"type,omitempty"`
310+
Value string `json:"value,omitempty"`
311+
}
312+
307313
type issueCommentRequest struct {
308314
Body string `json:"body"`
309315
Properties []issueCommentProperty `json:"properties"`
316+
Visibility issueCommentVisibility `json:"visibility,omitempty"`
310317
}
311318

312319
// AddIssueComment adds comment to an issue using POST /issue/{key}/comment endpoint.
313-
func (c *Client) AddIssueComment(key, comment string, internal bool) error {
314-
body, err := json.Marshal(&issueCommentRequest{Body: md.ToJiraMD(comment), Properties: []issueCommentProperty{{Key: "sd.public.comment", Value: issueCommentPropertyValue{Internal: internal}}}})
320+
func (c *Client) AddIssueComment(key, comment string, internal bool, visibilityGroup string) error {
321+
issueReq := issueCommentRequest{
322+
Body: md.ToJiraMD(comment),
323+
Properties: []issueCommentProperty{{Key: "sd.public.comment", Value: issueCommentPropertyValue{Internal: internal}}},
324+
}
325+
326+
if visibilityGroup != "" {
327+
issueReq.Visibility = issueCommentVisibility{Type: "group", Value: visibilityGroup}
328+
}
329+
330+
body, err := json.Marshal(issueReq)
315331
if err != nil {
316332
return err
317333
}

pkg/jira/issue_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func TestAddIssueComment(t *testing.T) {
531531
actualBody := new(strings.Builder)
532532
_, _ = io.Copy(actualBody, r.Body)
533533

534-
expectedBody := `{"body":"comment","properties":[{"key":"sd.public.comment","value":{"internal":false}}]}`
534+
expectedBody := `{"body":"comment","properties":[{"key":"sd.public.comment","value":{"internal":false}}],"visibility":{}}`
535535

536536
assert.Equal(t, expectedBody, actualBody.String())
537537

@@ -545,12 +545,12 @@ func TestAddIssueComment(t *testing.T) {
545545

546546
client := NewClient(Config{Server: server.URL}, WithTimeout(3*time.Second))
547547

548-
err := client.AddIssueComment("TEST-1", "comment", false)
548+
err := client.AddIssueComment("TEST-1", "comment", false, "")
549549
assert.NoError(t, err)
550550

551551
unexpectedStatusCode = true
552552

553-
err = client.AddIssueComment("TEST-1", "comment", false)
553+
err = client.AddIssueComment("TEST-1", "comment", false, "")
554554
assert.Error(t, &ErrUnexpectedResponse{}, err)
555555
}
556556

0 commit comments

Comments
 (0)