diff --git a/.prettierrc b/.prettierrc index 1a6b79ccdb..d0a89fb07d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,10 @@ { - "plugins": [ - "prettier-plugin-jsdoc" - ] + "arrowParens": "avoid", + "endOfLine": "lf", + "plugins": ["prettier-plugin-jsdoc"], + "printWidth": 120, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false } diff --git a/src/version3/issueComments.ts b/src/version3/issueComments.ts index 2e7a8a8b1c..16d9783d01 100644 --- a/src/version3/issueComments.ts +++ b/src/version3/issueComments.ts @@ -24,7 +24,7 @@ export class IssueComments { */ async getCommentsByIds( parameters: Parameters.GetCommentsByIds, - callback: Callback + callback: Callback, ): Promise; /** * Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of @@ -77,7 +77,7 @@ export class IssueComments { */ async getComments( parameters: Parameters.GetComments | string, - callback: Callback + callback: Callback, ): Promise; /** * Returns all comments for an issue. @@ -96,7 +96,7 @@ export class IssueComments { */ async getComments( parameters: Parameters.GetComments | string, - callback?: never + callback?: never, ): Promise; async getComments( parameters: Parameters.GetComments | string, @@ -145,7 +145,16 @@ export class IssueComments { */ async addComment(parameters: Parameters.AddComment, callback?: never): Promise; async addComment(parameters: Parameters.AddComment, callback?: Callback): Promise { - // todo add simple comment structure (string) + const body = typeof parameters.body === 'string' ? { + type: 'doc', + version: 1, + content: [ + { + type: 'paragraph', + content: [{ type: 'text', text: parameters.body }], + }, + ], + } : parameters.body; const config: RequestConfig = { url: `/rest/api/3/issue/${parameters.issueIdOrKey}/comment`, @@ -157,7 +166,7 @@ export class IssueComments { self: parameters.self, id: parameters.id, author: parameters.author, - body: parameters.body, + body, renderedBody: parameters.renderedBody, updateAuthor: parameters.updateAuthor, created: parameters.created, diff --git a/src/version3/parameters/addComment.ts b/src/version3/parameters/addComment.ts index 92358f9347..cda4b7d549 100644 --- a/src/version3/parameters/addComment.ts +++ b/src/version3/parameters/addComment.ts @@ -1,6 +1,6 @@ -import { Comment } from '../models'; +import { Comment, Document } from '../models'; -export interface AddComment extends Comment { +export interface AddComment extends Omit { /** The ID or key of the issue. */ issueIdOrKey: string; /** @@ -9,4 +9,9 @@ export interface AddComment extends Comment { * rendered in HTML. */ expand?: string; + /** + * The comment text in [Atlassian Document + * Format](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/). + */ + body?: string | Document; } diff --git a/tests/unit/version3/issueComments.test.ts b/tests/unit/version3/issueComments.test.ts index 40716dc261..e0996dbbc3 100644 --- a/tests/unit/version3/issueComments.test.ts +++ b/tests/unit/version3/issueComments.test.ts @@ -39,3 +39,40 @@ test('addComment should accept follow parameters', t => { visibility: undefined, }); }); + +test('addComment should accept body string and convert to simple Document', t => { + const client = new Version3Client({ + host: 'http://localhost', + newErrorHandling: true, + }); + const sendRequestStub = sinon.stub(client, 'sendRequest'); + + client.issueComments.addComment({ + issueIdOrKey: 'key', + body: 'Comment', + }); + + t.truthy(sendRequestStub.calledOnce); + + const callArgument = sendRequestStub.getCall(0).args[0]; + + t.is(callArgument.url, '/rest/api/3/issue/key/comment'); + t.deepEqual(callArgument.data, { + author: undefined, + body: { + type: 'doc', + version: 1, + content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Comment' }] }], + }, + created: undefined, + id: undefined, + jsdAuthorCanSeeRequest: undefined, + jsdPublic: undefined, + properties: undefined, + renderedBody: undefined, + self: undefined, + updateAuthor: undefined, + updated: undefined, + visibility: undefined, + }); +});