refactor: reduce complexity of execute_impl in comment_on_work_item.rs#1521
Merged
jamesadevine merged 1 commit intoJul 15, 2026
Conversation
Extract validate_target_policy helper to flatten the 3-arm match/nested-match block that combined allows_id, area_path_prefix, and get_work_item_area_path into a single nesting depth 6 block. The new helper returns Ok(None) for "allowed", Ok(Some(msg)) for "rejected", keeping execute_impl to a single early-return guard. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7a20ed0 to
ccad08a
Compare
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.
Summary
execute_implinsrc/safe_outputs/comment_on_work_item.rscontained a deeply nested 3-armmatchblock (nesting depth 6, ~50 lines) that mixed three different concerns:allows_id)area_path_prefix)get_work_item_area_path)All of this was inline inside
execute_impl, making it hard to read and test independently.Change
Extracted a new
validate_target_policyasync helper:Ok(None)→ work item is allowed, proceed.Ok(Some(msg))→ policy rejects this work item; caller returnsExecutionResult::failure(msg).Err(...)→ unexpected infrastructure failure (bubbled up with?).execute_implis reduced to a single guard:Before / After
execute_impllinesvalidate_target_policylinesVerification
cargo test)cargo clippy --all-targets --all-features)Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comSee Network Configuration for more information.