refactor: reduce complexity of execute_safe_outputs in execute.rs#313
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
refactor: reduce complexity of execute_safe_outputs in execute.rs#313github-actions[bot] wants to merge 1 commit intomainfrom
execute_safe_outputs in execute.rs#313github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Extract four focused helpers to bring cognitive complexity from 34 down to below the 25 threshold: - log_execution_context: pulls out the debug-logging block including the conditional allowed-repositories list; removes one branch from the main function body. - log_queued_entries: isolates the pre-execution for+if-let loop that enumerates queued entries at debug level. - enforce_budget: flattens the previously triply-nested if-let chain for budget enforcement into a ?-chained helper that mutates the counter in place and returns Option<ExecutionResult>. - log_and_print_entry_result: moves the if/else-if/else result-logging block out of the deeply nested match Ok arm. The main loop is now five lines of straightforward sequencing rather than a deeply nested tangle. Behaviour is identical; all tests pass. 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
execute_safe_outputsinsrc/execute.rshad a cognitive complexity of 34 (threshold: 25), driven by:if !ctx.allowed_repositories.is_empty()branch directly in the function bodyif let tool_name / if let (executed, max) / if let Some(result)budget-enforcement blockif result.is_warning() / else if result.success / elsechain inside an already-nestedmatch OkarmWhat changed
Four focused helper functions were extracted — no logic was altered:
log_execution_context(safe_output_dir, ctx)log_queued_entries(entries)enforce_budget(entry, budgets, total, i)if letnesting via?-chaining; mutates the counter and returnsOption<ExecutionResult>log_and_print_entry_result(i, total, tool_name, result)if/else if/elseresult-logging block extracted from the deeply-nested match armThe main loop shrinks from ~70 lines to ~15 lines of straightforward sequencing.
Before / after complexity
clippy::cognitive_complexity)Verification
Warning
The following domain was blocked by the firewall during workflow execution:
dev.azure.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.