52 lines
1.6 KiB
YAML
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
|
|
})
|
|
}
|