Skip to content

Commit ffc6dbc

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 ffc6dbc

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ 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", "V", "", "The name of the group that visibility of this comment is restricted to.")
5859
cmd.Flags().Bool("no-input", false, "Disable prompt for non-required fields")
5960
cmd.Flags().Bool("internal", false, "Make comment internal")
6061

@@ -103,7 +104,7 @@ func add(cmd *cobra.Command, args []string) {
103104
s := cmdutil.Info("Adding comment")
104105
defer s.Stop()
105106

106-
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal)
107+
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal, ac.params.visibilityGroup)
107108
}()
108109
cmdutil.ExitIfError(err)
109110

@@ -119,12 +120,13 @@ func add(cmd *cobra.Command, args []string) {
119120
}
120121

121122
type addParams struct {
122-
issueKey string
123-
body string
124-
template string
125-
noInput bool
126-
internal bool
127-
debug bool
123+
issueKey string
124+
body string
125+
template string
126+
visibilityGroup string
127+
noInput bool
128+
internal bool
129+
debug bool
128130
}
129131

130132
func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
@@ -144,19 +146,23 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
144146
template, err := flags.GetString("template")
145147
cmdutil.ExitIfError(err)
146148

149+
visibilityGroup, err := flags.GetString("visibility-group")
150+
cmdutil.ExitIfError(err)
151+
147152
noInput, err := flags.GetBool("no-input")
148153
cmdutil.ExitIfError(err)
149154

150155
internal, err := flags.GetBool("internal")
151156
cmdutil.ExitIfError(err)
152157

153158
return &addParams{
154-
issueKey: issueKey,
155-
body: body,
156-
template: template,
157-
noInput: noInput,
158-
internal: internal,
159-
debug: debug,
159+
issueKey: issueKey,
160+
body: body,
161+
template: template,
162+
visibilityGroup: visibilityGroup,
163+
noInput: noInput,
164+
internal: internal,
165+
debug: debug,
160166
}
161167
}
162168

pkg/jira/issue.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,32 @@ 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+
322+
issueReq := issueCommentRequest{
323+
Body: md.ToJiraMD(comment),
324+
Properties: []issueCommentProperty{{Key: "sd.public.comment", Value: issueCommentPropertyValue{Internal: internal}}},
325+
}
326+
327+
if visibilityGroup != "" {
328+
issueReq.Visibility = issueCommentVisibility{Type: "group", Value: visibilityGroup}
329+
}
330+
331+
body, err := json.Marshal(issueReq)
332+
315333
if err != nil {
316334
return err
317335
}

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)