refactor: reduce complexity of execute_impl in upload_build_attachment.rs - #2094
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…t.rs Split the 267/100 too_many_lines execute_impl() into 9 focused helper functions: resolve_effective_build_id, resolve_final_artifact_name, validate_file_extension, resolve_attachment_type, resolve_staged_file, read_and_verify_staged_bytes, resolve_timeline_coords, and upload_timeline_attachment (plus a TimelineAttachmentCoords struct to group the ADO API coordinates). execute_impl() is now a short orchestration function that delegates to these helpers via early returns on Result<T, ExecutionResult>. No behavior change. Full suite (3322 tests) + clippy pass. clippy --all-targets --all-features -W clippy::too_many_lines no longer flags this file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 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.
What was complex
UploadBuildAttachmentResult::execute_impl()insrc/safe_outputs/upload_build_attachment.rswas flagged by Clippy'stoo_many_lineslint at 267/100 lines. It combined build-ID reconciliation, artifact-name-prefix/validation, allow-list checks, extension checks, attachment-type resolution, staged-file path/integrity validation, SHA-256 verification, ADO API coordinate resolution, and the HTTP PUT + response handling all inline in one function.What changed
Split the function into 9 focused, independently-testable helpers (following the existing
Result<T, ExecutionResult>early-return pattern already used elsewhere in this module, e.g.update_github_issue.rs):resolve_effective_build_id— reconciles agent-suppliedbuild_idwith the current runresolve_final_artifact_name— appliesname-prefix, re-validates charset, checks the artifact-name allow-listvalidate_file_extension— checks the file extension againstallowed-extensionsresolve_attachment_type— resolves and validates the{type}URL segmentresolve_staged_file— canonicalizes/validates the staged file path, size integrity, and size limitread_and_verify_staged_bytes— reads file bytes and verifies the SHA-256 hashresolve_timeline_coords(+ newTimelineAttachmentCoordsstruct) — resolves ADO org/project/token/plan/timeline/record IDsupload_timeline_attachment— builds the URL, performs the PUT, and translates the HTTP responseexecute_impl()is now a short orchestration function (~50 lines) that delegates to these helpers.Verification
cargo test— full suite: 3322 passed, 0 failed (including all 39 tests inupload_build_attachment::tests).cargo clippy --all-targets --all-features— clean.cargo clippy -- -W clippy::too_many_lines— no longer flags this file (previously 267/100).Before/after complexity
execute_implline count (Clippytoo_many_lines)Warning
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.