Skip to content

refactor(disable): reduce complexity of run() in disable.rs#1489

Merged
jamesadevine merged 1 commit into
mainfrom
refactor/reduce-complexity-disable-run-91f4f9feffffac78
Jul 13, 2026
Merged

refactor(disable): reduce complexity of run() in disable.rs#1489
jamesadevine merged 1 commit into
mainfrom
refactor/reduce-complexity-disable-run-91f4f9feffffac78

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

The run() function in src/disable.rs had a nested match → if → match pattern inside its per-definition loop that made the control flow harder to follow. This PR extracts the loop body into a focused helper.

What changed

New: ApplyOutcome enum

enum ApplyOutcome { Skipped, Patched, Failed }

New: apply_action() async helper
Handles one Action, prints a one-line status message, and returns the outcome — no tallying, no loop concerns. The dry-run check and the HTTP call are now a flat two-arm match instead of a nested if { ... } match { Ok match { ... } Err ... }.

run() loop simplified

// Before: ~25 lines, nested match-if-match
// After:
match apply_action(action, &client, &ado_ctx, &auth, opts.dry_run).await {
    ApplyOutcome::Skipped => skipped += 1,
    ApplyOutcome::Patched => patched += 1,
    ApplyOutcome::Failed  => failure += 1,
}

Complexity delta

Function Before After
run() ~15 (nested loops) ~6 (flat coordinator)
apply_action() — (new) ~8

Checklist

  • cargo build — clean
  • cargo test — all pass
  • cargo clippy --all-targets --all-features — zero warnings
  • No public API changes
  • No behavioural changes

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · 61 AIC · ⌖ 12.1 AIC · ⊞ 7.2K ·

Extract ApplyOutcome enum and apply_action() helper so the per-definition
loop body is a flat three-arm match instead of nested match-if-match.

- New: ApplyOutcome { Skipped, Patched, Failed } enum
- New: apply_action() — handles one Action, prints status, returns outcome
- run() loop reduced from ~25 lines of nested control flow to 6 lines

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jamesadevine
jamesadevine marked this pull request as ready for review July 13, 2026 10:09
@jamesadevine
jamesadevine merged commit 4fb6b97 into main Jul 13, 2026
20 of 21 checks passed
@jamesadevine
jamesadevine deleted the refactor/reduce-complexity-disable-run-91f4f9feffffac78 branch July 13, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant