Skip to content

Notify on failed check #4

Notify on failed check

Notify on failed check #4

name: Notify on failed check
on:
check_run:
types: [completed]
permissions:
pull-requests: write
jobs:
notify:
name: notify-on-failed-check
if: github.event.check_run.conclusion == 'failure' && github.event.check_run.name != 'notify-on-failed-check'
runs-on: ubuntu-latest
steps:
- name: Comment on the PR author's check failure
uses: actions/github-script@v7
with:
script: |
const checkRun = context.payload.check_run;
const pullRequests = checkRun.pull_requests || [];
for (const pr of pullRequests) {
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: `⚠️ @${pullRequest.user.login} deployment on ${checkRun.name} failed. [View details](${checkRun.details_url})\n\ncc @shahatWM — this PR preview failed, please check with the author.`,
});
}