Skip to content

refactor: reduce complexity of classify_definition in src/ado/discovery.rs#1589

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-classify-definition-cb7a386714752b5e
Draft

refactor: reduce complexity of classify_definition in src/ado/discovery.rs#1589
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-classify-definition-cb7a386714752b5e

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

classify_definition in src/ado/discovery.rs (89 lines) constructed the same 6-field DiscoveredPipeline struct literal five times — once for every error arm of the preview_pipeline match and once for the early-return fast path. Every copy repeated definition_id: def.id, definition_name: def.name, repository_url, queue_status: def.queue_status verbatim, with only markers and status varying. This made it hard to see the actual decision logic and meant any struct-field change required five edits.

What changed

Two focused helpers were extracted:

  1. make_discovered_pipeline(def, repository_url, markers, status) -> DiscoveredPipeline — consumes a DefinitionSummary and the two varying fields to build the struct in one place (9 lines).

  2. classify_preview_result(def, repository_url, result) -> DiscoveredPipeline — owns the match preview_pipeline(...) arms and delegates struct construction to make_discovered_pipeline. The NotFound debug log stays in the arm that needs it (35 lines total).

classify_definition itself shrinks to ~20 lines: the fast-path early return (now a single call to make_discovered_pipeline) and a one-liner delegation to classify_preview_result.

Before / After

Before After
classify_definition 89 lines, struct repeated 5× ~20 lines
classify_preview_result (inline) 35 lines
make_discovered_pipeline (inline) 9 lines

Verification

  • cargo build — clean
  • cargo test — all tests pass
  • cargo clippy --all-targets --all-features — no new warnings (one pre-existing match → ? warning in src/compile/common.rs, unrelated)

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 · 137.3 AIC · ⌖ 12.2 AIC · ⊞ 7.2K ·

…ry.rs

Extract make_discovered_pipeline and classify_preview_result helpers to
eliminate 5× repeated DiscoveredPipeline struct construction in
classify_definition.

Before: classify_definition was 89 lines with the same 6-field struct
literal repeated verbatim for every error arm.

After: classify_definition is 20 lines (fast-path early-return + one
delegating call); classify_preview_result owns the match and delegates
struct construction to make_discovered_pipeline (7 lines). Each helper
is small and independently testable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants