Skip to content

refactor: reduce complexity of execute_impl in create_work_item.rs - #2006

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-work-item-execute-impl-f9a64e03f6d16129
Draft

refactor: reduce complexity of execute_impl in create_work_item.rs#2006
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-create-work-item-execute-impl-f9a64e03f6d16129

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

CreateWorkItemResult::execute_impl in src/safe_outputs/create_work_item.rs was flagged by clippy's too_many_lines lint at 205/100 — the second-highest unaddressed candidate in the codebase after create_pull_request.rs::execute_impl, which has already been the subject of several prior refactor attempts.

What was complex

The function mixed several distinct concerns inline:

  • Tag merging (static config tags + agent-provided tags, deduped case-insensitively)
  • Allowlist validation of agent-provided tags
  • Building the ADO JSON Patch document (title, description, optional fields, tags, custom fields)
  • Handling the HTTP success path (parsing the response, registering the resolved temporary ID, building the result message/payload)
  • Handling the HTTP failure path

What changed

Extracted five well-named helper functions, each owning one concern:

  • merge_tags — merges config and agent tags, case-insensitive dedup
  • check_allowed_tags — validates agent tags against the allowlist, returning an Err(message) instead of inline branching
  • build_patch_document — builds the full JSON Patch document, including field validation
  • handle_creation_success — parses the success response, registers the temporary ID, builds the result
  • handle_creation_failure — builds the failure result from a non-2xx response

execute_impl now reads as a straight-line sequence of these calls with no behavior change.

Before/after

  • Original: 205/100 (too_many_lines)
  • After: below the clippy too_many_lines threshold (no longer flagged)

Verification

  • cargo build — clean
  • cargo test (full suite) — all pass, no failures
  • cargo clippy --all-targets --all-features — clean (one pre-existing, unrelated warning in test code at line 1055)
  • No public API or observable behavior changes; same validation order, same error messages, same success/failure payloads.

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 · 79.1 AIC · ⌖ 10.8 AIC · ⊞ 11.4K ·

Extracted merge_tags, check_allowed_tags, build_patch_document,
handle_creation_success, and handle_creation_failure helpers from
CreateWorkItemResult::execute_impl. Complexity dropped from 205/100
(too_many_lines) to below the clippy threshold. No public API or
behavior changes; full test suite and clippy --all-targets --all-features
pass 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants