refactor: reduce complexity of execute_add_reviewers in update_pr.rs#1023
Merged
jamesadevine merged 1 commit intoJun 15, 2026
Merged
Conversation
Extract per-reviewer loop body into a standalone async helper resolve_and_add_reviewer, reducing execute_add_reviewers cognitive complexity from 21 to below 15 (at threshold=15). The extracted function handles: - VSSPS identity resolution (3 match arms) - PR reviewer PUT request (3 match arms) A new ReviewerAddResult enum carries the per-reviewer outcome back to the caller, replacing the inline push-to-added/push-to-failed pattern. Observable behaviour (success/failure messages, JSON output shape) is unchanged; all 1858 tests continue to pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jamesadevine
approved these changes
Jun 15, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was complex
execute_add_reviewersinsrc/safeoutputs/update_pr.rs(line 648) had a cognitive complexity of 21 (threshold 15 scan; just below the default Clippy threshold of 25). The function combined three separate concerns inline inside a singlefor reviewer in reviewersloop:matchon an HTTP responsematchwithcontinueonNonematchon the HTTP responseThe nesting depth drove the complexity score up: loop (1) → identity match (2) → PUT match (3), with each arm adding its own branches.
What changed
Introduced
ReviewerAddResultenum — a small private enum with two variants:Added— reviewer was successfully addedFailed(String)— short reason string (e.g."identity not found","HTTP 404","request error")Extracted
resolve_and_add_reviewer— a module-levelasync fnthat handles exactly one reviewer:ReviewerAddResultexecute_add_reviewerssimplified — the loop body collapses to a singlematchonReviewerAddResult, accumulatingadded/failedlists. All the VSSPS and HTTP logic lives in the extracted helper.Before / after complexity (at threshold = 15)
execute_add_reviewersresolve_and_add_reviewer(new)Behaviour preserved
cargo clippy --all-targets --all-featuresis clean at the default threshold (25)Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comspsprodweu4.vssps.visualstudio.comSee Network Configuration for more information.