Skip to content

web: update GitHub repo links from fastrepl/hyprnote to fastrepl/char #112

web: update GitHub repo links from fastrepl/hyprnote to fastrepl/char

web: update GitHub repo links from fastrepl/hyprnote to fastrepl/char #112

name: Blog Grammar Check
on:
pull_request:
branches:
- main
paths:
- "apps/web/content/articles/**"
jobs:
grammar-check:
if: startsWith(github.head_ref, 'blog/')
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Get changed files
id: changed-files
run: |
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'apps/web/content/articles/*.mdx' | tr '\n' ' ')
echo "files=$FILES" >> $GITHUB_OUTPUT
if [ -z "$FILES" ]; then
echo "has_files=false" >> $GITHUB_OUTPUT
else
echo "has_files=true" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.changed-files.outputs.has_files == 'true'
run: npm install ai @ai-sdk/anthropic zod
- name: Run grammar check
if: steps.changed-files.outputs.has_files == 'true'
id: grammar-check
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
CHANGED_FILES: ${{ steps.changed-files.outputs.files }}
run: |
node .github/scripts/grammar-check.mjs
- name: Post PR comment
if: steps.changed-files.outputs.has_files == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const comment = fs.readFileSync('grammar-check-results.md', 'utf8');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('<!-- grammar-check-bot -->')
);
const body = `<!-- grammar-check-bot -->\n${comment}`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}