Bug: Datatable pagination issue on Firefox(?) #298
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: Auto-format PR on Comment | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
format: | |
# only run on PR comments | |
if: github.event.issue.pull_request | |
runs-on: macos-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Check trigger and permissions | |
uses: actions/github-script@v7 | |
id: check-permission | |
with: | |
script: | | |
const commentBody = context.payload.comment.body; | |
const hasTrigger = commentBody.includes('/format') || commentBody.includes('/autoformat'); | |
if (!hasTrigger) { | |
console.log('Comment does not contain trigger phrase. Skipping.'); | |
core.setOutput('should-continue', 'false'); | |
return false; | |
} | |
const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
username: context.payload.comment.user.login | |
}); | |
const hasWriteAccess = ['admin', 'write'].includes(perm.permission); | |
if (!hasWriteAccess) { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: '❌ Sorry, you need write access to trigger auto-formatting.' | |
}); | |
core.setOutput('should-continue', 'false'); | |
return false; | |
} | |
core.setOutput('should-continue', 'true'); | |
return true; | |
- name: Get PR details | |
if: steps.check-permission.outputs.should-continue == 'true' | |
uses: actions/github-script@v7 | |
id: get-pr | |
with: | |
script: | | |
const { data: pr } = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}); | |
core.setOutput('head-ref', pr.head.ref); | |
core.setOutput('head-sha', pr.head.sha); | |
core.setOutput('base-ref', pr.base.ref); | |
core.setOutput('pr-number', pr.number); | |
- name: React to comment | |
if: steps.check-permission.outputs.should-continue == 'true' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
await github.rest.reactions.createForIssueComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: context.payload.comment.id, | |
content: 'rocket' | |
}); | |
- name: Checkout PR branch | |
if: steps.check-permission.outputs.should-continue == 'true' | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.get-pr.outputs.head-ref }} | |
- uses: pnpm/action-setup@v4 | |
if: steps.check-permission.outputs.should-continue == 'true' | |
- uses: actions/setup-node@v4 | |
if: steps.check-permission.outputs.should-continue == 'true' | |
with: | |
node-version: 20 | |
cache: pnpm | |
- name: Install dependencies | |
if: steps.check-permission.outputs.should-continue == 'true' | |
run: pnpm install | |
- name: Run formatter | |
if: steps.check-permission.outputs.should-continue == 'true' | |
run: pnpm format . | |
- name: Check for changes | |
if: steps.check-permission.outputs.should-continue == 'true' | |
id: check-changes | |
run: | | |
if [[ -z $(git status --porcelain) ]]; then | |
echo "has-changes=false" >> $GITHUB_OUTPUT | |
else | |
echo "has-changes=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit and push changes | |
if: steps.check-permission.outputs.should-continue == 'true' && steps.check-changes.outputs.has-changes == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "chore: auto-format code via GitHub Action | |
Triggered by @${{ github.event.comment.user.login }} in PR #${{ steps.get-pr.outputs.pr-number }}" | |
git push origin HEAD:${{ steps.get-pr.outputs.head-ref }} | |
- name: Comment on PR with result | |
uses: actions/github-script@v7 | |
if: always() && steps.check-permission.outputs.should-continue == 'true' | |
with: | |
script: | | |
const hasChanges = '${{ steps.check-changes.outputs.has-changes }}' === 'true'; | |
const success = '${{ job.status }}' === 'success'; | |
let body; | |
if (!success) { | |
body = '❌ Auto-formatting failed. Please check the workflow logs.'; | |
} else if (hasChanges) { | |
body = '✅ Code has been auto-formatted and changes have been pushed to this PR.'; | |
} else { | |
body = '✅ No formatting changes needed. Code is already properly formatted.'; | |
} | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: body | |
}); |