refactor: reduce complexity of execute_impl in upload_workitem_attachment.rs - #1830
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…ment.rs Extracts the 178-line execute_impl (clippy::too_many_lines 178/100) into four focused helpers: - validate_and_read_file: extension/size/symlink-escape/injection checks + read - upload_attachment_bytes: POST upload to ADO attachments endpoint - link_attachment_to_work_item: PATCH linking the attachment as a work item relation execute_impl now just orchestrates these steps. No behaviour change; all existing tests pass and the too_many_lines warning is cleared. 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
UploadWorkitemAttachmentResult::execute_implwas a 178-line function flagged byclippy::too_many_lines(178/100). It inlined five distinct phases in one body: extension-allowlist validation, symlink-escape-safe path resolution, file-size validation,##vso[command-injection scanning, the ADO attachment upload POST, and the work-item link PATCH — each with its own success/failure branching.What changed
Extracted three focused helpers, keeping
execute_implas a thin orchestrator:validate_and_read_file— extension allowlist, symlink-escape check, size limit, and##vso[injection scan, then reads the file bytes. ReturnsResult<Result<Vec<u8>, ExecutionResult>>so policy rejections surface as normalExecutionResult::failurevalues rather than being conflated with I/O errors.upload_attachment_bytes— POSTs the file to the ADO attachments endpoint and extracts the returned attachment URL.link_attachment_to_work_item— PATCHes theAttachedFilerelation onto the work item and builds the final success/failureExecutionResult.No behavior change: same validation order, same error messages, same success/failure payloads.
Before / after
clippy::too_many_lines (178/100)onexecute_impl.cargo clippy --all-targets --all-features -- -W clippy::cognitive_complexity).Verification
cargo check --all-targets— cleancargo test --bin ado-aw upload_workitem_attachment— all 19 tests pass (plus 2 related tests inexecute::tests)cargo clippy --all-targets --all-features -- -D warnings— no new warnings on the changed file