refactor: reduce complexity of execute_impl in create_pull_request.rs - #1946
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…ull_request.rs Extract create_pull_request.rs's execute_impl (582 lines) into ~9 focused helper methods on CreatePrResult: - build_effective_title - resolve_repo_alias_and_id - read_and_verify_patch - validate_patch_content - setup_worktree_and_collect_changes - resolve_base_commit - ensure_unique_source_branch - build_pr_description - build_fallback_failure_result Also introduces two small grouping structs (AdoConnection, WorktreeChanges) to keep helper signatures manageable, following the existing PushBranchParams/ PrContext convention in this file. execute_impl drops from 582 to 237 lines (clippy::too_many_lines). No behavior change: all 58 create_pull_request tests and the full test suite pass, and cargo clippy --all-targets --all-features is clean.
|
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.
Summary
Refactors
CreatePrResult::execute_implinsrc/safe_outputs/create_pull_request.rs, which clippy flagged as the most complex function in the codebase (clippy::too_many_lines).Before / After
too_many_lineswarning threshold is 100)Approach
Extracted the monolithic function body into focused, well-named helper methods on
CreatePrResult:build_effective_title— apply title prefix + validate the ADO 400-char title limitresolve_repo_alias_and_id— repository alias/ID resolutionread_and_verify_patch— patch existence, size limit, SHA-256 integrity checkvalidate_patch_content— path validation, protected-files check, max-files checksetup_worktree_and_collect_changes— git worktree creation, branch checkout, patch application, change collectionresolve_base_commit— recorded base commit or ADO refs API lookupensure_unique_source_branch— retry-with-suffix loop for branch name collisionsbuild_pr_description— PR body assembly (stats + symlink notice + footer)build_fallback_failure_result— fallback branch-recorded failure resultAlso added two small grouping structs,
AdoConnectionandWorktreeChanges, following the existingPushBranchParams/PrContextconvention already used elsewhere in this file to avoidclippy::too_many_arguments.execute_implitself is now a short orchestration function that calls these helpers in sequence.Behavior
No public API or observable behavior changes — this is a pure refactor.
Verification
cargo build— cleancargo test(full workspace suite, including all 58create_pull_requesttests) — all passcargo clippy --all-targets --all-features— clean, no new warningsclippy::too_many_linesscoped to the file:execute_impldropped from 582/100 to 237/100Warning
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.