Skip to content

refactor: reduce complexity of execute_impl in create_pull_request.rs - #1946

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-pull-request-execute-impl-4-e0f264bc167e1cb2
Draft

refactor: reduce complexity of execute_impl in create_pull_request.rs#1946
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-pull-request-execute-impl-4-e0f264bc167e1cb2

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Refactors CreatePrResult::execute_impl in src/safe_outputs/create_pull_request.rs, which clippy flagged as the most complex function in the codebase (clippy::too_many_lines).

Before / After

  • Before: 582 lines (clippy too_many_lines warning threshold is 100)
  • After: 237 lines

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 limit
  • resolve_repo_alias_and_id — repository alias/ID resolution
  • read_and_verify_patch — patch existence, size limit, SHA-256 integrity check
  • validate_patch_content — path validation, protected-files check, max-files check
  • setup_worktree_and_collect_changes — git worktree creation, branch checkout, patch application, change collection
  • resolve_base_commit — recorded base commit or ADO refs API lookup
  • ensure_unique_source_branch — retry-with-suffix loop for branch name collisions
  • build_pr_description — PR body assembly (stats + symlink notice + footer)
  • build_fallback_failure_result — fallback branch-recorded failure result

Also added two small grouping structs, AdoConnection and WorktreeChanges, following the existing PushBranchParams/PrContext convention already used elsewhere in this file to avoid clippy::too_many_arguments.

execute_impl itself 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 — clean
  • cargo test (full workspace suite, including all 58 create_pull_request tests) — all pass
  • cargo clippy --all-targets --all-features — clean, no new warnings
  • Re-ran clippy::too_many_lines scoped to the file: execute_impl dropped from 582/100 to 237/100

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · auto · 186.3 AIC · ⌖ 15.8 AIC · ⊞ 11.4K ·

…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

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants