Skip to content

Format only PR-changed files in web edit workflow#898

Open
ntotten wants to merge 1 commit intomainfrom
ntotten/format-pr-files
Open

Format only PR-changed files in web edit workflow#898
ntotten wants to merge 1 commit intomainfrom
ntotten/format-pr-files

Conversation

@ntotten
Copy link
Member

@ntotten ntotten commented Feb 10, 2026

Summary

  • Instead of running prettier on all **/*.md files, fetches the list of files changed in the PR via the GitHub API and formats only those
  • Broadens formatting to all file types prettier supports (md, json, yaml, ts, etc.) while keeping scope limited to PR-touched files
  • Uses --ignore-unknown so prettier skips file types it doesn't have a parser for

Test plan

  • Open a PR via the GitHub web editor that modifies a markdown file and verify it gets formatted
  • Open a PR that modifies a non-markdown file (e.g., JSON) and verify it gets formatted
  • Verify deleted files in a PR are excluded from formatting

🤖 Generated with Claude Code

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>
@vercel
Copy link

vercel bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Feb 10, 2026 1:54pm

Request Review

Comment on lines +37 to +44
- 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

Potential unsafe checkout of untrusted pull request on privileged workflow.

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).


Suggested changeset 1
.github/workflows/format.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml
--- a/.github/workflows/format.yaml
+++ b/.github/workflows/format.yaml
@@ -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
EOF
@@ -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
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant