Skip to content

refactor(safe-outputs): reduce complexity of create_pull_request execute_impl - #1938

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

refactor(safe-outputs): reduce complexity of create_pull_request execute_impl#1938
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-pull-request-execute-impl-3-c128eaf762c7b93f

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

CreatePrResult::execute_impl in src/safe_outputs/create_pull_request.rs was flagged by cargo clippy -W clippy::too_many_lines at 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_impl signature is untouched):

  • resolve_repo_id — repository alias/ID resolution against the allowed list
  • read_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 collection
  • resolve_base_commit — Stage-1-recorded SHA vs. ADO refs API fallback
  • ensure_unique_source_branch — branch-collision retry loop
  • build_pr_body — PR JSON payload construction (title/description/work items/labels)
  • build_fallback_failure_result — recovery ExecutionResult when PR creation fails but the branch was pushed

Also added a small AdoConnection<'a> struct to group org_url/project/token for the new helper signatures.

Before/after

  • Before: too_many_lines (582/100)
  • After: too_many_lines (211/100) — the largest remaining helper is setup_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 ignored
  • cargo clippy --all-targets --all-features: clean
  • cargo 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.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 · 137.3 AIC · ⌖ 9.6 AIC · ⊞ 11.4K ·

…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

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