Skip to content

Commit 0651093

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 0651093

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

@@ -103,7 +105,7 @@ func add(cmd *cobra.Command, args []string) {
103105
s := cmdutil.Info("Adding comment")
104106
defer s.Stop()
105107

106-
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal)
108+
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal, ac.params.visibilityGroup)
107109
}()
108110
cmdutil.ExitIfError(err)
109111

@@ -119,12 +121,13 @@ func add(cmd *cobra.Command, args []string) {
119121
}
120122

121123
type addParams struct {
122-
issueKey string
123-
body string
124-
template string
125-
noInput bool
126-
internal bool
127-
debug bool
124+
issueKey string
125+
body string
126+
template string
127+
visibilityGroup string
128+
noInput bool
129+
internal bool
130+
debug bool
128131
}
129132

130133
func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
@@ -144,19 +147,23 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
144147
template, err := flags.GetString("template")
145148
cmdutil.ExitIfError(err)
146149

150+
visibilityGroup, err := flags.GetString("visibility-group")
151+
cmdutil.ExitIfError(err)
152+
147153
noInput, err := flags.GetBool("no-input")
148154
cmdutil.ExitIfError(err)
149155

150156
internal, err := flags.GetBool("internal")
151157
cmdutil.ExitIfError(err)
152158

153159
return &addParams{
154-
issueKey: issueKey,
155-
body: body,
156-
template: template,
157-
noInput: noInput,
158-
internal: internal,
159-
debug: debug,
160+
issueKey: issueKey,
161+
body: body,
162+
template: template,
163+
visibilityGroup: visibilityGroup,
164+
noInput: noInput,
165+
internal: internal,
166+
debug: debug,
160167
}
161168
}
162169

pkg/jira/issue.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,31 @@ 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)
331+
315332
if err != nil {
316333
return err
317334
}

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)