import type { context as ctx, GitHub } from '@actions/github/lib/utils'; /** * Notifies the PR about uncommitted changes generated by the `generate:*` commands. * * This script is used by github-script * https://github.com/actions/github-script * * @param github A pre-authenticated octokit/rest.js client with pagination plugins * @param context An object containing the context of the workflow run * @param isSuccess A boolean indicating whether the workflow was successful */ export async function script( github: InstanceType, context: typeof ctx, isSuccess: boolean ): Promise { const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); const body = `GitHub Actions has found some problems running the preflight checks. Please make sure to: - run \`pnpm run preflight\` locally - fix all issues until the command completes without errors - commit and push the changes `; const botComment = comments.find( (comment) => comment.user?.type === 'Bot' && comment.body?.includes(body) ); if (isSuccess) { if (!botComment) return; await github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: botComment.id, }); return; } if (!botComment) { await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body, }); } }