diff --git a/internal/cmd/issue/comment/add/add.go b/internal/cmd/issue/comment/add/add.go index 8dbdb7d8..b32d5894 100644 --- a/internal/cmd/issue/comment/add/add.go +++ b/internal/cmd/issue/comment/add/add.go @@ -55,6 +55,10 @@ func NewCmdCommentAdd() *cobra.Command { cmd.Flags().Bool("web", false, "Open issue in web browser after adding comment") cmd.Flags().StringP("template", "T", "", "Path to a file to read comment body from") + cmd.Flags().StringP("visibility-group", + "V", + "", + "The name of the group that visibility of this comment is restricted to.") cmd.Flags().Bool("no-input", false, "Disable prompt for non-required fields") cmd.Flags().Bool("internal", false, "Make comment internal") @@ -103,7 +107,7 @@ func add(cmd *cobra.Command, args []string) { s := cmdutil.Info("Adding comment") defer s.Stop() - return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal) + return client.AddIssueComment(ac.params.issueKey, ac.params.body, ac.params.internal, ac.params.visibilityGroup) }() cmdutil.ExitIfError(err) @@ -119,12 +123,13 @@ func add(cmd *cobra.Command, args []string) { } type addParams struct { - issueKey string - body string - template string - noInput bool - internal bool - debug bool + issueKey string + body string + template string + visibilityGroup string + noInput bool + internal bool + debug bool } func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams { @@ -144,6 +149,9 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams { template, err := flags.GetString("template") cmdutil.ExitIfError(err) + visibilityGroup, err := flags.GetString("visibility-group") + cmdutil.ExitIfError(err) + noInput, err := flags.GetBool("no-input") cmdutil.ExitIfError(err) @@ -151,12 +159,13 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams { cmdutil.ExitIfError(err) return &addParams{ - issueKey: issueKey, - body: body, - template: template, - noInput: noInput, - internal: internal, - debug: debug, + issueKey: issueKey, + body: body, + template: template, + visibilityGroup: visibilityGroup, + noInput: noInput, + internal: internal, + debug: debug, } } diff --git a/pkg/jira/issue.go b/pkg/jira/issue.go index ef24c75d..8b00aa5b 100644 --- a/pkg/jira/issue.go +++ b/pkg/jira/issue.go @@ -304,14 +304,30 @@ type issueCommentProperty struct { Key string `json:"key"` Value issueCommentPropertyValue `json:"value"` } + +type issueCommentVisibility struct { + Type string `json:"type,omitempty"` + Value string `json:"value,omitempty"` +} + type issueCommentRequest struct { Body string `json:"body"` Properties []issueCommentProperty `json:"properties"` + Visibility issueCommentVisibility `json:"visibility,omitempty"` } // AddIssueComment adds comment to an issue using POST /issue/{key}/comment endpoint. -func (c *Client) AddIssueComment(key, comment string, internal bool) error { - body, err := json.Marshal(&issueCommentRequest{Body: md.ToJiraMD(comment), Properties: []issueCommentProperty{{Key: "sd.public.comment", Value: issueCommentPropertyValue{Internal: internal}}}}) +func (c *Client) AddIssueComment(key, comment string, internal bool, visibilityGroup string) error { + issueReq := issueCommentRequest{ + Body: md.ToJiraMD(comment), + Properties: []issueCommentProperty{{Key: "sd.public.comment", Value: issueCommentPropertyValue{Internal: internal}}}, + } + + if visibilityGroup != "" { + issueReq.Visibility = issueCommentVisibility{Type: "group", Value: visibilityGroup} + } + + body, err := json.Marshal(issueReq) if err != nil { return err } diff --git a/pkg/jira/issue_test.go b/pkg/jira/issue_test.go index 85664231..4e3745f1 100644 --- a/pkg/jira/issue_test.go +++ b/pkg/jira/issue_test.go @@ -531,7 +531,7 @@ func TestAddIssueComment(t *testing.T) { actualBody := new(strings.Builder) _, _ = io.Copy(actualBody, r.Body) - expectedBody := `{"body":"comment","properties":[{"key":"sd.public.comment","value":{"internal":false}}]}` + expectedBody := `{"body":"comment","properties":[{"key":"sd.public.comment","value":{"internal":false}}],"visibility":{}}` assert.Equal(t, expectedBody, actualBody.String()) @@ -545,12 +545,12 @@ func TestAddIssueComment(t *testing.T) { client := NewClient(Config{Server: server.URL}, WithTimeout(3*time.Second)) - err := client.AddIssueComment("TEST-1", "comment", false) + err := client.AddIssueComment("TEST-1", "comment", false, "") assert.NoError(t, err) unexpectedStatusCode = true - err = client.AddIssueComment("TEST-1", "comment", false) + err = client.AddIssueComment("TEST-1", "comment", false, "") assert.Error(t, &ErrUnexpectedResponse{}, err) }