refactor: reduce complexity of download_build_artifact in src/ado/mod.rs - #2136
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
Split the 178-line download_build_artifact function (flagged by clippy::too_many_lines) into focused helpers: - prepare_artifact_extraction_dir: create/reset the extraction dir - check_artifact_download_status: HTTP status validation with the 401/403 PAT-scope guidance - stream_artifact_to_temp_zip: stream the response body to a temp zip - artifact_zip_has_repeated_root: detect a repeated root directory in the archive - extract_zip_entry: extract a single zip entry, stripping the repeated root when present - extract_artifact_zip: open the temp zip and extract all entries No behaviour change — download_build_artifact now orchestrates these helpers. clippy::too_many_lines / cognitive_complexity no longer fire for this file; all existing ado:: tests and the full test suite pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
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
Refactors
download_build_artifactinsrc/ado/mod.rs, which clippy flagged withtoo_many_linesat 178/100 lines and high cognitive complexity from mixed concerns: directory prep, HTTP status handling (with 401/403 PAT-scope guidance), streaming the response into a temp zip, and zip extraction (including repeated-root detection/stripping) all lived in a single function.Changes
Extracted six focused helper functions, each with a single responsibility:
prepare_artifact_extraction_dir— create/reset the artifact extraction directorycheck_artifact_download_status— validate the HTTP response status, returning the structured 401/403 error with PAT-scope guidancestream_artifact_to_temp_zip— stream the response body into a temp zip fileartifact_zip_has_repeated_root— detect whether every zip entry shares the artifact name as its top-level path componentextract_zip_entry— extract a single zip entry, stripping the repeated root when presentextract_artifact_zip— open the downloaded temp zip and extract all entriesdownload_build_artifactnow simply orchestrates these helpers in sequence. No public API changes and no behavioural changes — error messages, extraction logic, and repeated-root handling are byte-for-byte identical to before.Verification
cargo build --bin ado-aw— cleancargo clippy --all-targets --all-features— clean, notoo_many_lines/cognitive_complexitywarnings remain for this filecargo test— full suite passes (3358+ tests), includingado::tests::download_build_artifact_errors_when_download_url_is_missingBefore / after complexity
too_many_lines (178/100)too_many_linesorcognitive_complexitywarning fordownload_build_artifactor any of the new helpersWarning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.