Skip to content

Suggest organization formatting fixes on pull requests - #1362

Merged
mlinksva merged 3 commits into
gh-pagesfrom
alphabetize-suggestions
Nov 17, 2026
Merged

mlinksva merged 3 commits into
gh-pagesfrom
alphabetize-suggestions

Conversation

@mlinksva

Copy link
Copy Markdown
Contributor

Summary

Addresses #991 with review suggestions instead of requiring a token that can push to contributors' forks, as attempted in #1011.

  • Post applyable suggestions for alphabetization and canonical YAML spacing. Contributors or maintainers can commit them through GitHub's review UI.
  • Share the formatter with the existing alphabetization check, which remains a required manual-fix signal when formatting differs.
  • When corrections fall outside GitHub's reviewable diff lines, include a complete applyable patch and the local formatting command in the review.
  • Suppress duplicate suggestions for the same head and refuse to post if the PR changes during processing.

Trust boundary

  • The new pull_request_target workflow checks out only trusted base-branch code, with persisted Git credentials disabled.
  • PR files are fetched as blobs and parsed with YAML.safe_load; no PR scripts, dependencies, or workflows are executed.
  • Permissions are limited to contents read and pull requests write. No fork write token or external service is needed.
  • This workflow becomes active after merging; it cannot demonstrate posting from its own PR.

Validation

  • 13 offline tests, 59 assertions: formatting parity, line ranges, suggestion application, patch application, safe parsing, mocked review posting, deduplication, and stale-head protection.
  • Targeted RuboCop passes.
  • Existing data is unchanged after bundle exec script/alphabetize.
  • Read-only dry run against the original Add Fukushima Lab. #1011 data generates one inline suggestion for line 117, with no fallback needed. No review was posted to that PR.
  • Workflow trust-boundary checks and git diff --check pass.

Run a trusted-base pull_request_target workflow that reads PR YAML through the GitHub API and posts applyable review suggestions without checking out or executing contributor code. Reuse the canonical formatter, avoid duplicate suggestions, detect stale heads, and provide complete patches for corrections outside reviewable diff ranges.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI adaptive review requested due to automatic review settings November 16, 2026 23:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Formatting suggestions can delete organization entries, while crafted filenames can make fallback patches modify files outside _data.

4 open issues
What changed in this PR

Adds review-based formatting help for organization data, addressing #991 without requiring write access to contributors’ forks.

Changes:

  • Shares the canonical YAML formatter between the existing check and suggestion generation.
  • Adds a trusted-base workflow for inline suggestions and fallback patches, with duplicate and stale-head checks.
  • Adds offline tests to the alphabetization workflow.
File Description
test/​alphabetize_suggestions_test.rb Tests formatting, suggestions, patches, parsing safety, and review posting.
script/​suggest-alphabetize Fetches PR data and posts formatting reviews.
script/​alphabetize Delegates formatting to the shared library.
lib/​alphabetize.rb Validates and formats organization YAML.
lib/​alphabetize_suggestions.rb Builds inline suggestions and fallback patches.
.github/​workflows/​suggest-alphabetize.yml Adds the trusted-base review workflow.
.github/​workflows/​ensure-alphabetize.yml Runs suggestion tests and expands relevant path filters.

Review effort: Max (adaptive)

Comment thread lib/alphabetize_suggestions.rb Resolved
Comment thread lib/alphabetize_suggestions.rb Resolved
Comment thread script/suggest-alphabetize Resolved
Address review feedback by combining file corrections into one atomic replacement, rejecting unsafe patch paths, including every changed file in fallback patches, and removing the live-data assertion that suppressed actionable formatting diffs. Add regression tests for moves, injected paths, and applying multi-file patches.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Encoding mismatches cause spurious suggestions for non-ASCII group names, while unpinned file retrieval can produce patches that introduce content absent from the captured PR head.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Pin changed-file retrieval to the captured PR head

script/​suggest-alphabetize:24

The changed-files request uses the live PR rather than the captured head, so an A→B→A head change during processing can leave blobs and patches from B while passing the final SHA check. The bot can then post a suggestion against A that introduces content absent from A when accepted. Pin file and patch retrieval to the captured commits, or verify each file's blob against the captured head before generating suggestions.

Medium severity Set decoded group names to UTF-8 before comparison

script/​suggest-alphabetize:35

Base64.strict_decode64 returns an ASCII-8BIT string, but YAML emits UTF-8. With a valid non-ASCII group name such as Côte, these strings compare unequal despite identical bytes, so an already canonical file receives a no-op suggestion—or a header-only fallback patch when that line is outside the diff. Set the decoded YAML's encoding to UTF-8 before formatting and comparing it.

4 resolved since last review

Review effort: Max (adaptive)

Check each changed file's blob SHA at the captured head before generating suggestions, rejecting transient-head data. Decode and validate UTF-8 to avoid no-op suggestions for non-ASCII group names. Add regression coverage for transient heads and Unicode data.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Contributor Author

Addressed both newly reported findings in 79f231b: each file blob is verified against the captured head SHA before suggestions are generated, so transient A→B→A head changes cannot introduce B-only content; decoded YAML is explicitly validated as UTF-8 before comparison and formatting. Added regressions for a mismatched blob with an otherwise unchanged head, canonical non-ASCII YAML producing no review, and non-ASCII names surviving actual corrections. All 19 tests (86 assertions), targeted RuboCop, and whitespace checks pass.

@mlinksva
mlinksva merged commit f2b7073 into gh-pages Nov 17, 2026
9 checks passed
@mlinksva
mlinksva deleted the alphabetize-suggestions branch November 17, 2026 00:48
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.

2 participants