Skip to content

addComment V3 support simple string body #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2023
Merged
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
11 changes: 8 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 14 additions & 5 deletions src/version3/issueComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class IssueComments {
*/
async getCommentsByIds<T = Models.PageComment>(
parameters: Parameters.GetCommentsByIds,
callback: Callback<T>
callback: Callback<T>,
): Promise<void>;
/**
* Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of
Expand Down Expand Up @@ -77,7 +77,7 @@ export class IssueComments {
*/
async getComments<T = Models.PageOfComments>(
parameters: Parameters.GetComments | string,
callback: Callback<T>
callback: Callback<T>,
): Promise<void>;
/**
* Returns all comments for an issue.
Expand All @@ -96,7 +96,7 @@ export class IssueComments {
*/
async getComments<T = Models.PageOfComments>(
parameters: Parameters.GetComments | string,
callback?: never
callback?: never,
): Promise<T>;
async getComments<T = Models.PageOfComments>(
parameters: Parameters.GetComments | string,
Expand Down Expand Up @@ -145,7 +145,16 @@ export class IssueComments {
*/
async addComment<T = Models.Comment>(parameters: Parameters.AddComment, callback?: never): Promise<T>;
async addComment<T = Models.Comment>(parameters: Parameters.AddComment, callback?: Callback<T>): Promise<void | T> {
// 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`,
Expand All @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions src/version3/parameters/addComment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Comment } from '../models';
import { Comment, Document } from '../models';

export interface AddComment extends Comment {
export interface AddComment extends Omit<Comment, 'body'> {
/** The ID or key of the issue. */
issueIdOrKey: string;
/**
Expand All @@ -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;
}
37 changes: 37 additions & 0 deletions tests/unit/version3/issueComments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});