Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions internal/cmd/issue/comment/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand All @@ -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 {
Expand All @@ -144,19 +149,23 @@ 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)

internal, err := flags.GetBool("internal")
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,
}
}

Expand Down
20 changes: 18 additions & 2 deletions pkg/jira/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/jira/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)
}

Expand Down