Skip to content

Commit 4f3747e

Browse files
author
Ismar Iljazovic
committed
feat: add group visibility for comments (ankitpokhrel#902)
Cherry-picked from upstream PR ankitpokhrel#902 by xbezdick. Adds --group flag to restrict comment visibility to a specific group.
1 parent f96029e commit 4f3747e

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
@@ -56,6 +56,10 @@ func NewCmdCommentAdd() *cobra.Command {
5656

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

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

107-
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal)
111+
return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal, ac.params.visibilityGroup)
108112
}()
109113
cmdutil.ExitIfError(err)
110114

@@ -120,12 +124,13 @@ func add(cmd *cobra.Command, args []string) {
120124
}
121125

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

131136
const (
@@ -150,19 +155,23 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
150155
template, err := flags.GetString("template")
151156
cmdutil.ExitIfError(err)
152157

158+
visibilityGroup, err := flags.GetString("visibility-group")
159+
cmdutil.ExitIfError(err)
160+
153161
noInput, err := flags.GetBool("no-input")
154162
cmdutil.ExitIfError(err)
155163

156164
internal, err := flags.GetBool("internal")
157165
cmdutil.ExitIfError(err)
158166

159167
return &addParams{
160-
issueKey: issueKey,
161-
body: body,
162-
template: template,
163-
noInput: noInput,
164-
internal: internal,
165-
debug: debug,
168+
issueKey: issueKey,
169+
body: body,
170+
template: template,
171+
visibilityGroup: visibilityGroup,
172+
noInput: noInput,
173+
internal: internal,
174+
debug: debug,
166175
}
167176
}
168177

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)