refactor: reduce complexity of execute_impl in create_pull_request.rs - #1946
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. |
|
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. |
|
✅ PR Security Reviewer completed the security review. Warning Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding. What happenedThe threat detection results could not be parsed. Review the workflow run logs for details. Reviewed PR #1946 (pure refactor of CreatePrResult::execute_impl into helper methods). Confirmed all security-relevant checks (patch size limit, SHA-256 integrity verification, path validation, protected-files check, max-files check, ADO token scoping via AdoConnection, sanitize_text usage in fallback description) are preserved verbatim across the extraction -- no logic changes, no new inputs, no weakened validation. Diff is security-neutral; no findings to post.
|
|
✅ Test Quality Sentinel completed the test quality analysis. Reviewed PR #1946 as Test Quality Sentinel. The diff is a pure refactor of CreatePrResult::execute_impl into smaller private helper methods (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) — no new public behavior, no test files touched, and no assertions added, weakened, or removed. The existing 58 tests in this file already exercise execute_impl end-to-end and continue to do so unchanged, since the extracted helpers are called from the same orchestration path. There is no new behavior surface requiring new tests and no regression risk in test coverage from this change, so no review comments are warranted from a test-quality perspective.
|
|
✅ Compiler Contract Reviewer completed the compiler contract review. Reviewed PR #1946 as compiler-contract reviewer. This is a pure internal refactor of CreatePrResult::execute_impl in src/safe_outputs/create_pull_request.rs, extracting helper methods without changing the Params struct, front-matter grammar, safe-output tool registration, typed IR, generated shell scripts, or any documented public contract. No codegen/lock/bundle drift: only one file changed (per pr-meta.json files list), no touches to filter_ir.rs, types.gen.ts, fact-catalog.gen.json, .github/workflows/*.md, or docs/. No raw String identifier fields introduced on Params (all new helper params are internal function args, not deserialized safe-output input). No compiler-contract findings to raise.
|
|
✅ Rust Code Quality Reviewer completed the Rust code quality review.
|
There was a problem hiding this comment.
Rust code quality review
Clean mechanical refactor. execute_impl (582 → 237 lines) was split into well-named helper methods, each keeping its original logic and error-handling paths intact — I diffed each extracted block against the original inline code and found no behavior drift, no swallowed context, and no new unwrap()/expect() on user-reachable paths. The anyhow::Result<Result<T, ExecutionResult>> double-Result pattern used for the new helpers already matches existing convention elsewhere in this file and in github_issue_common.rs/hide_github_issue_comment.rs, so it's consistent rather than novel.
Spot-checked for the common refactor failure modes (state not threaded through to helpers, reordered calls, borrow→clone regressions, lossy casts): none found. cargo build is clean.
Note: the rust-critic sub-agent I dispatched in parallel did not return a response within the session, so this review reflects only my own pass — no additional findings to reconcile.
No merge-blocking issues.
🦀 Rust code quality review by Rust Code Quality Reviewer · auto · 50.1 AIC · ⌖ 12.1 AIC · ⊞ 11.5K
Comment /review to run again
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.