Skip to content

refactor(safe-outputs): reduce complexity of execute_impl in link_github_sub_issue.rs - #2116

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-link-github-sub-issue-0ee7803b0ebaba52
Draft

refactor(safe-outputs): reduce complexity of execute_impl in link_github_sub_issue.rs#2116
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-link-github-sub-issue-0ee7803b0ebaba52

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What was complex

LinkGithubSubIssueResult::execute_impl in src/safe_outputs/link_github_sub_issue.rs was flagged by Clippy's too_many_lines lint at 190/100 lines — the single highest non-test candidate after the two functions already at the top of the list (create_pull_request.rs and ado_proxy/catalog.rs) had already been processed in prior runs.

The function mixed together several distinct concerns in one long block: config/token validation, resolving and cross-checking the parent/sub-issue targets, fetching and validating GitHub issue metadata, a GraphQL preflight check for an existing parent, and finally performing the addSubIssue mutation and validating its response.

What changed

Extracted four well-named helper functions/methods, each owning one concern:

  • LinkGithubSubIssueResult::resolve_targets — resolves the parent/sub-issue targets via resolve_github_issue_target and validates they're in the same repository and are distinct issues.
  • fetch_and_validate_metadata — fetches parent/sub-issue metadata and validates target capability + mutation filters.
  • check_existing_parent — runs the GraphQL preflight query and returns an early success (already linked to the same parent) or failure (linked to a different parent), or None to proceed.
  • link_sub_issue — performs the addSubIssue GraphQL mutation and validates the response identifies the requested parent/sub-issue.

execute_impl itself is now a short, linear sequence of these calls with early returns, matching the original control flow and error messages exactly. No public API signatures changed and no behaviour changed.

Verification

  • cargo build — succeeds.
  • cargo test --bin ado-aw — all 3322 tests pass (0 failed), including all 9 existing tests for this module (link_github_sub_issue::tests::*), unchanged.
  • cargo clippy --all-targets --all-features — clean, no warnings.
  • Re-ran the clippy::too_many_lines check scoped to this file — no warning remains (previously 190/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 · 86.3 AIC · ⌖ 10.2 AIC · ⊞ 11.4K ·

…ecute_impl

Split the 190-line execute_impl into focused helpers:
- resolve_targets: resolve and validate parent/sub-issue targets
- fetch_and_validate_metadata: fetch issue metadata and validate capability/mutation filters
- check_existing_parent: preflight check for already-linked sub-issues
- link_sub_issue: perform the addSubIssue mutation and validate the response

No behaviour change; all 9 existing unit tests for this module pass unchanged.

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