Skip to content

refactor: reduce complexity of execute_impl in close_github_issue.rs - #2017

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-close-github-issue-execute-impl-6e30a70e122eee69
Draft

refactor: reduce complexity of execute_impl in close_github_issue.rs#2017
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-close-github-issue-execute-impl-6e30a70e122eee69

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

CloseGithubIssueResult::execute_impl in src/safe_outputs/close_github_issue.rs was flagged by clippy::too_many_lines at 240/100 lines. The single function handled: config/token validation, target resolution, duplicate-target resolution and node-ID lookup, the already-closed short-circuit, posting an optional closing comment, the PATCH to close the issue, the GraphQL markAsDuplicate mutation, and building the final success message/JSON payload.

What changed

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

  • resolve_canonical_duplicate — resolves and validates the duplicate_of target (repository/self-reference checks, capability check, GraphQL node-ID lookup), returning Option<DuplicateCanonical>.
  • post_closing_comment — posts the optional closing comment (no-op if already closed / omitted / no body).
  • close_issue — sends the PATCH that transitions the issue to closed (no-op if already closed).
  • mark_as_duplicate — runs the markAsDuplicate GraphQL mutation and folds failures into an ExecutionResult that still reports the issue as closed.
  • build_success_result — builds the final message and JSON payload for the success path.

A small DuplicateCanonical struct replaces an inline 4-tuple to make the duplicate-resolution result self-documenting.

No public API or behavior changes — all control flow, error messages, and JSON payload shapes are preserved exactly.

Before / after

  • Before: this function has too many lines (240/100)
  • After: this function has too many lines (110/100)

Verification

  • cargo test --bin ado-aw — 3229 passed, 0 failed, 1 ignored (full suite, including all 14 close_github_issue tests unchanged).
  • cargo clippy --all-targets --all-features — clean for this file (one pre-existing, unrelated warning in create_work_item.rs).

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 · 116.8 AIC · ⌖ 17.5 AIC · ⊞ 11.4K ·

Extract resolve_canonical_duplicate, post_closing_comment, close_issue,
mark_as_duplicate, and build_success_result helper functions from
CloseGithubIssueResult::execute_impl.

No public API or behavior changes. Full test suite and
cargo clippy --all-targets --all-features pass clean.

Before: too many lines (240/100)
After: too many lines (110/100)
@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