refactor: reduce complexity of classify_definition in src/ado/discovery.rs#1589
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…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>
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
classify_definitioninsrc/ado/discovery.rs(89 lines) constructed the same 6-fieldDiscoveredPipelinestruct literal five times — once for every error arm of thepreview_pipelinematch and once for the early-return fast path. Every copy repeateddefinition_id: def.id,definition_name: def.name,repository_url,queue_status: def.queue_statusverbatim, with onlymarkersandstatusvarying. 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:
make_discovered_pipeline(def, repository_url, markers, status) -> DiscoveredPipeline— consumes aDefinitionSummaryand the two varying fields to build the struct in one place (9 lines).classify_preview_result(def, repository_url, result) -> DiscoveredPipeline— owns thematch preview_pipeline(...)arms and delegates struct construction tomake_discovered_pipeline. TheNotFounddebug log stays in the arm that needs it (35 lines total).classify_definitionitself shrinks to ~20 lines: the fast-path early return (now a single call tomake_discovered_pipeline) and a one-liner delegation toclassify_preview_result.Before / After
classify_definitionclassify_preview_resultmake_discovered_pipelineVerification
cargo build— cleancargo test— all tests passcargo clippy --all-targets --all-features— no new warnings (one pre-existingmatch → ?warning insrc/compile/common.rs, unrelated)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.