Skip to content

refactor: reduce complexity of execute_impl in create_branch.rs - #2328

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-branch-execute-impl-0cb68fc174d33f2d
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-branch-execute-impl-0cb68fc174d33f2d

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

CreateBranchResult::execute_impl in src/safe_outputs/create_branch.rs was flagged by clippy::too_many_lines at 160/100 lines. It mixed four distinct concerns inline:

  1. Policy validation (branch-pattern regex, allowed-repositories, allowed-source-branches)
  2. Repository/branch resolution (source commit vs. source branch → SHA)
  3. Request construction (ref name normalization, API URL)
  4. HTTP submission and response interpretation (including per-ref success/error handling embedded in an otherwise-2xx response)

What changed

Extracted 6 single-purpose helper functions, each handling one concern:

  • check_branch_pattern — validates the branch name against the configured branch-pattern regex
  • check_allowed_repository — validates the repository alias against allowed-repositories
  • check_allowed_source_branch — validates the source branch against allowed-source-branches
  • resolve_source_sha — resolves source_commit (if given) or looks up source_branch via the refs API
  • qualified_ref_name — normalizes a branch name to its refs/heads/... form
  • submit_branch_creation — POSTs the ref-creation request and interprets the HTTP/per-ref response

execute_impl itself shrank to a ~45-line orchestrator that calls these helpers in sequence. No public API signatures or observable behavior changed.

Before/after complexity

Lines
Before 160 (clippy::too_many_lines threshold: 100)
After not flagged by clippy::too_many_lines

Validation

  • cargo test --bin ado-aw create_branch — 17/17 passed
  • cargo test --bin ado-aw — 3408 passed, 0 failed, 1 ignored (full suite, no regressions)
  • cargo clippy --all-targets --all-features — no new warnings (only pre-existing, unrelated async_trait double_must_use warnings tracked separately in open PR fix(clippy): bump async-trait to 0.1.92 to clear double_must_use lint #2296)
  • Re-ran the too_many_lines lint scoped to this file: execute_impl no longer appears in the violations list

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 · 93.6 AIC · ⌖ 7.59 AIC · ⊞ 11.1K · ◷

…ranch.rs

Extract 6 helper functions from the 160-line execute_impl in
CreateBranchResult::execute_impl (flagged by clippy::too_many_lines
at 160/100):

- check_branch_pattern: validate branch-pattern regex config
- check_allowed_repository: validate allowed-repositories policy
- check_allowed_source_branch: validate allowed-source-branches policy
- resolve_source_sha: resolve source_commit or source_branch to a SHA
- qualified_ref_name: normalize branch_name to refs/heads/... form
- submit_branch_creation: POST the ref update and interpret the
  Azure DevOps response (including per-ref errors)

execute_impl itself shrank to a ~45-line orchestrator that calls
these helpers in sequence. No behavior change.

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.

This branch has not been deployed

No deployments
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