Skip to content

Commit 81c91a8

Browse files
authored
addComment V3 support simple string body (MrRefactoring#260)
* addComment V3 support simple string body * Apply code review suggestions
1 parent 5d9a19b commit 81c91a8

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

.prettierrc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2-
"plugins": [
3-
"prettier-plugin-jsdoc"
4-
]
2+
"arrowParens": "avoid",
3+
"endOfLine": "lf",
4+
"plugins": ["prettier-plugin-jsdoc"],
5+
"printWidth": 120,
6+
"singleQuote": true,
7+
"tabWidth": 2,
8+
"trailingComma": "all",
9+
"useTabs": false
510
}

src/version3/issueComments.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class IssueComments {
2424
*/
2525
async getCommentsByIds<T = Models.PageComment>(
2626
parameters: Parameters.GetCommentsByIds,
27-
callback: Callback<T>
27+
callback: Callback<T>,
2828
): Promise<void>;
2929
/**
3030
* Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of
@@ -77,7 +77,7 @@ export class IssueComments {
7777
*/
7878
async getComments<T = Models.PageOfComments>(
7979
parameters: Parameters.GetComments | string,
80-
callback: Callback<T>
80+
callback: Callback<T>,
8181
): Promise<void>;
8282
/**
8383
* Returns all comments for an issue.
@@ -96,7 +96,7 @@ export class IssueComments {
9696
*/
9797
async getComments<T = Models.PageOfComments>(
9898
parameters: Parameters.GetComments | string,
99-
callback?: never
99+
callback?: never,
100100
): Promise<T>;
101101
async getComments<T = Models.PageOfComments>(
102102
parameters: Parameters.GetComments | string,
@@ -145,7 +145,16 @@ export class IssueComments {
145145
*/
146146
async addComment<T = Models.Comment>(parameters: Parameters.AddComment, callback?: never): Promise<T>;
147147
async addComment<T = Models.Comment>(parameters: Parameters.AddComment, callback?: Callback<T>): Promise<void | T> {
148-
// todo add simple comment structure (string)
148+
const body = typeof parameters.body === 'string' ? {
149+
type: 'doc',
150+
version: 1,
151+
content: [
152+
{
153+
type: 'paragraph',
154+
content: [{ type: 'text', text: parameters.body }],
155+
},
156+
],
157+
} : parameters.body;
149158

150159
const config: RequestConfig = {
151160
url: `/rest/api/3/issue/${parameters.issueIdOrKey}/comment`,
@@ -157,7 +166,7 @@ export class IssueComments {
157166
self: parameters.self,
158167
id: parameters.id,
159168
author: parameters.author,
160-
body: parameters.body,
169+
body,
161170
renderedBody: parameters.renderedBody,
162171
updateAuthor: parameters.updateAuthor,
163172
created: parameters.created,

src/version3/parameters/addComment.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Comment } from '../models';
1+
import { Comment, Document } from '../models';
22

3-
export interface AddComment extends Comment {
3+
export interface AddComment extends Omit<Comment, 'body'> {
44
/** The ID or key of the issue. */
55
issueIdOrKey: string;
66
/**
@@ -9,4 +9,9 @@ export interface AddComment extends Comment {
99
* rendered in HTML.
1010
*/
1111
expand?: string;
12+
/**
13+
* The comment text in [Atlassian Document
14+
* Format](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/).
15+
*/
16+
body?: string | Document;
1217
}

tests/unit/version3/issueComments.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,40 @@ test('addComment should accept follow parameters', t => {
3939
visibility: undefined,
4040
});
4141
});
42+
43+
test('addComment should accept body string and convert to simple Document', t => {
44+
const client = new Version3Client({
45+
host: 'http://localhost',
46+
newErrorHandling: true,
47+
});
48+
const sendRequestStub = sinon.stub(client, 'sendRequest');
49+
50+
client.issueComments.addComment({
51+
issueIdOrKey: 'key',
52+
body: 'Comment',
53+
});
54+
55+
t.truthy(sendRequestStub.calledOnce);
56+
57+
const callArgument = sendRequestStub.getCall(0).args[0];
58+
59+
t.is(callArgument.url, '/rest/api/3/issue/key/comment');
60+
t.deepEqual(callArgument.data, {
61+
author: undefined,
62+
body: {
63+
type: 'doc',
64+
version: 1,
65+
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Comment' }] }],
66+
},
67+
created: undefined,
68+
id: undefined,
69+
jsdAuthorCanSeeRequest: undefined,
70+
jsdPublic: undefined,
71+
properties: undefined,
72+
renderedBody: undefined,
73+
self: undefined,
74+
updateAuthor: undefined,
75+
updated: undefined,
76+
visibility: undefined,
77+
});
78+
});

0 commit comments

Comments
 (0)