Skip to content

refactor: reduce complexity of download_build_artifact in src/ado/mod.rs - #2136

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-download-build-artifact-4e979c59c8039a5a
Draft

refactor: reduce complexity of download_build_artifact in src/ado/mod.rs#2136
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-download-build-artifact-4e979c59c8039a5a

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Refactors download_build_artifact in src/ado/mod.rs, which clippy flagged with too_many_lines at 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 directory
  • check_artifact_download_status — validate the HTTP response status, returning the structured 401/403 error with PAT-scope guidance
  • stream_artifact_to_temp_zip — stream the response body into a temp zip file
  • artifact_zip_has_repeated_root — detect whether every zip entry shares the artifact name as its top-level path component
  • extract_zip_entry — extract a single zip entry, stripping the repeated root when present
  • extract_artifact_zip — open the downloaded temp zip and extract all entries

download_build_artifact now 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 — clean
  • cargo clippy --all-targets --all-features — clean, no too_many_lines / cognitive_complexity warnings remain for this file
  • cargo test — full suite passes (3358+ tests), including ado::tests::download_build_artifact_errors_when_download_url_is_missing

Before / after complexity

  • Before: too_many_lines (178/100)
  • After: no too_many_lines or cognitive_complexity warning for download_build_artifact or any of the new helpers

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 · auto · 76 AIC · ⌖ 18.1 AIC · ⊞ 10.2K ·

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

Copy link
Copy Markdown
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.

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