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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ A GitHub action to create or update an issue or pull request comment.
| `comment-id` | The id of the comment to update. | |
| `body` | The comment body. Cannot be used in conjunction with `body-path`. | |
| `body-path` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
| `edit-mode` | The mode when updating a comment, `append`, or `replace`, or `recreate` . | `append` |
| `append-separator` | The separator to use when appending to an existing comment. (`newline`, `space`, `none`) | `newline` |
| `reactions` | A comma or newline separated list of reactions to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
| `reactions-edit-mode` | The mode when updating comment reactions, `replace` or `append`. | `append` |
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ inputs:
body-file:
description: 'Deprecated in favour of `body-path`.'
edit-mode:
description: 'The mode when updating a comment, "replace" or "append".'
description: 'The mode when updating a comment, "append", or "replace", or "recreate".'
default: 'append'
append-separator:
description: 'The separator to use when appending to an existing comment. (`newline`, `space`, `none`)'
Expand Down
58 changes: 38 additions & 20 deletions src/create-or-update-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,35 +151,52 @@ async function updateComment(
octokit,
owner: string,
repo: string,
issueNumber: number,
commentId: number,
body: string,
editMode: string,
appendSeparator: string
): Promise<number> {
if (body) {
let commentBody = ''
if (editMode == 'append') {
// Get the comment body
const {data: comment} = await octokit.rest.issues.getComment({
owner: owner,
repo: repo,
comment_id: commentId
})
commentBody = appendSeparatorTo(
comment.body ? comment.body : '',
appendSeparator
)
}
commentBody = truncateBody(commentBody + body)
core.debug(`Comment body: ${commentBody}`)
await octokit.rest.issues.updateComment({
if (!body) {
return commentId
}

if (editMode == 'recreate') {
await octokit.rest.issues.deleteComment({
owner: owner,
repo: repo,
comment_id: commentId,
body: commentBody
comment_id: commentId
})
core.info(`Removed comment id '${commentId}'.`)

return await createComment(octokit, owner, repo, issueNumber, body)
}

let commentBody = ''
if (editMode == 'append') {
// Get the comment body
const {data: comment} = await octokit.rest.issues.getComment({
owner: owner,
repo: repo,
comment_id: commentId
})
core.info(`Updated comment id '${commentId}'.`)
commentBody = appendSeparatorTo(
comment.body ? comment.body : '',
appendSeparator
)
}

commentBody = truncateBody(commentBody + body)
core.debug(`Comment body: ${commentBody}`)

await octokit.rest.issues.updateComment({
owner: owner,
repo: repo,
comment_id: commentId,
body: commentBody
})
core.info(`Updated comment id '${commentId}'.`)

return commentId
}

Expand Down Expand Up @@ -247,6 +264,7 @@ export async function createOrUpdateComment(
octokit,
owner,
repo,
inputs.issueNumber,
inputs.commentId,
body,
inputs.editMode,
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function run(): Promise<void> {
}
core.debug(`Inputs: ${inspect(inputs)}`)

if (!['append', 'replace'].includes(inputs.editMode)) {
if (!['append', 'replace', 'recreate'].includes(inputs.editMode)) {
throw new Error(`Invalid edit-mode '${inputs.editMode}'.`)
}

Expand Down