refactor(safe-outputs): reduce complexity of create_pull_request execute_impl - #1938
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…ute_impl Extract CreatePrResult::execute_impl into focused inherent-impl helpers: resolve_repo_id, read_and_validate_patch, setup_worktree_and_collect_changes, resolve_base_commit, ensure_unique_source_branch, build_pr_body, and build_fallback_failure_result, plus a small AdoConnection struct grouping org_url/project/token. No public API or observable behavior changes. Before: too_many_lines (582/100) After: too_many_lines (211/100, largest remaining helper is setup_worktree_and_collect_changes) Full workspace test suite (3201 tests) passes and clippy is clean. 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.
Summary
CreatePrResult::execute_implinsrc/safe_outputs/create_pull_request.rswas flagged bycargo clippy -W clippy::too_many_linesat 582/100 lines — the highest complexity function in the codebase per the current scan.What was complex
The function inlined every step of the PR-creation pipeline in one body: title-prefix/length validation, repository alias/ID resolution, ADO config extraction, patch file existence/size/hash/security validation, git worktree creation + patch application + change collection, base-commit resolution (Stage-1-recorded vs. ADO refs API), source-branch collision retry, PR body construction, PR creation + fallback-on-failure handling, and post-creation completion options/reviewers.
What changed
Extracted the following inherent-impl helper methods on
CreatePrResult(no public API changes —Executor::execute_implsignature is untouched):resolve_repo_id— repository alias/ID resolution against the allowed listread_and_validate_patch— patch existence/size/hash/security checks (path traversal, protected files, max-files)setup_worktree_and_collect_changes— worktree creation, patch application, and changed-file collectionresolve_base_commit— Stage-1-recorded SHA vs. ADO refs API fallbackensure_unique_source_branch— branch-collision retry loopbuild_pr_body— PR JSON payload construction (title/description/work items/labels)build_fallback_failure_result— recoveryExecutionResultwhen PR creation fails but the branch was pushedAlso added a small
AdoConnection<'a>struct to grouporg_url/project/tokenfor the new helper signatures.Before/after
too_many_lines (582/100)too_many_lines (211/100)— the largest remaining helper issetup_worktree_and_collect_changes(git worktree lifecycle is left intact as one cohesive unit; further splitting risks obscuring the guard/cleanup ordering).Verification
cargo test --bin ado-aw: 3201 passed, 0 failed, 1 ignoredcargo clippy --all-targets --all-features: cleancargo fmt --all -- --check: no diff introduced in the changed file (unrelated pre-existing diffs in other files left untouched)No behavior changes — this is a pure structural refactor.
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.