refactor: reduce complexity of execute_impl in close_github_issue.rs - #2017
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
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: 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was complex
CloseGithubIssueResult::execute_implinsrc/safe_outputs/close_github_issue.rswas flagged byclippy::too_many_linesat 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 GraphQLmarkAsDuplicatemutation, 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 theduplicate_oftarget (repository/self-reference checks, capability check, GraphQL node-ID lookup), returningOption<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 toclosed(no-op if already closed).mark_as_duplicate— runs themarkAsDuplicateGraphQL mutation and folds failures into anExecutionResultthat still reports the issue as closed.build_success_result— builds the final message and JSON payload for the success path.A small
DuplicateCanonicalstruct 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
this function has too many lines (240/100)this function has too many lines (110/100)Verification
cargo test --bin ado-aw— 3229 passed, 0 failed, 1 ignored (full suite, including all 14close_github_issuetests unchanged).cargo clippy --all-targets --all-features— clean for this file (one pre-existing, unrelated warning increate_work_item.rs).Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.