refactor: reduce complexity of resolve_reviewer_identity in create_pull_request.rs#1149
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…ll_request.rs Extract is_reviewer_guid() and find_identity_in_response() from the monolithic resolve_reviewer_identity() function (cognitive complexity 18 → below threshold). - is_reviewer_guid: encapsulates the 3-condition GUID check that was inline in the function body - find_identity_in_response: extracts all Identity Picker JSON navigation (triple &&-let chain, exact-match loop, first-result fallback) into a standalone helper that uses ? for early return; caller just calls the helper and emits a single warning on None - resolve_reviewer_identity: flattened with an early-return on HTTP error and a separate early-return on non-success status, removing one level of match nesting All tests pass; cargo clippy is clean. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
resolve_reviewer_identityinsrc/safeoutputs/create_pull_request.rshad a cognitive complexity of 18 (threshold: 15). The complexity came from three layers stacked together:&&-chained boolean expressions)match— outer on the HTTP send result, inner on JSON parsing&&-let chain inside the success arm to navigateresults[0].identitiesplus aforloop with its own&&-let condition and a separate fallback&&-letWhat changed
Two focused helpers extracted:
fn is_reviewer_guid(s: &str) -> boolEncapsulates the three-condition GUID check (length 36, exactly 4 hyphens, all hex/hyphen chars). Makes the call site read as intent, not implementation.
fn find_identity_in_response(data: &Value, reviewer: &str) -> Option<String>All Identity Picker JSON navigation in one place:
?for early return when fields are missing (replaces the triple&&-let chain)async fn resolve_reviewer_identity(simplified)Now reads as four sequential steps:
is_reviewer_guidfind_identity_in_response; warn ifNoneBefore / After complexity
resolve_reviewer_identityfind_identity_in_responseis_reviewer_guidVerification
cargo build— cleancargo test— all tests passcargo clippy --all-targets --all-features— clean (fixed one collapsible-if suggestion in the extracted helper)cargo clippy -W clippy::cognitive_complexitywith threshold=15 — zero warnings forcreate_pull_request.rsWarning
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.