Format only PR-changed files in web edit workflow#898
Conversation
Instead of running prettier on all **/*.md files, fetch the list of files changed in the PR via the GitHub API and format only those. This broadens formatting to all file types prettier supports while keeping the scope limited to what the PR actually touches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| - name: Checkout PR branch | ||
| if: ${{ steps.webui.outputs.is_webui == 'true' }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node |
Check warning
Code scanning / CodeQL
Checkout of untrusted code in trusted context Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 days ago
In general, the safest pattern is to ensure that workflows which check out and execute untrusted PR code do not perform privileged actions (such as pushing commits) or handle secrets. Instead, they should only build/test/format and upload results as artifacts. A separate privileged workflow, triggered via workflow_run, can then review or apply changes as needed using trusted code from the base repository, not from the untrusted PR head.
For this specific workflow, the simplest fix that preserves existing functionality as much as possible and removes the “checkout of untrusted code in privileged context” is to stop explicitly checking out the PR head ref and instead check out the trusted base branch (the repository’s default base for the PR). That way, the code being executed (npm ci, npx prettier) comes from the trusted base branch, while we still format and commit changes to the PR branch. This addresses the security concern (no untrusted code execution) while maintaining the job’s purpose (auto-format web-UI PRs in-place).
Concretely, we will change the with.ref argument in the “Checkout PR branch” step to use github.event.pull_request.base.ref instead of github.event.pull_request.head.ref. No additional imports or actions are required; everything else in the workflow remains the same. The job will still run only for same-repo branches and keep the same permissions and subsequent steps (npm ci, npx prettier, git push).
| @@ -34,11 +34,11 @@ | ||
|
|
||
| core.setOutput("is_webui", hasWebFlow ? "true" : "false"); | ||
|
|
||
| - name: Checkout PR branch | ||
| - name: Checkout PR base branch | ||
| if: ${{ steps.webui.outputs.is_webui == 'true' }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.ref }} | ||
| ref: ${{ github.event.pull_request.base.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node |
There was a problem hiding this comment.
Can we just make it so this doesnt run without approval for non members? Also we should filter so we only do this on PRs that are brances of this repo, not forks
Summary
**/*.mdfiles, fetches the list of files changed in the PR via the GitHub API and formats only those--ignore-unknownso prettier skips file types it doesn't have a parser forTest plan
🤖 Generated with Claude Code