chore(deps): renovatebot/github-action ^ v46.1.19 #38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bot - PR Formatting Checks | |
| on: | |
| pull_request_target: | |
| types: [opened, edited, synchronize] | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| check-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Validate PR Title and Body | |
| uses: actions/github-script@v9 | |
| env: | |
| PR_BODY: ${{ github.event.pull_request.body }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| with: | |
| github-token: ${{ secrets.BOT_GITHUB_TOKEN }} | |
| script: | | |
| const title = process.env.PR_TITLE; | |
| const body = process.env.PR_BODY || ""; | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const pull_number = context.issue.number; | |
| let errors = []; | |
| // 1. Conventional Commits + title length | |
| const ccRegex = /^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9\-]+\))?:\s.+$/; | |
| if (!ccRegex.test(title)) { | |
| errors.push("- **Title**: Does not follow conventional commits (e.g., `feat: add Kitty z-index support`, `fix(sandbox): handle EINTR`)."); | |
| } | |
| if (title.length >= 60) { | |
| errors.push(`- **Title**: Is too long (${title.length} characters). Keep PR titles under 60 characters.`); | |
| } | |
| // 2. PR template adherence | |
| if (!body.includes("## What?") || !body.includes("## Why?")) { | |
| errors.push("- **Body**: Missing the `## What?` or `## Why?` headings required by the PR template."); | |
| } | |
| // Strip HTML comments to detect untouched template placeholders | |
| const cleanedBody = body.replace(/<!--[\s\S]*?-->/g, "").trim(); | |
| if (cleanedBody.length < 10) { | |
| errors.push("- **Body**: The PR description is too short or hasn't replaced the template placeholders."); | |
| } | |
| // 3. Request changes or dismiss prior bot review | |
| if (errors.length > 0) { | |
| const message = `Hi @${context.actor}! Please fix the following issues with your PR:\n\n${errors.join("\n")}`; | |
| await github.rest.pulls.createReview({ | |
| owner, | |
| repo, | |
| pull_number, | |
| body: message, | |
| event: 'REQUEST_CHANGES' | |
| }); | |
| core.setFailed("PR formatting checks failed."); | |
| } else { | |
| const { data: botUser } = await github.rest.users.getAuthenticated(); | |
| const { data: reviews } = await github.rest.pulls.listReviews({ | |
| owner, | |
| repo, | |
| pull_number | |
| }); | |
| const botReviews = reviews.filter(r => | |
| r.user.login === botUser.login && | |
| r.state === 'CHANGES_REQUESTED' | |
| ); | |
| for (const review of botReviews) { | |
| await github.rest.pulls.dismissReview({ | |
| owner, | |
| repo, | |
| pull_number, | |
| review_id: review.id, | |
| message: 'Formatting issues have been resolved. Thank you!' | |
| }); | |
| } | |
| } |