Skip to content

refactor: reduce complexity of execute_impl in upload_build_attachment.rs#1656

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-upload-build-attachment-b39e2174a6be97a2
Draft

refactor: reduce complexity of execute_impl in upload_build_attachment.rs#1656
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-upload-build-attachment-b39e2174a6be97a2

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

UploadBuildAttachmentResult::execute_impl was a 345-line monolithic async function with 6 separate inline phases, each with its own error-return paths and nesting depth up to 5 levels.

What was complex

The function sequentially handled:

  1. Build-ID match/validation (current-run-only invariant, 4-arm match)
  2. Name-prefix application + charset/allowlist validation
  3. Attachment-type resolution + charset validation
  4. Staged-file path canonicalization, directory guard, size integrity check
  5. ADO API context collection (org URL, token, project, project ID, plan/timeline/record IDs) + URL construction
  6. HTTP PUT upload + response parsing

Each phase had 2–4 early-return failure paths, making the function hard to read and test in isolation.

What changed

Extracted five focused helpers:

Helper Responsibility
resolve_effective_build_id Build-ID match/validation; returns Ok(Ok(id)) / Ok(Err(failure)) / Err(infra)
resolve_final_artifact_name Name-prefix application + charset + allowlist checks
resolve_attachment_type Operator config resolution + charset validation
resolve_staged_file Path canonicalization, escape guard, directory check, size integrity
resolve_ado_attachment_url ADO context collection + timeline-attachment URL construction
upload_attachment_to_ado HTTP PUT + response parsing (uses AttachmentUploadParams struct to avoid clippy too_many_arguments)

execute_impl body shrinks from 345 lines to ~100 lines of clear sequential phases.

Verification

  • All 2580 unit tests pass
  • Clippy is clean (zero warnings/errors)
  • No behaviour changes — all error messages, log lines, and response shapes are preserved verbatim

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 · 124.8 AIC · ⌖ 16 AIC · ⊞ 7.2K ·

…t.rs

Extract five focused helpers from the 345-line monolithic execute_impl:
- resolve_effective_build_id: build-ID match/validation logic
- resolve_final_artifact_name: name-prefix application + charset/allowlist checks
- resolve_attachment_type: operator config resolution + charset validation
- resolve_staged_file: path canonicalization, directory guard, size integrity check
- resolve_ado_attachment_url: ADO context collection + timeline-attachment URL construction
- upload_attachment_to_ado: HTTP PUT + response parsing (AttachmentUploadParams struct)

execute_impl body shrinks from 345 lines to ~100 lines of clear sequential
phases. All 2580 unit tests pass; clippy is clean.

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