Skip to content

Check Positive Reaction on PR Approval #8

Check Positive Reaction on PR Approval

Check Positive Reaction on PR Approval #8

name: Check Positive Reaction on PR Approval
on:
pull_request_review:
types: [submitted]
jobs:
check-reaction:
name: Check for positive reaction on all bot's comments
if: startsWith(github.event.pull_request.head.ref, 'fix-comment-check')
runs-on: ubuntu-latest
steps:
- name: Check for positive reaction on bot's comments
uses: actions/github-script@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Get comments on the PR
const comments = await github.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// Iterate over each comment
for (const comment of comments.data) {
if (comment.user.login === 'github-actions[bot]') {
const reactions = await github.reactions.listForIssueComment({
comment_id: comment.id,
owner: context.repo.owner,
repo: context.repo.repo
});
console.log("Reactions for the comment:", reactions.data); // Logging the reactions for the comment
// If the current bot's comment doesn't have a thumbs-up reaction, fail the action
if (!reactions.data.some(reaction => reaction.content === '+1')) {
core.setFailed("A validation comment by github-actions[bot] does not have the required thumbs-up reaction!");
return; // Exit the script immediately if a comment is found without the thumbs-up reaction
}
}
}
console.log("All bot's comments have the required thumbs-up reaction.");