action-pr-comment/action.yml
GregoryDosh c1b02a8555 feat: more verbosity in plugin execution (#6)
fix breaking chars through env var sub instead of direct sub

log back in console the comment

fix: sanitize input through env var step

add env step

sanity check env

remove env dump

remove extra step

add debugging steps

Reviewed-on: #6
Co-authored-by: GregoryDosh <authentik@gregorydosh.com>
Co-committed-by: GregoryDosh <authentik@gregorydosh.com>
2024-05-01 04:32:09 +00:00

68 lines
2.2 KiB
YAML

# git.auengun.net/homelab/action-pr-comment
# Copyright (C) 2023 GregoryDosh
---
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
env:
COMMENT: ${{ inputs.comment }}
with:
github-token: ${{ inputs.github-token }}
script: |
const anchor = '<!-- Bot Anchor - ${{ inputs.pr-anchor }} -->'
console.debug("Comment Anchor:")
console.debug(anchor)
const { COMMENT } = process.env
console.debug("Input Comment:")
console.debug(COMMENT)
console.log("Gathering existing comments")
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
console.log("Finding existing comment by anchor")
const existingComment = comments.find(comment => {
return comment.body.includes(anchor)
})
const output = `${anchor}\n` + COMMENT
console.debug("Constructed Output:")
console.debug(output)
if (existingComment) {
console.info("Updating existing comment")
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: output
})
} else {
console.info("Creating new comment")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}