refactor(safe-outputs): reduce complexity of execute_impl in submit_pr_review - #1697
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…r_review Extract four focused helper functions to replace the 286-line monolithic execute_impl: - fetch_authenticated_user_id: fetches /connectiondata and extracts the authenticated user ID, returning Ok(Err(failure)) on HTTP errors - check_self_approval: positive-vote guard — returns Some(failure) when the caller would vote on their own PR, None otherwise - submit_vote: PUTs the review vote, returns None on success - post_review_comment_thread: POSTs the optional comment thread, returns the thread ID on success execute_impl is now ~100 lines of sequenced calls with early-return guard clauses. Each phase is independently readable and testable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
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
execute_implinsrc/safe_outputs/submit_pr_review.rswas a 286-line monolithic async function with five inline phases and up to 5 levels of nesting, particularly in the self-approval guard block where anif vote_value > 0contained nestedif pr_response.status().is_success()with another nestedif creator_id == Some(user_id).What changed
Extracted four focused async helper functions, reducing
execute_implto ~100 lines of sequenced calls with early-return guard clauses:fetch_authenticated_user_id/connectiondata, extracts authenticated user ID; returnsOk(Err(failure))on HTTP errorscheck_self_approvalvote_value <= 0, otherwise fetches PR and returnsSome(failure)if caller is the PR authorsubmit_voteNoneon successpost_review_comment_threadVerification
cargo build— cleancargo test— all tests passcargo clippy --all-targets --all-features— clean (zero warnings)Before: 286-line
execute_impl, max nesting depth 5After: ~100-line
execute_impl+ 4 helpers, max nesting depth 3Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comSee Network Configuration for more information.