[Repo Assist] refactor(guard): deduplicate label_response write paths and extract get_author_association#8343
Conversation
…et_author_association Replace the two duplicate 10-line write blocks in label_response (path-based and legacy branches) with calls to try_write_json_output, mapping its -1 failure code to the 0 that label_response uses for 'skip labeling'. Extract a private get_author_association helper in helpers.rs to consolidate the dual-alias lookup (author_association / authorAssociation) that was duplicated between has_author_association and author_association_floor. Fixes: - Removes unsafe as u32 / as i32 truncation casts (now uses try_from) - All three exported WASM functions use the same safe write helper - Single source of truth for the two-alias field lookup Closes #8328 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the Rust GitHub guard to reduce duplication and make label_response output writing consistent with other exported WASM entrypoints by routing through the existing safe try_write_json_output helper, and centralizes author_association alias lookup logic in one place.
Changes:
- Refactors
label_responseto usetry_write_json_outputfor both the path-based and legacy output write paths (avoids unsafeas u32/as i32casts). - Extracts a private
get_author_associationhelper and reuses it fromhas_author_associationandauthor_association_floor. - Updates/expands doc comments around the author association extraction helper.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/lib.rs | Deduplicates label_response output writing via try_write_json_output and maps write failures to the existing “skip labeling” return convention. |
| guards/github-guard/rust-guard/src/labels/helpers.rs | Deduplicates the author_association/authorAssociation lookup into a single helper and updates call sites. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request and fix failing ci checks https://github.com/github/gh-aw-mcpg/actions/runs/28448521427/job/84304139332?pr=8343 |
…-assist/fix-rust-guard-dedup-8328-4e0d93d67886d79e # Conflicts: # guards/github-guard/rust-guard/src/lib.rs
Merged The CI failure was caused by a missing closing |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Closes #8328
Problem
label_responseinlib.rshad two near-identical 10-line write blocks — one in the path-based branch and one in the legacy item-based branch — that both reimplemented the output-write logic manually:output_json.len() as u32 > output_size— theas u32cast is unsound for outputs exceeding 4 GBoutput_json.len() as i32return — can produce a negative return value if output exceedsi32::MAX, which the host misinterprets as an error codeMeanwhile,
try_write_json_output(already used inlabel_agentandlabel_resource) handles these casts safely viau32::try_from/i32::try_from.label_responsewas never updated to use it.Similarly,
has_author_associationandauthor_association_floorinhelpers.rsboth duplicated the dual-alias lookup forauthor_association/authorAssociation.Fix
lib.rs: Replace both write blocks with two-linetry_write_json_outputcalls, mapping-1(buffer too small / overflow) to0(label_response's "skip labeling" signal):helpers.rs: Extract a privateget_author_associationhelper and delegate both callers to it:Impact
label_responsebranchesTest Status
All 556 Rust unit tests pass (
cargo testgreen). Go tests skipped due to sandbox network restrictions (infrastructure-only failure, not caused by these changes).Add this agentic workflow to your repo
To install this agentic workflow, run