Skip to content

Commit 1278c80

Browse files
dynekPierrick Brossin
andauthored
feat: Allow adding internal comment on JSD (#825)
Co-authored-by: Pierrick Brossin <pierrick.brossin@kudelskisecurity.com>
1 parent feeb585 commit 1278c80

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ $ jira issue comment add
491491
# Pass required parameters to skip prompt
492492
$ jira issue comment add ISSUE-1 "My comment body"
493493

494+
# Same as above but as an internal comment
495+
$ jira issue comment add ISSUE-1 "My comment body" --internal
496+
494497
# Load comment from template file
495498
$ jira issue comment add ISSUE-1 --template /path/to/template.tmpl
496499

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func NewCmdCommentAdd() *cobra.Command {
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")
5858
cmd.Flags().Bool("no-input", false, "Disable prompt for non-required fields")
59+
cmd.Flags().Bool("internal", false, "Make comment internal")
5960

6061
return &cmd
6162
}
@@ -102,7 +103,7 @@ func add(cmd *cobra.Command, args []string) {
102103
s := cmdutil.Info("Adding comment")
103104
defer s.Stop()
104105

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

@@ -122,6 +123,7 @@ type addParams struct {
122123
body string
123124
template string
124125
noInput bool
126+
internal bool
125127
debug bool
126128
}
127129

@@ -145,11 +147,15 @@ func parseArgsAndFlags(args []string, flags query.FlagParser) *addParams {
145147
noInput, err := flags.GetBool("no-input")
146148
cmdutil.ExitIfError(err)
147149

150+
internal, err := flags.GetBool("internal")
151+
cmdutil.ExitIfError(err)
152+
148153
return &addParams{
149154
issueKey: issueKey,
150155
body: body,
151156
template: template,
152157
noInput: noInput,
158+
internal: internal,
153159
debug: debug,
154160
}
155161
}

pkg/jira/issue.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,22 @@ func (c *Client) GetLinkID(inwardIssue, outwardIssue string) (string, error) {
296296
return "", fmt.Errorf("no link found between provided issues")
297297
}
298298

299+
type issueCommentPropertyValue struct {
300+
Internal bool `json:"internal"`
301+
}
302+
303+
type issueCommentProperty struct {
304+
Key string `json:"key"`
305+
Value issueCommentPropertyValue `json:"value"`
306+
}
299307
type issueCommentRequest struct {
300-
Body string `json:"body"`
308+
Body string `json:"body"`
309+
Properties []issueCommentProperty `json:"properties"`
301310
}
302311

303312
// AddIssueComment adds comment to an issue using POST /issue/{key}/comment endpoint.
304-
func (c *Client) AddIssueComment(key, comment string) error {
305-
body, err := json.Marshal(&issueCommentRequest{Body: md.ToJiraMD(comment)})
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}}}})
306315
if err != nil {
307316
return err
308317
}

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"}`
534+
expectedBody := `{"body":"comment","properties":[{"key":"sd.public.comment","value":{"internal":false}}]}`
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")
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")
553+
err = client.AddIssueComment("TEST-1", "comment", false)
554554
assert.Error(t, &ErrUnexpectedResponse{}, err)
555555
}
556556

0 commit comments

Comments
 (0)