refactor: reduce complexity of execute_impl in create_pull_request.rs - #1895
Closed
github-actions[bot] wants to merge 1 commit into
Closed
Conversation
Extract five more cohesive blocks from CreatePrResult::execute_impl into named helper functions: resolve_target_repository, load_and_validate_patch, create_target_worktree, resolve_base_commit, and resolve_unique_source_branch. No public API or behavior changes. Verified via full test suite (2948 tests passing) and clean clippy. Before: 583/100 (too_many_lines) After: 349/100 (too_many_lines) 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. |
Collaborator
|
Closing as superseded by #1946, the strongest and most current version of this |
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
CreatePrResult::execute_implinsrc/safe_outputs/create_pull_request.rswas flagged by Clippy'stoo_many_lineslint at 583/100 lines (a previous pass had already reduced it to 362/100). It mixed several independent concerns inline: repository allow-list resolution, patch loading/validation/security checks, git worktree setup, base-commit resolution, and source-branch collision handling — all interleaved with the PR creation logic itself, making the function hard to read and test in isolation.What changed
Extracted five cohesive blocks into named helper functions, each returning
Result<Result<T, ExecutionResult>>(outer for infra errors viaanyhow, inner for user-facing failures) so the call sites keep the original early-return-on-failure behavior:resolve_target_repository— repository alias/ID resolution against the allowed-repositories listload_and_validate_patch(+ newPatchValidationstruct) — patch existence/size/SHA-256 integrity/path-security/protected-files/max-files checkscreate_target_worktree— git-repo verification and worktree creation (withorigin/fallback), returning theTempDir, worktree path, andWorktreeGuardresolve_base_commit— recorded (Stage 1) vs. ADO refs API base commit resolutionresolve_unique_source_branch— the branch-collision retry loop with random suffix renamingNo public API or observable behavior changes.
Before/after
too_many_lines)too_many_lines)Verification
cargo build— cleancargo clippy --all-targets --all-features— clean, no warningscargo test— full suite passes (2948 passed, 0 failed, 1 ignored — pre-existing)execute_implremains above thetoo_many_linesthreshold; further extraction (PR-creation body-building, completion-options/reviewers wiring, file-change collection) is a good next target, tracked in cache memory for the next automated pass.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.