action-pr-comment/action.yml
GregoryDosh b422c1bb0f revert 803b90604e
revert Update action.yml
2024-03-02 21:19:24 +00:00

52 lines
1.6 KiB
YAML

name: Post/Update PR Comment
description: An action to add or update an existing comment anchored in a PR for test results, status messages, etc.
inputs:
pr-anchor:
description: 'The unique identifier to anchor/update when posting a comment.'
required: false
default: '${{ github.workflow }}'
comment:
description: 'The comment to leave on the PR.'
required: true
github-token:
description: 'A GitHub (or compatible) token.'
required: true
runs:
using: "composite"
steps:
- uses: https://github.com/actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ inputs.github-token }}
script: |
const anchor = '<!-- Bot Anchor - ${{ inputs.pr-anchor }} -->'
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const existingComment = comments.find(comment => {
return comment.body.includes(anchor)
})
const output = `${anchor}
${{ inputs.comment }}`
if (existingComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}